Results 1 to 3 of 3

Thread: Having issue with SELECT * FROM

  1. #1
    Join Date
    Nov 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having issue with SELECT * FROM

    Code:
    <?php
    
    $connection = mysql_connect("xxxxxx", "xxxxxx", "xxxxx","xxxxxxx") or die ("Couldn't connect to server."); 
     
    $db = mysql_select_db("persons", $connection) or die ("Couldn't select database.");  
    
        $search=$_POST['search']; 
    
    $data = 'SELECT * FROM `table_name` WHERE `ID` = "'.$search.'"'; 
    
      $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); 
    
      $data2 = mysql_fetch_array($query); 
       
       
    ?>
    still getting this ERR Couldn't execute query. No such file or directory
    Last edited by Beverleyh; 11-12-2015 at 06:43 AM. Reason: Formatting

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Try removing the weird apostrophes around `table_name`and `ID`and check that table_name is correct
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Try echoing $data and see what query is being sent.

    EDIT:

    The backtics you are using are fine. They are known as identifiers and allow you to use odd names for tables and columns that are outside of the normal [a-zA-Z_0-9] character list. I personally don't use them. For more on identifiers see this:

    http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

    It appears the MySQL website has been updated finally and is actually user friendly now. I was beginning to wonder if they would ever update their website

    In your case if you echoed your query it would look like this:

    SELECT * FROM `table_name` WHERE `ID` = "search"

    where search is whatever your search term or phrase is. Notice that your quotes are being displayed as well. I have not tested it, but the additional quotes you have added should not be necessary. I would just use

    Code:
    $data = "SELECT * FROM table_name WHERE ID = $search";
    You are also using the very deprecated mysql as opposed to the standard mysqli

    Here is one of my typical queries using this method:

    Code:
    $get_addresses        = "SELECT ID FROM news WHERE ID = $ID";
       $get_addresses_res = mysqli_query($conn,$get_addresses);
           $add_info      = mysqli_fetch_array($get_addresses_res);
               $ID        = $add_info['ID'];
    To read more about it go here: http://dev.mysql.com/downloads/connector/php-mysqlnd/

    There is also one or two threads here you should take a look at:

    http://www.dynamicdrive.com/forums/s...ng-deprecated-!

    In fact I'm thinking the above thread should be stickied to the MySQL forum.
    Last edited by james438; 11-14-2015 at 03:45 AM. Reason: added more info
    To choose the lesser of two evils is still to choose evil. My personal site

Similar Threads

  1. Chained select menu issue
    By jackcall in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 09-28-2010, 01:03 AM
  2. Resolved SELECT issue
    By AdrielGreene in forum MySQL and other databases
    Replies: 4
    Last Post: 04-24-2009, 02:44 PM
  3. File size issue w/chained select menu
    By fastsol in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 04-30-2008, 09:23 PM
  4. Replies: 0
    Last Post: 11-09-2007, 10:26 PM
  5. any link dropdown menu select box in IE issue
    By kalisurfer in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 09-12-2005, 09:50 PM

Bookmarks

Posting Permissions

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