473,624 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($Partnu mber, $Partname, $Partdescriptio n)
{
//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_Descriptio n) values ($Partnumber, $Partname, $Partdescriptio n)";

if (mysql_query($D BName, $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($Li nk);

}

Krista
Jul 17 '05 #1
1 3341

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($Partnu mber, $Partname, $Partdescriptio n)
{
//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_Descriptio n) values ($Partnumber, $Partname, $Partdescriptio n)";

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


if (mysql_query($D BName, $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($Li nk);

}


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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2080
by: Michael J. Astrauskas | last post by:
I have a site where a user logs in and a session variable I created is used to keep track of the fact that the user is logged in. This various pages query a MySQL database to get information (mostly to generate a catalogue and news page). Occasionally when loading a page I simply get the error "No database selected" when the PHP script attempts to run the query. Usually I can press reload in my browser (Netscape, IE, and Opera) and the...
15
7378
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover - 03/03/2004)"); INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
11
7150
by: grumfish | last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code: connection = MySQLdb.connect(host="localhost", user="root", passwd="pw", db="japanese") cursor = connection.cursor() cursor.execute("INSERT INTO edict (kanji, kana, meaning) VALUES (%s, %s, %s)", ("a", "b", "c") ) connection.close() After running, a SELECT * on the table shows no new rows added. Adding
3
2231
by: hshen | last post by:
Hi All, I have encountered a weird behavoir of embedded MySQL. Through a simple program I made (in Delphi 6), I can insert rows to a table through embedded MySQL and I can retrieve the rows from my program. But using mysql.exe which points to the same table (through 127.0.0.1, with the same basedir and datadir), I cannot see the rows I inserted using my embedded program. Another way around, the rows inserted by mysql.exe can be seen...
8
5462
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
5
5082
by: smatta | last post by:
I have just installed MySql version 5.0-18 on Red Hat Fedora Core 4. It is running but I cant connect to it using MySql Query Browser running on my pc. >From my pc, I can telnet to the sql server / port. I get back a garbled message: 5.0.18-standard§}WxyuadT,☻V6F?J5i1YMT= Should this be garbled ? or is there a problem ?
0
3619
by: james.peer | last post by:
I'm fairly new to this so hopefully it is a dumb mistake... I need to create a simple stored procedure along the lines of: delimiter // CREATE DEFINER='root'@'localhost' PROCEDURE Insertuser() BEGIN insert into user (firstname,lastname) values (@fn, @ln); END; //
3
4904
by: FNA access | last post by:
Hello all, I am relitivley new to mySQL. I started by downloading from the mySQL site. I then downloaded mySQL administrator and mySQL Query browser. With my set up I got a user root with a specified password. I created a DB(school) . When I log into mySQL Query browser with root connection, I see all my tables etc. I even see the information_schema. I can select anything from anything. I set up a new user (student)that has...
3
1943
by: Hazza | last post by:
Hi, I am using PHP and mysql to create a website. I am fairly new to PHP, and thus am grateful to anyone who helps! Firstly I am running a homepage, that displays additional content if a user has logged in. I set a loggedin session in the log in page, which I have tested and works fine in other scripts. I am displaying news on the homepage (which is stored in a mysql database), and this works fine when the user accesses the homepage...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.