Results 1 to 4 of 4
  1. #1
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    I am Stumped with a PHP/MYSQL problem
    I have a search form (_POST) on the top of my pages that goes to a search.php page where I try and retrieve some records from my database.

    //Some pseudo code
    Code:
    $find = stripslashes($_POST['find']);
    mysql_connect("cccc", "ccccc", "cccc");
    $find = mysql_real_escape_string( $find );
    
    //Update search activity table
    echo "[" . $find . "]";  //Prints out the string "green"
    $query = "INSERT INTO mydb.search (searchfor) VALUES ('$find')";
    $result = mysql_query($query);
    When I put "green" in the search form, I can see "[green]" printed out at the top of the search.php page. That's all groovy.

    The problem is that when I look at the latest entry in my search database table, I see a string other than the word "green". I echo $find var on the line before the insert which looks fine.

    Any ideas?
    Last edited by Uncle Rico; August 12th, 2010 at 11:42 AM.

  2. #2
    Member esnagel's Avatar
    Join Date
    January 1st, 2008
    Location
    Buffalo, NY
    Posts
    88
    What happens when you echo $query? What's the structure for the search table?

  3. #3
    Full Member iolaire's Avatar
    Join Date
    October 3rd, 2006
    Location
    Arlington, VA
    Posts
    229
    Quote Originally Posted by Uncle Rico View Post
    The problem is that when I look at the latest entry in my search database table, I see a string other than the word "green".
    Maybe the table is not deplaying in the order you expect, i.e. last in equals last in the view.

    Try using unique search values to test each time. So for example for one round use green1a1, then run a select statment to see if that unique value (green1a1) is now in the database.

  4. #4
    Newbie
    Join Date
    July 23rd, 2010
    Location
    Monterrey, Mexico
    Posts
    45
    Hello Uncle Rico,

    You forgot to escape the $find variable, use .$varname. to concatenate strings!

    $query = "INSERT INTO mydb.search (searchfor) VALUES (" . $find . ")";

    Hope this helps!

    http://php.net/manual/en/language.operators.string.php
    Last edited by emilioolivares; August 13th, 2010 at 06:20 PM.

  5. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP and MySQL Knowledge
    By scm21st in forum Midnight Cafe'
    Replies: 5
    Last Post: August 5th, 2007, 10:30 PM
  2. looking for php/mysql work
    By spiderninja in forum Midnight Cafe'
    Replies: 0
    Last Post: January 31st, 2007, 11:12 PM
  3. Php Mysql - Repeating..??
    By AddHandler in forum Programming / Datafeeds / Tools
    Replies: 13
    Last Post: May 7th, 2005, 03:25 PM
  4. PHP & mySQL but....
    By perfectG in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: November 6th, 2002, 06:58 AM

Posting Permissions

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