jarv Posted December 13, 2010 Share Posted December 13, 2010 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); Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 13, 2010 Share Posted December 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 13, 2010 Share Posted December 13, 2010 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()); Quote Link to comment Share on other sites More sharing options...
jarv Posted December 13, 2010 Author Share Posted December 13, 2010 there is no UPDATE I am trying to SELECT and INSERT I know the code works, it's worked before, just a problem with rsTown?! Quote Link to comment Share on other sites More sharing options...
jarv Posted December 13, 2010 Author Share Posted December 13, 2010 I am also having problems echoing out! Quote Link to comment Share on other sites More sharing options...
jarv Posted December 13, 2010 Author Share Posted December 13, 2010 please help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.