DF7 Posted February 21, 2007 Share Posted February 21, 2007 I have a PHP form that should add data to the database, but the database is never updated from the form. I have another test file that will work just fine using the very same statement to update - just without the actual form, so it's not a problem with connecting to the database. It seems to be the if (submit) statement, but I cannot for the life of me figure out what the problem is! :-( I have included the php form here. Any help would be greatly appreciated. ****** <html> <body> <?php $hostname="p3smysql9.secureserver.net"; $username="DDWD"; $pword="Mydiane"; $dbname="DDWD"; $usertable="QuestionComment"; if($submit) { // process form echo "This is the top line of process form. Next I connect to database. "; mysql_connect($hostname,$username,$pword) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db($dbname) or die ('Unable to select database!'); $today = date("m d Y", mktime()); echo $today, "is today's date."; $sql = "INSERT INTO $usertable (source,submit_date,emailaddress,firstname,lastname,phone) VALUES ($source,Now(),$emailaddress,$firstname,$lastname,$phone)" or die ('I cannot insert records to the database because: ' . mysql_error()); $result = mysql_query($sql) or die ('Error in query: $query. ' . mysql_error()); echo "Thank you! Your question/comment was entered."; } else{ // display form ?> <form method="post" action="<?php echo $PHP_SELF?>"> <input type="hidden" name="source" value="Contact page"> EmailAddress:<input type="Text" name="emailaddress">*Required<br> First name:<input type="Text" name="firstname"><br> Last name:<input type="Text" name="lastname"><br> Phone:<input type="Text" name="phone"><br> <input type="submit" name="submit" value="submit"> </form> <?php } // end if ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/39495-solved-database-form-that-is-not-updating-the-database/ Share on other sites More sharing options...
DF7 Posted February 27, 2007 Author Share Posted February 27, 2007 I finally fixed it myself - thanks anyway! Link to comment https://forums.phpfreaks.com/topic/39495-solved-database-form-that-is-not-updating-the-database/#findComment-195205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.