You are here: Re: ok problems entering data into database « PHP Programming Language « IT news, forums, messages
Re: ok problems entering data into database

Posted by so many sites so little time on 11/23/06 00:22

yeah i think im gonna insert null i just wat to be able to post text so
that it appears like the content of a web page and then can be edited
but when ive been going and trying to edit it say i say home_id 1 or
what ever and then i tell it to get from row 1 it returns a error
which i tell it to if it didnt get an id

Gordon Burditt wrote:
> > ok so i am having problems if you look at the script below you will
> >see that it the query has 4 values to insert but the actual values only
> >contain title entry and now() for the date. well i have made the
> >database and the blog_id is a primary auto interger what ever table
> >bascly look below the the insert code block to find the code block
> >that makes the table in the database,
> >
> >
> >// Define the query.
> > $query = "INSERT INTO blog_entries (blog_id, title, entry,
> >date_entered) VALUES ('{$_POST['title']}', '{$_POST['entry']}',
> >NOW())";
> >
> > // Execute the query.
> > if (@mysql_query ($query)) {
> > print '<p>The blog entry has been added.</p>';
> > } else {
> > print "<p>Could add the entry because: <b>" . mysql_error() . "</b>.
> >The query was $query.</p>";
> > }
> >
> >---------------------------------------------------------------------------------------------------------------------------------------------------
> >
> >
> >// Define the query.
> >$query = 'CREATE TABLE blog_entries (
> > blog_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
> > title VARCHAR(100) NOT NULL,
> > entry 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>');
> >}
> >
> >---------------------------------------------------------------------------------------------------------------------------------------------
> >>>>>blog_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,<<<<
> >basicly that right above is what the table looks like now though if i
> >go and run the insert script it says that the collumns dont match the
> >values ect. but how can i get it to utilize the blog id table?
> >what do i enter as a value?
>
> You have three columns and two values in your insert. You need
> the number of columns and the number of values to match.
>
> If you leave the blog_id column out of the insert, it will get
> filled in with an auto-increment value. This, I think, is what you
> want.
>
> If you leave the blog_id column in the insert, and supply null as
> a matching value, it will still get filled in with an auto-increment
> value. This, I think, is what you want, done another way.
>
> On the other hand, if you leave the blog_id column in the insert,
> and supply a number as a matching value, it will insert that value.
> Among other things, this lets you restore tables from a backup
> without messing up the auto-increment entries.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация