bigdaddykraven Posted September 23, 2006 Share Posted September 23, 2006 The code:[code=php:0] <?phpif (!isset($_POST['submit'])) {?></p> <p class="style3">Post the newest news Article Here for it to appear on the front page.</p> <form action="" method="post"> <p>Article Title: <input name="title" type="text" id="title"> </p> <label>Full Article:<br> <textarea name="content" cols="80" rows="10" id="content"></textarea></label> <br> <br> <input type="submit" name="submit" value="Submit!"> </p> </form><?php} else {$title = $_POST['title'];$content = $_POST['content'];mysql_query("INSERT INTO `articles` (title, content) VALUES ('$title','$content')");echo "This news article has been added to the page!";}?>[/code]I have two forums, one posts my roleplays into their archive while this one is SUPPOSED to post into my articles board. The roleplays board works fine, it posts to my database and then I can look at my archives board and see them all. It's this article poster I have trouble with. I know everything should work fine in my connections (which I am not showing but trust me, it works). The only difference between this and the rp poster code is that it is posting into a different table within the same database "articles" and other than the Title and Content (and the usual ID), I have a postdate with a timestamper invloved. I'm wondering if maybe that has something to do with it?I've never used timestamper before, so I don't know if that's different. I know the table does work as I manually inputted one article on the mySQL/PHP admin page and it displays on the front page just fine. SO I know it's something simple, but what am I missing? This code goes through and says it is posted, but in reality, doesn't send it to my articles table... Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/ Share on other sites More sharing options...
wildteen88 Posted September 23, 2006 Share Posted September 23, 2006 Code and the query seems fine from looking at it. To see if its a problem with the query use this:[code]$sql = "INSERT INTO `articles` (title, content) VALUES ('$title','$content')";mysql_query($sql) or die("Unable to perform query <code>{$sql}</code><br />\n" . mysql_query());[/code]Instead of:[code]mysql_query("INSERT INTO `articles` (title, content) VALUES ('$title','$content')");[/code]If you do get an error post the full error message hear.Also you dont want to use raw user input either. You should always validate user input and make it secure too when using user input in a database query. You can do this using the [url=http://php.net/mysql_real_escape_string]mysql_real_escape_string[/url] function. Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97302 Share on other sites More sharing options...
bigdaddykraven Posted September 23, 2006 Author Share Posted September 23, 2006 Good call, I didn't think about having an error bounce back :)Error:Warning: Wrong parameter count for mysql_query() in /home3/bdkraven/public_html/kraven/newsposter.php on line 72Unable to perform query INSERT INTO `articles` (title, content) VALUES ('Testing','Boom')Line 72 is the second part of the code you asked me to put in, the "or die" string. Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97303 Share on other sites More sharing options...
wildteen88 Posted September 23, 2006 Share Posted September 23, 2006 Opps I did a typo. My bad. This:[code]mysql_query($sql) or die("Unable to perform query <code>{$sql}</code><br />\n" . mysql_query());[/code]Should be this:[code]mysql_query($sql) or die("Unable to perform query <code>{$sql}</code><br />\n" . mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97304 Share on other sites More sharing options...
bigdaddykraven Posted September 23, 2006 Author Share Posted September 23, 2006 Error:Unable to perform query INSERT INTO 'articles' (title, content) VALUES ('HEllo','testing')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 ''articles' (title, content) VALUES ('HEllo','testing')' at line 1Like I said, strange since I have another script just like this one and it posts fine...could the TIMESTAMPER data be a problem? Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97306 Share on other sites More sharing options...
bigdaddykraven Posted September 23, 2006 Author Share Posted September 23, 2006 My MYSQL version is: 5.0.24-standard Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97308 Share on other sites More sharing options...
wildteen88 Posted September 23, 2006 Share Posted September 23, 2006 Not sure what you mean by timstamper. Do you mean unix timestamp? However i noticed in your query you are using single quotes. When before you where using single quotes when before you had backticks (`) around [b]article[/b]. Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97310 Share on other sites More sharing options...
bigdaddykraven Posted September 23, 2006 Author Share Posted September 23, 2006 yeah, I'm sorry. The timestamp thing in the mysql field, for my postdate field in the table. So when I post my articles, it'll date/time it for me.After removing the backtags and single quotes, I got this: Unable to perform query INSERT INTO articles (title, content) VALUES ('Testing','Article Info ')Duplicate entry '1' for key 1---I think the backtags to single quotes my my bad because I accidentally deleted one of em and on the fly, just replaced them with single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97312 Share on other sites More sharing options...
bigdaddykraven Posted September 23, 2006 Author Share Posted September 23, 2006 Wait! Doh! I realized that meant auto_increment wasn't on. I had it checked when creating the table but I bet I scroll balled it off again before submitting :)Edit: That seemed to have done it. I'm stupid and as I said, it was an easy one, just needed help isolating the problem. Thanks a bunch for your help. Quote Link to comment https://forums.phpfreaks.com/topic/21787-this-ones-an-easy-one-solved/#findComment-97313 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.