Insert Into

Reply

Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

Insert Into

 
0
  #1
Jun 8th, 2007
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!';
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 14
Reputation: Andy-Pandy is an unknown quantity at this point 
Solved Threads: 0
Andy-Pandy Andy-Pandy is offline Offline
Newbie Poster

Re: Insert Into

 
0
  #2
Jun 8th, 2007
  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 41
Reputation: hussulinux is an unknown quantity at this point 
Solved Threads: 2
hussulinux hussulinux is offline Offline
Light Poster

Re: Insert Into

 
0
  #3
Jun 10th, 2007
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.
Hussain Fakhruddin
Teks: http://www.teks.co.in
hussulinux at gmail dot com
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: Insert Into

 
0
  #4
Jun 11th, 2007
Closing the connection shouldn't matter, but yes, you will need an actual query, rather than just initialising the sql statement.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

Re: Insert Into

 
0
  #5
Jun 12th, 2007
Data error No database selected

I have created a db in phpMyAdmin...i get this error tho
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 83
Reputation: ProgrammersTalk is an unknown quantity at this point 
Solved Threads: 7
ProgrammersTalk's Avatar
ProgrammersTalk ProgrammersTalk is offline Offline
Junior Poster in Training

Re: Insert Into

 
0
  #6
Jun 18th, 2007
or you can add else there lol..
The ProgrammersTalk Community | Programming & Marketing | Buying & Selling Script
Hang out place of novice and intermediate programmers
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC