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); Link to comment https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/ 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? Link to comment https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/#findComment-1146613 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()); Link to comment https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/#findComment-1146616 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?! Link to comment https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/#findComment-1146629 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! Link to comment https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/#findComment-1146630 Share on other sites More sharing options...
jarv Posted December 13, 2010 Author Share Posted December 13, 2010 please help Link to comment https://forums.phpfreaks.com/topic/221500-cannot-insert-into-is-my-code-ok/#findComment-1146682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.