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
Share on other sites

But like i said all the others insert fine so all you need to know is the refip one as that is the only one that dont insert.

 

correct?

 


mysql_query("SELECT * FROM userdb WHERE `ipaddress` = '$refip' AND `id` = '$_GET[refer]'");

Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.