Data not getting populated

prasad.mhatre's Avatar

prasad.mhatre

23 Feb, 2012 04:47 AM

Dear friends,

I am trying to make this script work, but find it difficult.

I am using database to get the options. I do get No Results Found if I try wrong values, but if I give correct values it doesn't show anything.

I also found one uniquie problem the same script was working earlier night and the next day it failed, also if I add new data to my database it doesn't show up when the script was working, I did verified that the database is picked up correctly.

My code goes like this:

File: suggest.php




File: suggest2.php
<?
include ("../mystuffdb5.wphp");

  /* connect to the database */
 mysql_connect( "$hostname",  "$username",  "$password");
 @mysql_select_db( "$dbName") or die(  "Unable to select database");

$input = $GET["q"]; $data = array(); // query your DataBase here looking for a match to $input $query = mysql_query("SELECT * FROM mytable WHERE name LIKE '%$input%'"); while ($row = mysql_fetch_assoc($query)) {
$json = array(); $json['value'] = $row['id']; $json['name'] = $row['name']; $data[] = $json; } header("Content-type: application/json");
echo $json_encode($data);
echo $
POST['as_values_name'];
?>

Can anyone suggest what I am doing wrong?

Thanks for the great script.

Regards
Prasad

  1. 1 Posted by Jon on 27 Feb, 2012 09:08 AM

    Jon's Avatar

    Try:

    $input = mysql_real_escape_string($_GET['q']);
    $data= array();
    $query = ....................
    while ($row = mysql_fetch_assoc($query)) {
      $data[] = array("value" => $row["id"], "name" => $row["name"]);
    }
    echo json_encode($data);
    
  2. 2 Posted by prasad.mhatre on 01 Mar, 2012 06:38 AM

    prasad.mhatre's Avatar

    There was an error extra $ sign in jason.

    Thanks anyways Jon.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac