Jump to content

cannot insert into, is my code ok?


jarv

Recommended Posts

hi, this piece of code is not working, is it ok?

 

$query1 = "SELECT * FROM members_copy WHERE RSUSER = '".$RSUSER."' AND RSPASS = '".$RSPASS."'";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);

$_SESSION['USERID']=$row1['USERID'];
$_SESSION['rsTown']=$row1['rsTown'];
$_SESSION['RSEMAIL']=$row1['RSEMAIL'];
$_SESSION['RSUSER']=$row1['RSUSER'];

$pSQL = "INSERT INTO favepub_copy (USERID,PUBID)";
$pSQL = $pSQL."SELECT ".$_SESSION['USERID'].", PUBID ";
$pSQL = $pSQL."FROM pubs ";
$pSQL = $pSQL."WHERE rsTown = '".$rsTown;
//echo "hello world";
//echo $pSQL;
//exit();
mysql_query($pSQL);

Link to comment
Share on other sites

First off, while the way you concatenate variables is fine... it's easier to read if you do something like

 

$pSQL = "INSERT INTO favepub_copy (USERID,PUBID)";
$pSQL .= "SELECT ".$_SESSION['USERID'].", PUBID ";

 

Achieves the same goal, however, what are you trying to do with this query? Because it ends up being...

 

INSERT INTO blah values SELECT userid, pubid FROM pubs WHERE rsTown = $rsTown...

 

What are you trying to do, insert data, select data, or update data already in the database?

Link to comment
Share on other sites

try this:

$query1 = "SELECT * FROM members_copy WHERE RSUSER = '$RSUSER' AND RSPASS = '$RSPASS'";
echo $queryl;
$result1 = mysql_query($query1) or die(mysql_error());
$row1 = mysql_fetch_array($result1);
print_r($row1);

$_SESSION['USERID']=$row1['USERID'];
$_SESSION['rsTown']=$row1['rsTown'];
$_SESSION['RSEMAIL']=$row1['RSEMAIL'];
$_SESSION['RSUSER']=$row1['RSUSER'];

$pSQL = "INSERT INTO favepub_copy (USERID,PUBID) VALUES ('{$_SESSION['USERID']}','PUBID')";
echo $pSQL;
mysql_query($pSQL) or die(mysql_error());

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.