Jump to content

[SOLVED] One value result?


sam06

Recommended Posts

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

$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');

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?

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.