Jump to content

Recommended Posts

 

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?

 

 

 

 

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

 

 

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.