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

Link to comment
Share on other sites

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