srhino Posted November 3, 2008 Share Posted November 3, 2008 Maybe I have been looking at this screen to long but I can't figure out what I am doing wrong. I am simply trying to make a form that you can post some information on the website. I have a form called newpractice.inc.php I have made it as simple as possible. <form action="index.php" method="post"> POSTER: <input type="text" name="poster"> PRACTICE INFORMATION: <input type="text" name="desc"> <input type="submit" value="Submit"> <input type="hidden" name="content" value="addpractice"> </form> And here is the insert php code called addpractice.inc.php <?php $poster = $_POST['poster']; $desc = htmlspecialchars($_POST['desc']); if (trim($poster == '')) { echo "<h2>Sorry, each Quote must have a Poster</h2>\n"; }else { $con = mysql_connect("XXXX", "XXXX", "XXXX") or die('Could not connect to database'); mysql_select_db("database_name", $con) or die('Sorry could not connect to the database'); $query = "INSERT INTO newpractice (eventid,poster,desc) " . " VALUES ('$eventid', '$poster', '$desc')"; $result = mysql_query($query) or die('Sorry, we could not accept your information at this time'); if ($result) echo "<a href=\"index.php\"><font color=\"#000000\"><h2>Comment Accepted</h2></font></a>\n"; else echo "<h2>Sorry, there was a problem accepting your event</h2>\n"; } ?> I cant figure out what I am doing wrong can some use a fresh set of eyes and tell me what I am doing wrong? Thanks in Advance. Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/ Share on other sites More sharing options...
katlis Posted November 3, 2008 Share Posted November 3, 2008 Is your database name really database_name? mysql_select_db("database_name", $con) or die('Sorry could not connect to the database'); Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681591 Share on other sites More sharing options...
srhino Posted November 3, 2008 Author Share Posted November 3, 2008 No I just changed it for protection purposes Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681597 Share on other sites More sharing options...
AndyB Posted November 3, 2008 Share Posted November 3, 2008 desc is a MySQL reserved word. You really shouldn't try to use it as a table or field name. You could wrap it with `backticks` but it's much better practice not to use reserved words. http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681618 Share on other sites More sharing options...
bastones Posted November 3, 2008 Share Posted November 3, 2008 $query = "INSERT INTO newpractice (eventid,poster,desc) " . " VALUES ('$eventid', '$poster', '$desc')"; Why are you adding a concatenation operator your query? That isn't required; nevertheless it isn't the problem. You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) so change your code like this: $query = "INSERT INTO `newpractice` (`eventid`,`poster`,`desc`) " . " VALUES ('$eventid', '$poster', '$desc')"; ...see if that works . Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681628 Share on other sites More sharing options...
AndyB Posted November 3, 2008 Share Posted November 3, 2008 You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ... Was there something in my post about reserved words that was so unclear you needed to reiterate the advice? Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681639 Share on other sites More sharing options...
bastones Posted November 3, 2008 Share Posted November 3, 2008 You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ... Was there something in my post about reserved words that was so unclear you needed to reiterate the advice? I am allowed to post my side of the problem and I actually did not reiterate your post, sometimes SQL queries will not work without backticking them. Please do not post such remarks to me! Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681650 Share on other sites More sharing options...
DarkWater Posted November 4, 2008 Share Posted November 4, 2008 You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ... Was there something in my post about reserved words that was so unclear you needed to reiterate the advice? I am allowed to post my side of the problem and I actually did not reiterate your post, sometimes SQL queries will not work without backticking them. Please do not post such remarks to me! Time to set some things straight. 1) He said that they could be backticked in his post, so you were reiterating. 2) The REASON for the backticks is because you're using a MySQL reserved word. 3) Backticks are a MySQL-ONLY operator. 4) Backticks should NEVER be used. 5) You should not create tables or columns with the same names as reserved words, in order to not have to use backticks. Moral of the story: Don't use backticks and rename your tables. Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681653 Share on other sites More sharing options...
bastones Posted November 4, 2008 Share Posted November 4, 2008 You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ... Was there something in my post about reserved words that was so unclear you needed to reiterate the advice? I am allowed to post my side of the problem and I actually did not reiterate your post, sometimes SQL queries will not work without backticking them. Please do not post such remarks to me! Time to set some things straight. 1) He said that they could be backticked in his post, so you were reiterating. 2) The REASON for the backticks is because you're using a MySQL reserved word. 3) Backticks are a MySQL-ONLY operator. 4) Backticks should NEVER be used. 5) You should not create tables or columns with the same names as reserved words, in order to not have to use backticks. Moral of the story: Don't use backticks and rename your tables. I did not realise that you need to backtick reserved-words only so that is why I stated that. It is a learning process so I cannot be perfect in my reply, except I am perfect in my reply based on my knowledge. That GM did not need to get on the defensive with his reply. Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681660 Share on other sites More sharing options...
srhino Posted November 4, 2008 Author Share Posted November 4, 2008 OMG!!!!! I am so dumb...it never even crossed my mind....Thanks for finding that for me. Quote Link to comment https://forums.phpfreaks.com/topic/131275-solved-easy-insert-problem/#findComment-681665 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.