Jump to content

Another INSERT problem


R1der

Recommended Posts

Ok i am trying to insert something into referals database but its not inserting the users ipaddress can anyone see a problem?

 

mysql_query("SELECT * FROM userdb WHERE `ipaddress` = '$refip' AND `id` = '$_GET[refer]'");
mysql_query("INSERT INTO referals (id, refer, referip, referedip, refered) VALUES ('', '$refer', '$refip', '$ip', '$username')") or die(mysql_error());

 

All insert right except 'referip'

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/54910-another-insert-problem/
Share on other sites

... can anyone see a problem?

 

mysql_query("SELECT * FROM userdb WHERE `ipaddress` = '$refip' AND `id` = '$_GET[refer]'");
mysql_query("INSERT INTO referals (id, refer, referip, referedip, refered) VALUES ('', '$refer', '$refip', '$ip', '$username')") or die(mysql_error());

 

Yes. You never retrieve any values from anywhere.  You do execute a database query but you don't get the values returned by that query.

Well, you're telling the query to select the one the 'ipaddress' that matches $refip so $refip needs to already have a value set for it. Usually that is done by something like a:

 

$refip = $_POST['refip'];

 

from a form, for example. Or, possibly something passed in the url like this:

 

$refip = $_GET['refip'];

 

Now, in your query, it will match the value of that $refip with the value in the 'ipaddress' field.

Ok, let's walk through that a step at a time:

 

get the user's ip address from the userdb

 

mysql_query("SELECT ipaddress FROM userdb

 

where the 'id' is 'refer' then it will insert..blah blah

 

WHERE `id` =  '$_GET[refer]'");

 

Now, all you need is to make sure you pass the 'refer' through the URL so the $_GET snags it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.