Hi, in this my php/mysql script....

<?
$title = $_POST['title']; 
$about = $_POST['about'];
$screenshots = $_POST['screenshots'];
$source = $_POST['source'];

if (!$title || !$about || !$screenshots || !$source)
{
	echo "You have not completed all of the required feilds in your article report.<br>"
."please go back and try again.";
	exit;
}

$title = addslashes($title);
$about = addslashes($about);
$screenshots = addslashes($screenshots);
$source = addslashes($source);

@ $db = mysql_pconnect("localhost", "mike", "c00l");
if (!$db)

{

echo "<b>Could not connect to database, try again later.</b>";

exit;

}

mysql_select_db("news");

$sql ="INSERT INTO articles (title, about, screenshots, source) VALUES ('', '$title', '$about', '$screenshots', '$source')";

$result = mysql_query($sql) or die (mysql_error());;
if ($result)
My_SQLError() 
?>

i get this error...

Column count doesn't match value count at row 1

Waht does that mean and hiow can i fix it?
Thanks- Brcolow

    This means that your insert query does not have the correct number of columns in it. You have to many or not enough.

    Take a look at your table in MySQL and compare it to your query in PHP.

    You will see a difference.

      $sql ="INSERT INTO articles (title, about, screenshots, source)
      VALUES ('', '$title', '$about', '$screenshots', '$source')";

      here you have four columns listed, but five values. That's the problem.

        Well, i dont see five value i see 4 and they are title, about, source and screenshots.. and my table is this....

        title
        about
        screenshots
        source

        Edit: Oh wait, i see what ur talking about... thats there to make it null for an auto_increcment, but one question should all of my coulmns have auto_increcment on them?? Or mabye like one coulmn for the null thing?? I am kind o a newbie here so please walk me through this.

        Those are all the coulmns i have.... mabye its something INSIDE my table?

          $sql ="INSERT INTO articles (title, about, screenshots, source)
          VALUES ('', '$title', '$about', '$screenshots', '$source')";

          The first value you're putting into the DB is a empty string!

            yes, but isnt that to make it null so it can go in an auto_increcment? Or mabye I should just dlete that and make all of my coulmns have auto_increcment on them...but if i do that im not sure how i would access all of them together using php?

            Thanks
            Mike

              I suppose you have auto_increment field for id, am I right? And you want it to increment automatically.
              Then you need not assign anything to it.

              $sql ="INSERT INTO articles (title, about, screenshots, source)
              VALUES ('$title', '$about', '$screenshots', '$source')";

              will be enough. Do not try assigning empty values to auto_increment field, especially if you haven't mention it in field list. Just forget about that empty string and everything gonna be OK.

                What the_Igel said..

                🙂

                  so i need a new coulmn caled id with auto_increcment on it... does it need anything else?

                    yes? no? please help me with this

                      • [deleted]

                      FIRST check to see if you don't already have an auto-increment field set up on your table. You would be well served to have a program like phpMyAdmin set up on your server to help manage MySQL.

                      ALTER TABLE news.articles ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

                      🙂

                        ok, looks like it worked... now, i know this is asking alot but can you please write the script i need to use to access the one id that is the id they went to.. like www.flashstand.com/article.php?id=1
                        so then it loads one? Thanks for the help already,
                        -Brcolow

                          damn, at least put some effort into learning php/sql b4 asking people to write scripts for you.

                            uhh i did.. im just unclear on how to weite the SELECT from part... and u havent found a tutoial that fits my needs for what i need to do...

                              Write a Reply...