| | |
Insert Into
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2007
Posts: 34
Reputation:
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:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
$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:
PHP Syntax (Toggle Plain Text)
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 6:44 pm.
•
•
Join Date: Feb 2007
Posts: 41
Reputation:
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:
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
![]() |
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?
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





