2

I am getting a parser error whenever I try to execute a program.

Parse error: parse error, unexpected '.' in /var/www/html/spywgc/adm/ctshell/getproduct/getproduct.php on line 9

This is the code

$select_url= " select product_id from sp_url where url like '%.$url.%'";

$url is a string and I want to retrieve it from database to assign it to $select_url.

1
  • What is the value of $url? Could you post the lines above and below this line too? Commented Apr 15, 2011 at 18:36

4 Answers 4

3

The line you posted is syntactically correct. The real error is that somewhere BEFORE that line, you have a string with an unterminated '.

$somevar = 'blah blah    <--missing ' here
... blah blah blah ...
$select_url = "...... '%   <---string closes here

So you're ending up with

$somevar = 'big long string select product_id .... ' % .

% is the modulo operator, which would normally be fine, but then it's followed by a . which isn't valid.

"string modulo concatenate"

and as others have said, your string is internally incorrect. You're using a double-quoted string, so there's no need for the attempt at concatenation within the string.

Sign up to request clarification or add additional context in comments.

Comments

1

I'm not sure if you meant to have the dots in there, but you can do any of the following:

  • $select_url= "select product_id from sp_url where url like '%.{$url}.%'";
  • $select_url= "select product_id from sp_url where url like '%." . $url . ".%'";

1 Comment

@vincy: Have a look at @Marc B's answer. This error is an indication that he is right. I asked you to post more of your code, but you didn't. It would have been so much easier to help you.
0

Based on what you have presented above I am assuming you want to do something like this

   /* Assuming you have a database connection already */
    $result = mysql_query("SELECT product_id FROM sp_url WHERE url LIKE '%".$url."%'";
    $row = mysql_fetch_assoc($result);
    $select_url = $row['product_id'];

edit: you may want to escape $url as well mysql_real_escape_string($url)

Comments

0

Dots arent even needed, you could end with something like that:

$select_url= "SELECT product_id FROM sp_url WHERE url LIKE '%$url%'";

And then make your mysql_query with this string.

1 Comment

Could you add a Sample value of the string?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.