Forum Moderators: coopster

Message Too Old, No Replies

Select with Variable Question

         

TroyE

12:40 am on Sep 11, 2009 (gmt 0)

10+ Year Member



I have searched all over the internet and seen many ways to do this, but none of them seem to work. I have only put the echo in here to test the result. Any help would be very much appreciated.

$qlsid = $qls->user_info['id'];
echo $qlsid;
//look up variableid
$variableidqry = "SELECT variableid FROM 'table_users' WHERE 'qls3_Id'=".$qlsid";
$variableid = mysql_query($variableidqry) or die("Query failed : " . mysql_error());
echo $variableid;

rocknbil

3:24 am on Sep 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard TroyE, what are you getting, a failure on the query? By the looks of it, you are. You don't quote the field names, and don't need to quote the table names. You also have an extra quote there at the end.

$variableidqry = "SELECT variableid FROM 'table_users' WHERE 'qls3_Id'=".$qlsid";

If it's a numeric field, you don't need to quote the value, but it doesn't hurt it. So any of these should work.

$variableidqry = "SELECT variableid FROM table_users WHERE qls3_Id=" . $qlsid;

Since double quotes interpolate variables, you can also do this. You might think the first single-quoted value of $qlsid won't interpolate, but that value is already interpolated by the PHP double quotes. The single quotes are passed through to the mysql select statement.

$variableidqry = "SELECT variableid FROM table_users WHERE qls3_Id='$qlsid'";

$variableidqry = "SELECT variableid FROM table_users WHERE qls3_Id=$qlsid";

TroyE

10:28 am on Sep 11, 2009 (gmt 0)

10+ Year Member



rocknbil, Thanks I got this working. I appreciate the help.

TroyE

11:40 am on Sep 11, 2009 (gmt 0)

10+ Year Member



I have tested and I am getting a blank page when running the whole script.

When I get down to
$groupid = mysql_query($groupidqry) or die("Query failed : " . mysql_error());

I get Query failed : Unknown column 'Array' in 'where clause'

Any thoughts on this?

// get the twitterid
$variableidqry = "SELECT variableid FROM table_users WHERE qls3_Id=".$qls->user_info['id'];
$variableid = mysql_query($variableidqry) or die("Query failed : " . mysql_error());

$variableidrow = mysql_fetch_assoc(variableid);

//look up forum_group_id
$groupidqry = "SELECT id FROM feeder_keyword_groups WHERE name=".$variableidrow;
$groupid = mysql_query($groupidqry) or die("Query failed : " . mysql_error());

$groupidrow = mysql_fetch_assoc($groupid);

//Assign each array to a variable

foreach($_POST['keyword'] as $row=>$key)
{
$keyword=$key;
}

// Assigns $keyword as variable

foreach($_POST['keyword'] as $row=>$key)
{
$keyword=mysql_real_escape_string($key);
}

//Inserts into database

$involv = "INSERT INTO feeder_keyword (id, keyword, forum_id, group_id, type, status, rotate_urls)
VALUES ('','.$keyword.', 2, '.$groupid.;', '.$row['userid'].', 0, 1, '')";

var_dump($involv);
if (!mysql_query($involv))
{
die('Error: ' . mysql_error());
}
echo "$row record added";