smithmr8 Posted January 7, 2008 Share Posted January 7, 2008 Hello, I seem to be having some trouble including some values in a database. The code is shown below. Connection information is contained in my header file, and there is nothing wrong with it as similr things to this work. Theoretically, this form and script should enter the values entered into the text boxes into a table 'updates'. It says 'Update Added', but nothing is actually added to the table. If I do it manually via PHPMYADMIN it does work, obviously. They are then displayed on the page: http://www.templateking.co.uk/updates.php <?php include('header.php') ?> <form method="POST" action="add_update.php?step=action_add"> Date <input type="text" name="date" size="15"><br> Update Contents <input type="text" name="update" size="20"><br> <input type="submit" value="Submit" name="submit"><br> </form> <?php if ($_GET['step'] == 'action_add') { $thedate = $_POST['date']; $theupdate = $_POST['update']; $db_handle = mysql_connect($dbhost, $dbuname, $dbpass); $db_found = mysql_select_db($dbname, $db_handle); $dbtable = "updates"; if ($db_found) { //$SQL = "INSERT INTO $dbtable (date, update) VALUES ('$date', '$update')"; $SQL = "INSERT INTO updates (date, update) VALUES ($thedate, $theupdate)"; $result = mysql_query($SQL); mysql_close($db_handle); print "Update Added"; } else { print "Database NOT Found. Error."; mysql_close($db_handle); } } ?> <?php include('footer.php') ?> Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/ Share on other sites More sharing options...
revraz Posted January 7, 2008 Share Posted January 7, 2008 $SQL = "INSERT INTO updates (date, update) VALUES ('$thedate', '$theupdate')"; And your "Update added" has no error checking at all, so even if it fails, it will say that. Check to make sure the sql query was really added before you echo that. Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432874 Share on other sites More sharing options...
smithmr8 Posted January 7, 2008 Author Share Posted January 7, 2008 I changed that line, but it is still telling me it has added it.. when it hasn't. Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432875 Share on other sites More sharing options...
thomashw Posted January 7, 2008 Share Posted January 7, 2008 Oops. Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432877 Share on other sites More sharing options...
revraz Posted January 7, 2008 Share Posted January 7, 2008 $result = mysql_query($SQL) or die ("Error in query: $SQL. " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432878 Share on other sites More sharing options...
smithmr8 Posted January 7, 2008 Author Share Posted January 7, 2008 Good Idea There an error. Error in query: INSERT INTO updates (date, update) VALUES ('44', 'Thank-You PHPFreaks. Working.'). 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 'update) VALUES ('44', 'Thank-You PHPFreaks. Working.')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432883 Share on other sites More sharing options...
revraz Posted January 7, 2008 Share Posted January 7, 2008 UPDATE is a Reserved word, rename your field to something else or use backticks `update` *Sorry, just UPDATE is Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432884 Share on other sites More sharing options...
smithmr8 Posted January 7, 2008 Author Share Posted January 7, 2008 Thank-You Once Again This forum is so helpful. I would never have realised that Thanks and Best Regards, Luke Quote Link to comment https://forums.phpfreaks.com/topic/84904-solved-inserting-values-into-a-database/#findComment-432890 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.