•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,504 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,681 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1746 | Replies: 5
![]() |
•
•
Join Date: Apr 2007
Posts: 34
Reputation:
Rep Power: 2
Solved Threads: 0
Hello again...
I've connected to th edb but i need to insert into the db in phpmyadmin....
I dont get any errors it says that it has inserted the data, but it hasn't...please help...
my code...
$link = mysql_connect('localhost', 'root', "");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
$query = "INSERT INTO information VALUES ('title', 'fname', 'mname',
'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')";
if (!$query) {
die('Data error ' . mysql_error());
}
echo 'Inserted successfully!';
I've connected to th edb but i need to insert into the db in phpmyadmin....
I dont get any errors it says that it has inserted the data, but it hasn't...please help...
my code...
$link = mysql_connect('localhost', 'root', "");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
$query = "INSERT INTO information VALUES ('title', 'fname', 'mname',
'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')";
if (!$query) {
die('Data error ' . mysql_error());
}
echo 'Inserted successfully!';
•
•
Join Date: Oct 2006
Posts: 14
Reputation:
Rep Power: 2
Solved Threads: 0
$link = mysql_connect('localhost', 'root', "");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
$query = "INSERT INTO information (title, fname, mname, lname, address, city, state, zip, email, memo) VALUES ('title', 'fname', 'mname',
'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')";
if (!$query) {
die('Data error ' . mysql_error());
}
echo 'Inserted successfully!';First of all, you close the connection before any queries are made.
Second, there isn't a query there
This should be the code you want:
mysql_connect('localhost', 'root', "") or die ('Could not connect ' . mysql_error());
$query = mysql_query("INSERT INTO information VALUES ('title', 'fname', 'mname',
'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')");
if (!$query) {
die('Data error ' . mysql_error());
}
echo 'Inserted successfully!';
mysql_close();Hope this will work
Last edited by Andy-Pandy : Jun 8th, 2007 at 5:44 pm.
•
•
Join Date: Feb 2007
Posts: 41
Reputation:
Rep Power: 2
Solved Threads: 2
You also might want to insert actual data instead of just the words: title, fname, mname etc.
If they are variables use $ sign before them.
If they are variables use $ sign before them.
•
•
Join Date: Aug 2005
Posts: 76
Reputation:
Rep Power: 4
Solved Threads: 1
Closing the connection shouldn't matter, but yes, you will need an actual query, rather than just initialising the sql statement.
or you can add else there lol..
The ProgrammersTalk Community | Programming & Marketing | Buying & Selling Script
Hang out place of novice and intermediate programmers
Hang out place of novice and intermediate programmers
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Rows not added correctly when using 'INSERT' (PHP)
- Need Help with "Please Insert Disk" message in Quark (Mac Software)
- insert image into mysql (Visual Basic 4 / 5 / 6)
- Program to tell if Insert,Caps, Numlock, Alt, Ctrl, Leftshift & Rightshift is pressed (C)
- How to insert an image into a GUI? (Java)
- 'Insert disk into drive c:\' when starting WinXP (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: PHP - creating subdomains - creating child websites for users
- Next Thread: Returning HTML code through SQL query?


Linear Mode