Jump to content

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


bigdaddykraven

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.