944,103 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 6542
  • PHP RSS
Jun 8th, 2007
0

Insert Into

Expand Post »
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!';
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
pbrookee is offline Offline
34 posts
since Apr 2007
Jun 8th, 2007
0

Re: Insert Into

PHP Syntax (Toggle Plain Text)
  1. $link = mysql_connect('localhost', 'root', "");
  2. if (!$link) {
  3. die('Could not connect: ' . mysql_error());
  4. }
  5. echo 'Connected successfully';
  6. mysql_close($link);
  7. $query = "INSERT INTO information (title, fname, mname, lname, address, city, state, zip, email, memo) VALUES ('title', 'fname', 'mname',
  8. 'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')";
  9. if (!$query) {
  10. die('Data error ' . mysql_error());
  11. }
  12. 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)
  1. mysql_connect('localhost', 'root', "") or die ('Could not connect ' . mysql_error());
  2. $query = mysql_query("INSERT INTO information VALUES ('title', 'fname', 'mname',
  3. 'lname', 'address', 'city', 'state', 'zip', 'email', 'memo')");
  4. if (!$query) {
  5. die('Data error ' . mysql_error());
  6. }
  7. echo 'Inserted successfully!';
  8. mysql_close();

Hope this will work
Last edited by Andy-Pandy; Jun 8th, 2007 at 6:44 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Andy-Pandy is offline Offline
14 posts
since Oct 2006
Jun 10th, 2007
0

Re: Insert Into

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.
Reputation Points: 10
Solved Threads: 2
Light Poster
hussulinux is offline Offline
41 posts
since Feb 2007
Jun 11th, 2007
0

Re: Insert Into

Closing the connection shouldn't matter, but yes, you will need an actual query, rather than just initialising the sql statement.
Reputation Points: 31
Solved Threads: 1
Junior Poster in Training
leelee is offline Offline
76 posts
since Aug 2005
Jun 12th, 2007
0

Re: Insert Into

Data error No database selected

I have created a db in phpMyAdmin...i get this error tho
Reputation Points: 10
Solved Threads: 0
Light Poster
pbrookee is offline Offline
34 posts
since Apr 2007
Jun 18th, 2007
0

Re: Insert Into

or you can add else there lol..
Reputation Points: 21
Solved Threads: 7
Junior Poster in Training
ProgrammersTalk is offline Offline
83 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP - creating subdomains - creating child websites for users
Next Thread in PHP Forum Timeline: Returning HTML code through SQL query?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC