User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,504 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,681 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1746 | Replies: 5
Reply
Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

Insert Into

  #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!';
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Posts: 14
Reputation: Andy-Pandy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Andy-Pandy Andy-Pandy is offline Offline
Newbie Poster

Troubleshooting Re: Insert Into

  #2  
Jun 8th, 2007
$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
Last edited by Andy-Pandy : Jun 8th, 2007 at 5:44 pm.
Reply With Quote  
Join Date: Feb 2007
Posts: 41
Reputation: hussulinux is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
hussulinux hussulinux is offline Offline
Light Poster

Re: Insert Into

  #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  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: Insert Into

  #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  
Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

Re: Insert Into

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

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

Re: Insert Into

  #6  
Jun 17th, 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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC