roberts78 Posted August 8, 2009 Share Posted August 8, 2009 I have a registration form that will allow users to register to receive a monthly newsletter. I have created a newsignup form and the signup form when submit is pressed directs to a file called newsignup_ac that adds the info to the db. It looks to work correctly but it doesn't add anything into the db. it creates a row but nothing appears. Any help would be appreciated. Here is my code. ****** newsignup.php ****** <FORM ACTION="newsignup_ac.php" METHOD=post> <h1 align="center"> <br> <br> <table border="2"> <tr> <td><strong>Name</strong><span class="style4">..</span> :</td><td><input name="name" type="name" size"40"></input></td> </tr> <tr> <td><strong>Email</strong><span class="style4"> ...</span>:</td><td><input name="email" type="email" size"40"></input></td> </tr> <tr> <td><strong>College</strong> :</td> <td><SELECT NAME="college"> <OPTION VALUE="Please Select" SELECTED>--- Please Select ---</OPTION> <OPTION VALUE="University of Houston">University of Houston</OPTION> <OPTION VALUE="Texas Tech University">Texas Tech University</OPTION> <OPTION VALUE="Texas A&M - Corpus Christi">Texas A&M - Corpus Christi</OPTION> <OPTION VALUE="Other">Other</OPTION> </SELECT> </input> </td> </tr> </table> <br> <input type="submit" value="Register"> </input> ****** newsignup_ac.php ****** <?php $dbhost="localhost"; $dbuser="uname"; $dbpass="pword"; $conn= mysql_connect($dbhost,$dbuser,$dbpass)or die(mysql_error()); $dbname= 'db'; $db_tbl= 'user'; mysql_select_db($dbname); $sql="insert into $db_tbl (name,email,college)values('$_POST[name]','$_POST','$_POST[college]')"; $result=mysql_query($sql,$conn) or die(mysql_error()); header("location:TheShores.html"); ?> Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/ Share on other sites More sharing options...
abazoskib Posted August 8, 2009 Share Posted August 8, 2009 looks like you are missing a space. try this: $sql="insert into $db_tbl (name,email,college) values('$_POST[name]','$_POST[email]','$_POST[college]')"; Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/#findComment-893739 Share on other sites More sharing options...
mattal999 Posted August 8, 2009 Share Posted August 8, 2009 looks like you are missing a space. try this: $sql="insert into $db_tbl (name,email,college) values('$_POST[name]','$_POST[email]','$_POST[college]')"; Actually, should look more like: $sql = "INSERT INTO $db_tbl (name, email, college) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['college']."')"; Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/#findComment-893745 Share on other sites More sharing options...
abazoskib Posted August 8, 2009 Share Posted August 8, 2009 mattal999, what makes that more correct? Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/#findComment-893746 Share on other sites More sharing options...
roberts78 Posted August 8, 2009 Author Share Posted August 8, 2009 I changed the $sql statement and still get the same result. When I check the db it shows the following: id name email college 16 15 14 17 Fields: name, email, college are all blank Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/#findComment-893747 Share on other sites More sharing options...
mattal999 Posted August 8, 2009 Share Posted August 8, 2009 mattal999, what makes that more correct? Basically, PHP and MySQL prefer to use correctly formatted strings. The Capital function names just help MySQL make logic of the string. Also, the ".$_POST parts show that it is a variable being pulled from PHP, not just a string. I think that your POST variables are not being passed correctly. Try this for the signup code: <?php $dbhost = "localhost"; $dbuser = "uname"; $dbpass = "pword"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); $dbname = 'db'; $db_tbl = 'user'; mysql_select_db($dbname); $sql = "INSERT INTO $db_tbl (name, email, college) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['college']."')"; //$result=mysql_query($sql, $conn) or die(mysql_error()); //header("location:TheShores.html"); print_r($_POST); ?> Tell me what the output is. Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/#findComment-893754 Share on other sites More sharing options...
roberts78 Posted August 8, 2009 Author Share Posted August 8, 2009 THANK YOU SO MUCH abazoskib !!!!!!! After I did that I noticed where the problem was. I had it trying to post to regname, regemail, and regcollege. Instead of going to name, email, college. You guys are awesome, Thanks again for all the help on this issue Link to comment https://forums.phpfreaks.com/topic/169383-solved-php-posting-issue/#findComment-893762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.