sam06 Posted July 5, 2008 Share Posted July 5, 2008 Hi there, I'm not too sure how to query the mysql database to get 1 specific result, and than use that in another query: <?php $offerid = $_GET['id']; mysql_connect("localho*************** or die(mysql_error()); mysql_select_db(*********") or die(mysql_error()); $result = mysql_query("SELECT Name FROM offers WHERE ID='$offerid"); mysql_query("INSERT INTO clicks (id, username, value) VALUES('$offerid', '$username', '$result' ) ") or die(mysql_error()); echo "Data Inserted!"; echo $result ?> It is inserting the ID, no username as I haven't defined it yet, but nothing for result. I put the echo $result to see if it was catching anything, and it's not. Cheers, Sam Quote Link to comment Share on other sites More sharing options...
Barand Posted July 6, 2008 Share Posted July 6, 2008 $result = mysql_query("SELECT Name FROM offers WHERE ID='$offerid"); This does not put the selected name into $result. $resullt is a resource ID of the results set retuned by the query. You need to get the name from this result set $result = mysql_query("SELECT Name FROM offers WHERE ID='$offerid"); $name = mysql_result ($result, 0, 'name'); Quote Link to comment Share on other sites More sharing options...
sam06 Posted July 6, 2008 Author Share Posted July 6, 2008 I've changed it so now it's : $result = mysql_query("SELECT Name FROM offers WHERE ID='$offerid"); $name = mysql_result ($result, 0, 'Name'); mysql_query("INSERT INTO clicks (id, username, value) VALUES('$offerid', '$username', '$name' ) ") or die(mysql_error()); echo "Data Inserted!"; echo $name But now it comes with "Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/sam06/public_html/reward/click.php on line 9" Line 9 is $name = mysql_result ($result, 0, 'Name'); Any Ideas? Quote Link to comment Share on other sites More sharing options...
Barand Posted July 6, 2008 Share Posted July 6, 2008 Then there's an error in your query. Use mysql_error() to find out what. Quote Link to comment Share on other sites More sharing options...
sam06 Posted July 6, 2008 Author Share Posted July 6, 2008 $result = mysql_query("SELECT Name FROM offers WHERE ID='$offerid"); $name = mysql_result ($result, 0, 'Name') or die(mysql_error()); How do you do it? The way I've put does nothing. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 6, 2008 Share Posted July 6, 2008 $result = mysql_query("SELECT Name FROM offers WHERE ID='$offerid") or die(mysql_error()); $name = mysql_result ($result, 0, 'Name'); Quote Link to comment Share on other sites More sharing options...
sam06 Posted July 6, 2008 Author Share Posted July 6, 2008 I'm jsut getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1' at line 1 Quote Link to comment Share on other sites More sharing options...
Barand Posted July 6, 2008 Share Posted July 6, 2008 Missing single quote after $offerid Quote Link to comment Share on other sites More sharing options...
sam06 Posted July 6, 2008 Author Share Posted July 6, 2008 That was it the whole time! Man you're great - many thanks ! Sam Quote Link to comment 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.