470,849 Members | 1,097 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

cannot insert in mysql using php

Hi guys, i have a problem about inserting data into the table. I dont
know why the output always said cannot be added to the database!
Anyone has idea for me?
i check the connect is ok, but dont know why.
The following is a function i will call to insert the database.
Thx!!!
function AddPart($Partnumber, $Partname, $Partdescription)
{
//Set the variables for the database
$DBName="krista";
$TableName = "parts";
$Link = mysql_connect("localhost","","") or die ('I cannot connect to
the database because: ' . mysql_error());
mysql_select_db($DBName,$Link);

$Query = "INSERT into $TableName (Part_Number, Part_Name,
Part_Description) values ($Partnumber, $Partname, $Partdescription)";

if (mysql_query($DBName, $Query, $Link)){

print("Your information is successfully added to the database!!
<BR>\n");
}
else{
print("Your information cannot be added to the database! <BR>\n");
}

//close MySQL
mysql_close($Link);

}

Krista
Jul 17 '05 #1
1 3195

On 19-Dec-2003, yw*****@hotmail.com (Krista) wrote:
Hi guys, i have a problem about inserting data into the table. I dont
know why the output always said cannot be added to the database!
Anyone has idea for me?
i check the connect is ok, but dont know why.
The following is a function i will call to insert the database.
Thx!!!
function AddPart($Partnumber, $Partname, $Partdescription)
{
//Set the variables for the database
$DBName="krista";
$TableName = "parts";
$Link = mysql_connect("localhost","","") or die ('I cannot connect to
the database because: ' . mysql_error());
mysql_select_db($DBName,$Link);

$Query = "INSERT into $TableName (Part_Number, Part_Name,
Part_Description) values ($Partnumber, $Partname, $Partdescription)";

Unless the data are numeric, you need to enclose their values in
apostrophies like this:
Part_Description) values ('$Partnumbe'r, '$Partname', '$Partdescription')";


if (mysql_query($DBName, $Query, $Link)){

print("Your information is successfully added to the database!!
<BR>\n");
}
else{
print("Your information cannot be added to the database! <BR>\n");
please change the above to
print("Your information cannot be added to the database! <br>
$Query failed because ".mysql_error()."<BR>\n");

You will find the additional information very helpful in debugging.

}

//close MySQL
mysql_close($Link);

}


--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael J. Astrauskas | last post: by
11 posts views Thread by grumfish | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.