Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT problems..again! 1

Status
Not open for further replies.

QuietDean

Instructor
Mar 10, 2001
163
GB
I know you get loads of these 'can't use insert' problems, so I have read all of them and not found why my insert query is not working. Heres the insert -


$resultat_sql = mysql_db_query(&quot;INSERT INTO 'indy' (name,email,rank) VALUES ('$name', '$email', '$rank')&quot;, $connexion) or die(&quot; <br>Didnt work&quot;);
echo &quot;Added&quot;;


It works a treat if I use fixed values, but variables are a no-go.

Any ideas?

I'm a mySQL newbie, so be gentle. Dean Owen
 
It's actually not your mySQL, but your PHP. The mysql_db_query() function takes two arguemnts, both strings:

You have:[tt]
$resultat_sql = mysql_db_query(&quot;INSERT INTO 'indy' (name,email,rank) VALUES ('$name', '$email', '$rank')&quot;, $connexion) or die(&quot; <br>Didnt work&quot;);
echo &quot;Added&quot;;
[/tt]

Where it should be:
[tt]
$resultat_sql = mysql_db_query(&quot;database&quot;,&quot;INSERT INTO 'indy' (name,email,rank) VALUES ('$name', '$email', '$rank')&quot;) or die(&quot; <br>Didnt work&quot;);
echo &quot;Added&quot;;
[/tt]

Also, I suggest several things:
1. You download the PHP manual or check it online at it will solve most problems like this.
2. You store your queries in a variable so that code can be read easier:
[tt]
$sql = &quot;INSERT INTO table(id,field1,field) VALUES ('','$var1','$var2')&quot;;
$result = mysql_db_query($database,$sql);
[/tt]

Just suggestions.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
I don't know but try mysql_query instead of mysql_db_query.

// Henrik
 
Just suggestions they may be, but very good ones. Thank you.

I have the php manual in html-help format, but I guess I missed that. PHP newbie!
Again, thanks. Have a gold(red) star. Dean Owen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top