| | |
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?
Views: 3792 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube





