skbanta Posted May 17, 2008 Share Posted May 17, 2008 I'm not sure whats wrong with this but I keep getting and error. <?php $con=mysql_connect(******) or die ('A problem has occurred'); mysql_select_db(write); $query="INSERT INTO articles (title, article, author, topic) VALUES ('$_POST[title]','$_POST[article]','$_POST[author]','$_POST[topic])"; if (!mysql_query($query,$con)) { die('Problem Encountered'); } echo "Thank You"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/106013-solved-need-help-with-code/ Share on other sites More sharing options...
pocobueno1388 Posted May 17, 2008 Share Posted May 17, 2008 I went through and commented your mistakes. If this doesn't fix it, tell us what the error is. <?php $con=mysql_connect(******) or die ('A problem has occurred'); //You should use quotes around the DB name mysql_select_db("write"); //Your were missing a single quote on the last variable $query="INSERT INTO articles (title, article, author, topic) VALUES ('$_POST[title]','$_POST[article]','$_POST[author]','$_POST[topic]')"; if (!mysql_query($query,$con)) { die('Problem Encountered'); } echo "Thank You"; //Missing a semi-colon after line mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/106013-solved-need-help-with-code/#findComment-543332 Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 When echoing an array, you must enclose it in { }, like {$_POST['title']}. Also, use ' ' to mark off your associative array keys. Link to comment https://forums.phpfreaks.com/topic/106013-solved-need-help-with-code/#findComment-543333 Share on other sites More sharing options...
skbanta Posted May 17, 2008 Author Share Posted May 17, 2008 I followed your comments and got this error: Parse error: syntax error, unexpected T_STRING in C:\wamp\www\write\article.php on line 12 Link to comment https://forums.phpfreaks.com/topic/106013-solved-need-help-with-code/#findComment-543335 Share on other sites More sharing options...
skbanta Posted May 17, 2008 Author Share Posted May 17, 2008 I've fixed it. Thank you for the help. Link to comment https://forums.phpfreaks.com/topic/106013-solved-need-help-with-code/#findComment-543338 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.