Greaser9780 Posted February 21, 2007 Share Posted February 21, 2007 Here's the form: <form action="addplayer.php" method="post"> Player Name:<input type="text" name="name"><br> Position:<input type="text" name="pos"><br> <button type="submit">Submit</button> </form> Here's the script: <?php include("db.php"); array_pop($_POST); if ( get_magic_quotes_gpc() ) { $_POST= array_map('stripslashes', $_POST); } $name = mysql_real_escape_string(trim($_POST['name'])); $pos = mysql_real_escape_string(trim($_POST['pos'])); $sql = mysql_query("INSERT INTO `players` (`name`,`pos`) VALUES ('$name','$pos')") or die(mysql_error()); $playerid = mysql_insert_id(); include("addplayerform.html"); ?> The name will get entered but the position "pos" will not go into the table. I even set default value for what my $_POST['pos'] is and it still won't go in. Field is set to varchar 20 and that's it. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 Just FYI, <button> isn't supported by all browsers, you should use <input type="submit"> What happens if you do: $q = "INSERT INTO `players` (`name`,`pos`) VALUES ('$name','$pos')"; print $q; $sql = mysql_query($q) or die(mysql_error()); What does it show you the query says? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 21, 2007 Author Share Posted February 21, 2007 INSERT INTO `players` (`name`,`pos`) VALUES ('Joe','') Odd, it's like it's either not getting it from the form or not recognizing the variable. Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted February 21, 2007 Share Posted February 21, 2007 Its not recognizing the variable is what i would say, i've had this problem many of times. Make sure the $pos var is getting posted to the page with the query. Try adding: $pos = $_POST['pos']; At the begining of the php code then running the other functions separatly. $pos = mysql_real_escape_string($pos); $pos = trim($pos); Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 add print_r($_POST); at the top Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 21, 2007 Author Share Posted February 21, 2007 Changed variable name and now it works. That was really weird. Quote Link to comment Share on other sites More sharing options...
Patrick3002 Posted February 21, 2007 Share Posted February 21, 2007 Maybe you had two of the same variable names? That is really weird, hmm. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.