R1der Posted June 9, 2007 Share Posted June 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/ Share on other sites More sharing options...
simcoweb Posted June 9, 2007 Share Posted June 9, 2007 Please show us where/how you have those variables defined. Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271562 Share on other sites More sharing options...
R1der Posted June 9, 2007 Author Share Posted June 9, 2007 How do u mean? Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271566 Share on other sites More sharing options...
simcoweb Posted June 9, 2007 Share Posted June 9, 2007 These variables: $refer '$refip $ip $username have to have their values set somehow/somewhere. Show me how you set the values. Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271569 Share on other sites More sharing options...
R1der Posted June 9, 2007 Author Share Posted June 9, 2007 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]'"); Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271571 Share on other sites More sharing options...
AndyB Posted June 9, 2007 Share Posted June 9, 2007 Quote ... 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. Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271578 Share on other sites More sharing options...
R1der Posted June 9, 2007 Author Share Posted June 9, 2007 So how would i do that? Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271580 Share on other sites More sharing options...
simcoweb Posted June 9, 2007 Share Posted June 9, 2007 This segment: WHERE `ipaddress` = '$refip' Where/how is $refip set? Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271581 Share on other sites More sharing options...
R1der Posted June 9, 2007 Author Share Posted June 9, 2007 I thought it was set in that select query? Sorry i am confused :S Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271583 Share on other sites More sharing options...
AndyB Posted June 9, 2007 Share Posted June 9, 2007 Time to take a look at any of the simple MySQL tutorials around (and on this site). All a query does is return a resource. Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271585 Share on other sites More sharing options...
simcoweb Posted June 9, 2007 Share Posted June 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271586 Share on other sites More sharing options...
R1der Posted June 9, 2007 Author Share Posted June 9, 2007 Basicly i want it to get the users ip address from the userdb where there 'id' is 'refer' then it will insert there ip address in the referals database being 'refid' Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271589 Share on other sites More sharing options...
simcoweb Posted June 9, 2007 Share Posted June 9, 2007 Ok, let's walk through that a step at a time: get the user's ip address from the userdb Quote mysql_query("SELECT ipaddress FROM userdb where the 'id' is 'refer' then it will insert..blah blah Quote WHERE `id` = '$_GET[refer]'"); Now, all you need is to make sure you pass the 'refer' through the URL so the $_GET snags it. Quote Link to comment https://forums.phpfreaks.com/topic/54910-another-insert-problem/#findComment-271595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.