Jump to content

Archived

This topic is now archived and is closed to further replies.

bigdaddykraven

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

Recommended Posts

The code:
[code=php:0]
  <?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!";
}
?>
[/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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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].

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.