GetReady Posted April 16, 2010 Share Posted April 16, 2010 Hey to my knowledge this should submit 1 into class yet it isn't can anyone spot why? Thanks <tr class="lil1"> <td colspan="2" align="center"> <input type="hidden" name="class" value="37"> <input type="Submit" value="Select Hustler As My Class"><br><br> </td> </tr> </form> <form action="<?php if(isset($_POST['submit'])) { mysql_query("INSERT INTO users ('class') VALUES ('1')"); } ?>" method="post"> <tr class="lil2"> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/ Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 your submit button wasn't in a form. <?php if(isset($_POST['submit'])) { mysql_query("INSERT INTO users ('class') VALUES ('1')"); } ?> <form action="" method="post"> <tr class="lil2"> <td colspan="2" align="center"> <input type="hidden" name="class" value="37"> <input type="Submit" value="Select Hustler As My Class"><br><br> </td> </tr> </form> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043412 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 Oh, also.. your submit button doesn't have a name. Replace this for your button. <input type="submit" value="Select Hustler As My Class" name="submit"> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043415 Share on other sites More sharing options...
GetReady Posted April 16, 2010 Author Share Posted April 16, 2010 So in theory the following should work; (It's not wondering if im missing something, :sight: maybe time to go back to coldfusion :'( <?php if(isset($_POST['submit'])) { mysql_query("INSERT INTO users ('class') VALUES ('1')"); } ?> <form action="" method="post"> <tr class="lil2"> <td colspan="2" align="center"> <input type="hidden" name="submit" value="37"> <input type="submit" value="Select Hustler As My Class" name="submit"><br><br> </td> </tr> </form> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043417 Share on other sites More sharing options...
ChemicalBliss Posted April 16, 2010 Share Posted April 16, 2010 No, because the mysql query is invalid. Single quotes are only used around VALUES. <?php if(isset($_POST['submit'])) { mysql_query("INSERT INTO users (class) VALUES ('1')") or die(mysql_error()); // if it fails it will tell you why. } ?> <form action="" method="post"> <tr class="lil2"> <td colspan="2" align="center"> <input type="submit" value="Select Hustler As My Class" name="submit"><br><br> </td> </tr> </form> Edit; You dont need that hidden value, the submit button wil do just fine as the condition variable. -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043418 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 <?php if(isset($_POST['submit'])) { mysql_query("INSERT INTO users ('class') VALUES ('1')"); } ?> <form action="" method="post"> <tr class="lil2"> <td colspan="2" align="center"> <input type="hidden" name="submit" value="37"> <input type="submit" value="Select Hustler As My Class" name="submit" /><br><br> </td> </tr> </form> You didn't close the end of the button. Which is a / Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043419 Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 No, because the mysql query is invalid. Single quotes are only used around VALUES. I use queries with single quotes around the collum names and values Works fine for me. Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043420 Share on other sites More sharing options...
ChemicalBliss Posted April 16, 2010 Share Posted April 16, 2010 I know you dont because it fails a query ;P you are thinking of the backtick, which he is not using. phpmyadmin: SELECT 'test_column' FROM 'testtable' Try it. ` != ' -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043425 Share on other sites More sharing options...
GetReady Posted April 16, 2010 Author Share Posted April 16, 2010 Hey i did the following; im Getting no errors reported, not is it submitting it, should the digit 1 not be submitted to the database via this form? Im wondering is it possibly anything to do with value="37", I do appreciate the help you are providing me with, Many Thanks. <?php if(isset($_POST['submit'])) { mysql_query("INSERT INTO users (class) VALUES ('1')") or die(mysql_error()); // if it fails it will tell you why. } ?> <form action="" method="post"> <tr class="lil2"> <td colspan="2" align="center"> <input type="hidden" name="submit" value="37"> <input type="submit" value="Select Hustler As My Class" name="submit" /><br><br> </td> </tr> </form> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043426 Share on other sites More sharing options...
ChemicalBliss Posted April 17, 2010 Share Posted April 17, 2010 Get rid of this line: <input type="hidden" name="submit" value="37"> You dont need it. Try putting backticks around the table and column names: INSERT INTO `users` (`class`) VALUES ('1') -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043430 Share on other sites More sharing options...
TeddyKiller Posted April 17, 2010 Share Posted April 17, 2010 Yeah <input type="hidden" name="submit" value="37"> you don't need that. If you want to keep it, change the name to sometihng other than submit. Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043433 Share on other sites More sharing options...
mrMarcus Posted April 17, 2010 Share Posted April 17, 2010 has nothing to do with the 37. either change the name of your hidden input tag, or get rid of it. not quite sure what it's purpose is as you're not using it at all. if you're not receiving any errors from the mysql. rule of thumb, (especially) when in development, as a form of troubleshooting, always handle your conditions with an ELSE so as to determine where your script(s) are failing. This carries into production as well as you must be ready to redirect a user/script upon failure. now, there is no visible reason your check on whether submit was sent, but you should lose the IF and simply execute the query to ensure your db is accepting queries at the moment. Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043434 Share on other sites More sharing options...
mrMarcus Posted April 17, 2010 Share Posted April 17, 2010 Get rid of this line: <input type="hidden" name="submit" value="37"> You dont need it. Try putting backticks around the table and column names: INSERT INTO `users` (`class`) VALUES ('1') -cb- backticks are not necessary (but are good practice), as neither 'class' nor 'users' are reserved mysql words. Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043436 Share on other sites More sharing options...
GetReady Posted April 17, 2010 Author Share Posted April 17, 2010 found the error... i believe.. for some reason a new user is created from that code i fail to see why the hell thats happening :/ Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043452 Share on other sites More sharing options...
ChemicalBliss Posted April 17, 2010 Share Posted April 17, 2010 Um, so you want to update an existing row, not insert a new one? Use UPDATE table SET (`col`='value') WHERE `col`='value' -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043456 Share on other sites More sharing options...
GetReady Posted April 17, 2010 Author Share Posted April 17, 2010 sorry it would appear i wasn't clear with the post.. apologies for that. Would it basically be something along these lines, and is there any way to then redirect the user to another page once the update has taken place, or is that not a possibility? Sorry for the noobish posts im making trying to get my head around php atm. <?php if(isset($_POST['submit'])) { mysql_query("UPDATE users SET (`class`='1') WHERE `class`='5'") or die(mysql_error()); } ?> <form action="" method="post"> <tr class="lil2"> <td colspan="2" align="center"> <input type="submit" value="Select Hustler As My Class" name="submit" /><br><br> </td> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043464 Share on other sites More sharing options...
ChemicalBliss Posted April 17, 2010 Share Posted April 17, 2010 why are you trying to set class to 1? -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043469 Share on other sites More sharing options...
GetReady Posted April 17, 2010 Author Share Posted April 17, 2010 Basically when a user logs in they have the option of choosing between 4 player class's, That's the option for the first of the 4, After choosing a class id like to redirect them to welcome.php, but that code doesn't appear to change the class field to 1, i get the error message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(`class`='1') WHERE `class`='5'' at line 1 Any info would help, Many thanks. Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043475 Share on other sites More sharing options...
mrMarcus Posted April 17, 2010 Share Posted April 17, 2010 lose the brackets around `class`='1' will throw an error; your: or die(mysql_error()); should be picking that up. [EDIT]: your: or die(mysql_error()); DID in fact pick that up. Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043478 Share on other sites More sharing options...
ChemicalBliss Posted April 17, 2010 Share Posted April 17, 2010 Yes, but also you need to figure out something; Do you have a login? are your users logged in when they go to this form? you need to tell mysql which row (or user) it has to change. so it should be like where user = 'someusername' -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043481 Share on other sites More sharing options...
GetReady Posted April 17, 2010 Author Share Posted April 17, 2010 Yea, i have everything set up via this, It now works like a charm Thanks guys, That ones being racking my brain for a while, Would it be easy enough to make it so this page only cropped up if the player class is 5? im guessing it would be something like <? if ($class >= 5) { ?> Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043484 Share on other sites More sharing options...
ChemicalBliss Posted April 17, 2010 Share Posted April 17, 2010 yes, you would make the user login, once logged in you can store all the details from the SELECT query you used to check his username and password, into SESSION variables. Put this at the top of every members page (not for included files, only at the start of the page): session_start(); Then, on the login page, use a query like this: SELECT * FROM usertable WHERE username='someuser' AND password='somepass'; You would use mysql_num_row() to check if its valid. then you can use mysql_fetch_assoc() to store the details into the $_SESSION array like so: $_SESSION['username'] = $row['username']; $_SESSION['class'] = $row['class']; etc.. Then on any page using sessions, you can do: if($_SESSION['class'] >= 4){ // display content }else{ echo 'not allowed.'; } -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043494 Share on other sites More sharing options...
GetReady Posted April 17, 2010 Author Share Posted April 17, 2010 Thanks, I did the code as said, and all i get is not allowed. then the content underneath it all I did this at the page top <? session_start(); $_SESSION['username'] = $row['username']; $_SESSION['class'] = $row['class']; ?> <? include "vsys.php"; ?> and this before the forms <? if($_SESSION['class'] >= 4){ // display content }else{ echo 'not allowed.'; } ?> <h2>Select a Character Class for <? $user=getusers($_SESSION['isLogined'],'userName');echo $user->userName; ?></h2> <table cellpadding="0" cellspacing="0" border="0" width="600" align="center"> <tr class="lil1"> Am i missing something here? Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043506 Share on other sites More sharing options...
ChemicalBliss Posted April 17, 2010 Share Posted April 17, 2010 You need to get the concept of php variables. Every variable in php ($variable) has to come from somewhere. if it was not set, then it doesnt exhist yet (except for environment vars etc). You only set the session variables at login. The only thing at the top of your page should be session_start(); -cb- Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043525 Share on other sites More sharing options...
TeddyKiller Posted April 17, 2010 Share Posted April 17, 2010 <? session_start(); $_SESSION['username'] = $row['username']; $_SESSION['class'] = $row['class']; ?> <? include "vsys.php"; ?> For 1, you don't need to close and open a PHP tag for no reason. For 2, you have $row['tablename'] when $row isn't defined. For 3, you could use a function, to find out if a user is "alive" or dead. replace /index.php with your homepage for non-logged in users. Make sure you have two sessions set upon log-in, for example.. $_SESSION['uid'] - Contains the user_id of current user logged in $_SESSION['name'] - contains the name of the current user logged in Place the function in a file called functions.php, and include it to all pages. function check_user() { if (!isset($_SESSION['uid']) || !isset($_SESSION['name'])) { session_unset(); session_destroy(); header("Location: /index.php"); } else { $query = mysql_query("SELECT * FROM users WHERE id='".$_SESSION['uid']."'") or trigger_error("Query failed: ".mysql_error()); $userarray = mysql_fetch_array($query); if (mysql_num_rows($query) ==0) { session_unset(); session_destroy(); header("Location: /index.php"); } foreach($userarray as $key=>$value) { $user->$key = $value; } return $user; } } To call this function, in the page that you wish to be shown to members, simply do.. $user = check_user(); What this does, is not only check if the user is logged in, and if not redirect them to homepage... It'll grab all the data from the users table based on that user .. and plonk it into an array. The data can be accessed like so. echo $user->username; //username being the COLLUM name in the users database table. As for your query you are doing before... if you are using the function above.. you can simply do this. mysql_query("UPDATE users SET (`class`='1') WHERE `class`='5' AND `id`='$user->id'") or die(mysql_error()); Although I'm really not sure why you have where `class`='5' when you stated there is only 4 classes to choose from? Link to comment https://forums.phpfreaks.com/topic/198807-any-idea-as-to-why-this-isnt-being-submitted/#findComment-1043666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.