Jump to content

Database Insertion not working, maybe something with the date field?


jaxdevil

Recommended Posts

This is a very small footprint of code but it just is not working. It displays the database insertion was successful but the database is not updated. The connection settings are pointing to the correct database. I have never posted to a 'date' database field before so maybe that is the issue. I posted a screenshot of the database below so you can see that, maybe I set the date field wrong or soemthing?

 

<?php
if ( $action== "Insert" ) {
mysql_connect('localhost','xxx_xxx','xxx');
mysql_select_db('xxx_xxx') or die( "An error has ocured: " .mysql_error (). ":" .mysql_errno ());
$query = "INSERT INTO events(`id`,`date`,`day`,`name`,`description`,`active`)
VALUES('$id','$date','$day','$name','$description','$active')" or die( "An error has ocured: " .mysql_error (). ":" .mysql_errno ());
print "<h1>Event Insertion Successful</h1><br>database<br /><br /><em>Updated!</em><br /><br />";
}
?>

 

 

db.jpg

You're not actually running the query.

 

You've setup the query string in $query

 

but you should use mysql_query( $query ) or die ( mysql_error() );

 

Agreed. And where are these values coming from? If they are user supplied values or might have quotes/new lines/etc, you will want to run them through mysql_real_escape_string()

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.