Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

SQL syntax in PHP

mysqli syntax

  • Please log in to reply
No replies to this topic

#1 Blue Indian

Blue Indian

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 61 posts

Posted 28 September 2010 - 11:42 AM

I am trying to implement a search function that searches a coffee database for all coffees containing all or part of the user's entered search string. The user enters a search string which I store below in a variable called $name.

I want to use this variable in a SQL statement and store it in a variable called $sql.

The following is a code segment that is producing a syntax error:

I am pretty sure the error is being caused by the where statement where I am trying to concatenate the $name variable into my sql statement.

$name = $_GET['name'];
        $sql = "
                select Coffee_SKU, Coffee_Name, category_name, coffee_details, coffee_price,
                coffee_roast, coffee_grind, coffee_picture, coffee_weight, coffee_price,
                from coffee, coffee_shops, categories
                where coffee_category_id = category_id and coffee_name like \'%" . $name . "%\'
        $rs = mysqli_query($conn, $sql);

  • 0

Also tagged with one or more of these keywords: mysqli, syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download