son.of.the.morning Posted November 25, 2011 Share Posted November 25, 2011 I have done a simple insert query on a comment system but it works once and when i go back and try add another record it just doesnt work at all. <?php include ("class.database.connection.php"); // the database connection class include ("settings.config.php"); // hostname, password ect $name = $_POST["UserName"]; $email = $_POST["UserEmail"]; $comment = $_POST["UserComment"]; $sql="INSERT INTO comments (name, email, comment)VALUES('$name', '$email', '$comment')"; $result=mysql_query($sql); ?> if anyone can help me with this i would be a happy chappy! Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/ Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 In what way does it not work? Are there errors? What steps are you taking the second time you run it? Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291218 Share on other sites More sharing options...
son.of.the.morning Posted November 25, 2011 Author Share Posted November 25, 2011 It acts normally just, no errors but the data just isnt going into the database Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291219 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 Have you checked to see if there are any database errors returned with mysql_error()? Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291223 Share on other sites More sharing options...
son.of.the.morning Posted November 25, 2011 Author Share Posted November 25, 2011 yea well i have applied that within my datavase connection class public function databaseConnection($objDatabaseConnect) { $this->_database_connection = mysql_pconnect($this->hostname, $this->username, $this->password) or trigger_error(mysql_error(),E_USER_ERROR); return $this->_database_connection; } Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291224 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 $result = mysql_query($sql) or die( "<br>Query string: $sql<br>Produced error: " . mysql_error() ); Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291227 Share on other sites More sharing options...
son.of.the.morning Posted November 25, 2011 Author Share Posted November 25, 2011 Do i but this within the class or within the page with the query on it? Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291229 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 Assuming the code you posted above is the actual code you're executing, just edit the line that executes the query to be as I posted above. Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291231 Share on other sites More sharing options...
son.of.the.morning Posted November 25, 2011 Author Share Posted November 25, 2011 Just tryied it still nothing it's driving me insane!! http://dvplus.webuda.com/oophptest/database.query.php This sis it up and running, i have set the post page just as blank i just wana make sure that the data it getting into the database first. Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291234 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 Oddly enough, when I try to use the form I get this: Query string: INSERT INTO comments (name, email, comment)VALUES('bob', '[email protected]', 'WTF?') Produced error: Duplicate entry '0000-00-00 00:00:00' for key 'datatime' Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291239 Share on other sites More sharing options...
son.of.the.morning Posted November 26, 2011 Author Share Posted November 26, 2011 Yea am on to it now, it was totaly baffiling me. How do i add the datetime in as "NOW"? Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291245 Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2011 Share Posted November 26, 2011 Just add the field name to the field list, and NOW() (no quotes) in the appropriate place in the list of values. Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291246 Share on other sites More sharing options...
son.of.the.morning Posted November 26, 2011 Author Share Posted November 26, 2011 $sql="INSERT INTO comments (name, email, comment, datatime)VALUES('$name', '$email', '$comment', NOW())"; like so..? Quote Link to comment https://forums.phpfreaks.com/topic/251808-strange-insert-problem/#findComment-1291248 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.