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
https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/
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?

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

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.