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!';

Recommended Answers

All 5 Replies

$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 :)

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.

Closing the connection shouldn't matter, but yes, you will need an actual query, rather than just initialising the sql statement.

Data error No database selected

I have created a db in phpMyAdmin...i get this error tho

or you can add else there lol..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.