dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Displaying results that have a space

  1. #1
    Join Date
    Aug 2007
    Posts
    9

    Displaying results that have a space

    Hi there,

    Wondered if anyone could help, this may be more php side than SQL, im not sure, it involves them both.

    I have an SQL querie that is used to delete records from a database, it is as follows:

    Code:
    DELETE FROM categories WHERE category=$category
    The $category is generated from a drop down box (select/option in a HTML form) which is populated by a DISTINCT(category) statement.

    Now the only problem I have is that there is a record in the database called 'Plumbing & Heating' and when this record is selected the SQL statement trys to delete all records where the category=Plumbing and not the full Plumbing & Heating.

    Anyone else come across this problem and been able to resolve it?

    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,305
    Any non-numeric literal value must be quoted within SQL:
    PHP Code:
    $query "DELETE FROM categories WHERE category='$category'"
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Aug 2007
    Posts
    9
    Hi there,

    Sorry, that was just me rushing to write this before I went to bed, the code is exactly as follows:

    Code:
    	$sqlquery = "DELETE FROM manufacturers WHERE manufacturer='$removemanufacturer'";
    But as mentioned, when $removemanufacturer result has a space (eg. Norwich Union) The SQL is looking to remove 'Norwich'

    Any ideas?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,305
    Is the variable coming from a HTML form? If so, make sure you quoted the value in the form element, or it will ignore everything after the space.
    Code:
    <input type="text" name="foobar" value="<?php echo $value; ?>">
    It's best to just get in the habit of quoting all HTML element attribute values, as it is required for properly formatted XML and XHTML.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles