|
Posted by Norman Peelman on 11/19/06 22:49
"so many sites so little time" <kkddrpg@gmail.com> wrote in message
news:1163951865.217385.224180@m73g2000cwd.googlegroups.com...
> this time i am going to use the scripts from the book and just change
> the names to match what i am trying to do now i just got an error that
> i know shouldnt be an error i think. this is the error:
>
> Could add the site entry because: Column count doesn't match value
> count at row 1. The query was INSERT INTO home (home_id, header, body,
> date_entered) VALUES ('Welcome!', 'What is a Progressive Parent? A
> Progressive Parent ...
>
> now i created the table using what the book gave me which is:
>
> // Define the query.
> $query = 'CREATE TABLE home (
> home_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
> header VARCHAR(100) NOT NULL,
> body TEXT NOT NULL,
> date_entered DATETIME NOT NULL
> )';
>
> // Run the query.
> if (@mysql_query ($query)) {
> print '<p>The table has been created.</p>';
> } else {
> die ('<p>Could not create the table because: <b>' . mysql_error() .
> '</b>.</p><p>The query being run was: ' . $query . '</p>');
> }
>
> and when i ran that script live i got the message "The table has been
> created."
>
> now when i run this script and try to insert the data is when i get the
> error message i posted above and that script looks like:
>
> // Define the query.
> $query = "INSERT INTO home (home_id, header, body, date_entered)
> VALUES ('{$_POST['header']}', '{$_POST['body']}', NOW())";
>
> // Execute the query.
> if (@mysql_query ($query)) {
> print '<p>The site entry has been added.</p>';
> } else {
> print "<p>Could add the site entry because: <b>" . mysql_error() .
> "</b>. The query was $query.</p>";
> }
>
> mysql_close();
>
> }
>
First problem is you are not entering your home_id at all (it takes a 0 -
zero or a NULL to work), make your $query look like this:
$query = "INSERT INTO home (home_id, header, body, date_entered) VALUES
(NULL,'{$_POST['header']}', '{$_POST['body']}', NOW())";
....and second (and personal taste) is if you aren't using multi-dimensional
arrays you can do it this way:
$query = "INSERT INTO home (home_id, header, body, date_entered) VALUES
(NULL,'$_POST[header]', '$_POST[body]', NOW())";
> // Display the form.
> ?>
> <form action="edit_site.php" method="post">
> <p>Entry Title: <input type="text" name="header" size="40"
> maxsize="100" /></p>
> <p>Entry Text: <textarea name="body" cols="40" rows="5"></textarea></p>
> <input type="submit" name="submit" value="Add to the Site" />
> </form>
>
Norm
--
FREE Avatar hosting at www.easyavatar.com
Navigation:
[Reply to this message]
|