Jump to content

[SOLVED] Inserting values into a database.


smithmr8

Recommended Posts

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') ?>

Link to comment
Share on other sites

$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.

 

Link to comment
Share on other sites

Good Idea :P

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.