|
Posted by Jerry Stuckle on 11/19/06 22:57
Norman Peelman wrote:
> "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:
>
Incorrect. It is perfectly valid to not enter home_id in the INSERT
statement. The autonum value will be used.
> $query = "INSERT INTO home (home_id, header, body, date_entered) VALUES
> (NULL,'{$_POST['header']}', '{$_POST['body']}', NOW())";
>
This will also work, but is not necessary.
> ...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())";
>
>
Additionally, you should never use data entered by the user without
validating it. Additionally, any data entered should be processed by
mysql_real_escape_string() before placing in the database.
>
>
>
>
>>// 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
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|