Jump to content


Photo

This one's an easy one... (SOLVED)


  • Please log in to reply
8 replies to this topic

#1 bigdaddykraven

bigdaddykraven
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 September 2006 - 04:58 PM

The code:
  <?php
if (!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!";
}
?>

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 September 2006 - 05:07 PM

Code and the query seems fine from looking at it. To see if its a problem with the query use this:
$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());

Instead of:
mysql_query("INSERT INTO `articles` (title, content) VALUES ('$title','$content')");

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 mysql_real_escape_string function.

#3 bigdaddykraven

bigdaddykraven
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 September 2006 - 05:14 PM

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 72
Unable 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.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 September 2006 - 05:16 PM

Opps I did a typo. My bad. This:
mysql_query($sql) or die("Unable to perform query <code>{$sql}</code><br />\n" . mysql_query());
Should be this:
mysql_query($sql) or die("Unable to perform query <code>{$sql}</code><br />\n" . mysql_error());


#5 bigdaddykraven

bigdaddykraven
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 September 2006 - 05:21 PM

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 1

Like I said, strange since I have another script just like this one and it posts fine...could the TIMESTAMPER data be a problem?

#6 bigdaddykraven

bigdaddykraven
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 September 2006 - 05:22 PM

My MYSQL version is: 5.0.24-standard

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 September 2006 - 05:29 PM

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 article.

#8 bigdaddykraven

bigdaddykraven
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 September 2006 - 05:33 PM

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.

#9 bigdaddykraven

bigdaddykraven
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 September 2006 - 05:35 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users