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 Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/ 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'); Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582602 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? Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582794 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. Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582796 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. Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582797 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'); Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582798 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 Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582799 Share on other sites More sharing options...
Barand Posted July 6, 2008 Share Posted July 6, 2008 Missing single quote after $offerid Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582800 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 Link to comment https://forums.phpfreaks.com/topic/113376-solved-one-value-result/#findComment-582804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.