dh091275 Posted July 10, 2007 Share Posted July 10, 2007 MySQL client version: 4.0.16 Ok i am having a little problem with the following converting mysql into php. Using the following mysql statement INSERT INTO Url_User( Userid, Urlid ) SELECT 'bob', Urlid FROM Urls WHERE url = 'www.excel.com'; Now I can get the following code to work if i hard code it e.g(Bob and www..adobe.com). $sql = 'INSERT INTO Url_User( Userid, Urlid ) ' . ' SELECT \'bob\', Urlid' . ' FROM Urls' . ' WHERE url = \'www.excel.com\';'; mysql_query ($sql); the problem that i have is when i try to insert variables into the sql statement. For example, if i replace bob with $x (e.g. $x = bob1;) then the code doesnt pick up the variable it inserts "$x" into the table. Now if i strip the \' s from the code (ie \'$x\' to $x) it still doesn't work. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/59249-solved-insert-into-and-select-with-variables/ Share on other sites More sharing options...
Illusion Posted July 10, 2007 Share Posted July 10, 2007 try this $sql = "INSERT INTO Url_User (Userid,Urlid) SELECT '$x','$Y' from URls where url=''www.excel.com'"; . Link to comment https://forums.phpfreaks.com/topic/59249-solved-insert-into-and-select-with-variables/#findComment-294271 Share on other sites More sharing options...
dh091275 Posted July 10, 2007 Author Share Posted July 10, 2007 Thanks managed to get it to work with this... $sql1 = "INSERT INTO Url_User (Userid,Urlid) SELECT '$entry[userid]', Urlid from Urls where url='$x'"; mysql_query($sql1); I was just getting confused. I created the orginally query in myphpadmin and generated the php code from there. Thought that i would be able to just insert the variables. Thanks again Link to comment https://forums.phpfreaks.com/topic/59249-solved-insert-into-and-select-with-variables/#findComment-294295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.