Date: Tue, 30 Mar 2004 15:13:35 +0800
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: INSERT problem--Need help urgently
Hi all:
I was having some problem with INSERT query here and
do hope to get
some help
real soon.
I have a form whereby once the form is submitted, the
values entered
shall be
inserted into the database. Next I have also written a
SELECT query to
view the
records which have just been inserted into the
database.
Data was able to insert into the database and I was
also able to
retrieve these
data from database. However, my problem is, whenever a
form was being
submitted, it actually INSERT another row of null
values into the
database. And
so, when I clicked to view my data, i can see the
previously inserted
values as
well as an empty row of records.
Why is this so? How can I prevent the row of null
value to be inserted?
I have included a snip of my code below and hope to
get some help real
soon.
All help are greatly appreciated. Thanks in advance.
<snip>
$dsn = "mysql://root:[EMAIL PROTECTED]/databaseName";
$db = DB::connect ($dsn);
if (DB::isError ($db))
die ($db->getMessage());
$tutor_name = $_POST["tutor_name"];
$tutor_contact = $_POST["tutor_contact"];
$tutor_email = $_POST["tutor_email"];
$tutor_profile = $_POST["tutor_profile"];
$sql ="INSERT INTO tutor (tutor_name, tutor_contact,
tutor_email,
tutor_profile)
VALUES('$tutor_name','$tutor_contact','$tutor_email','$tutor_profile')";
$result = $db->query($sql);
if( DB::isError($result) ) {
die ($result->getMessage());
}
?>
</snip>
Is there anything wrong with my SELECT query ??
Thanks in advance.
Regards,
Irin
----
Hi Irin,
Can't say I have ever used $dsn connection you have
above. So maybe this will NOT help one little bit,
least I tried. ;)
<snip>
$sql ="INSERT INTO tutor (tutor_name, tutor_contact,
tutor_email,
tutor_profile)
VALUES('$tutor_name','$tutor_contact','$tutor_email','$tutor_profile')";
</snip>
1: I suggest you NOT use the same form names as the
field name. Keep it basic... Something like.
tutor_name = t_n
tutor_contact = t_c
Your using the same names for the form and db fields.
Try and change the form names to something different,
easier to edit also and can't manke errors. :)
Instead of using VALUE why not use...
tutor_name='$t_c' , tutor_contact='t_c' ...
I found using that method better than using the VALUE
option. So that's why I use that method mostly, I
found using VALUE can be a problem and real problems
to edit since you needed to know the right number
accross to change or add a field. Having my way you
can add it wherever/change etc without needing to
waste time working out what goes where.
$dsn I don't recommend using. I have found not all
servers support it either which is odd. Some don't
connect to the db at all but if you use a basic $sql
it will.
But I dunno if this helps, if not why not use $sql
rather than $dsn I am sure you will find it easier to
use as a newbie and or professional.
J
P.S. Sorry if someone has already fixed your
problem... Goodluck!
Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php