Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    95
    Thanks
    13
    Thanked 1 Time in 1 Post

    my query seems its wrong

    Hello i am trying to make a simple ajax database search like it explain Here
    http://www.w3schools.com/php/php_ajax_database.asp
    But when i am trying to display records it pops that i have an error on my query line which is this:
    Code:
    "SELECT * FROM products WHERE productid = '".$q."'"
    The 'q' is the user option.
    Did i use an invalid format or what?
    Soz i am new in programming

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,438
    Thanks
    23
    Thanked 630 Times in 629 Posts
    Your missing and end ;

    Otherwise it look ok.


    I hope your query looks like this in its entirety.

    $query = "SELECT * FROM products WHERE productid = '" . $q . "'";
    $result = mysql_query($query);
    Last edited by sunfighter; 04-14-2011 at 07:20 PM.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    And if sunfighter's guess isn't right, then show your *REAL* code. The whole thing. Not a fragment.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Apr 2011
    Posts
    95
    Thanks
    13
    Thanked 1 Time in 1 Post
    PHP Code:
    <?php require_once('Connections/Mysitedb.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      if (
    PHP_VERSION 6) {
        
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    mysql_select_db($database_Mysitedb$Mysitedb);
    $query_Recordset1 "SELECT * FROM products WHERE productid = '" $q "'";
    $Recordset1 mysql_query($query_Recordset1$Mysitedb) or die(mysql_error());
    $row_Recordset1 mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 mysql_num_rows($Recordset1);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <table>
      <tr>
        <td width="132">price</td>
        <td width="138"><?php echo $row_Recordset1['price']; ?></td>
      </tr>
      <tr>
        <td>name</td>
        <td><?php echo $row_Recordset1['productname']; ?></td>
      </tr>
      <tr>
        <td>man</td>
        <td><?php echo $row_Recordset1['manufacturer']; ?></td>
      </tr>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result
    ($Recordset1);
    ?>

  • #5
    New Coder
    Join Date
    Apr 2011
    Posts
    95
    Thanks
    13
    Thanked 1 Time in 1 Post
    oO ok i forgot to add
    PHP Code:
    $q=$_GET["q"]; 
    at the top, it seems start working now

  • #6
    New to the CF scene
    Join Date
    Apr 2011
    Location
    Georgia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question quotes

    Actually, when yo do the query, you don't actually have to do "SELECT * FROM table WHERE column='" . $request . "'". You can do "SELECT * FROM table WHERE column='$request'"..... I'm new here, but I know a lot of languages! Ask me for help sometime!

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Quote Originally Posted by maniakk View Post
    I'm new here, but I know a lot of languages! Ask me for help sometime!
    Okay: Чего должны вы сделать если вы имеете слона в вашем карманн?

    Or if you meant computer languages, how do you exit early from an expression in Prolog?

    [Just kidding! Welcome. But those who post here don't ask *specific* people for help. They just post a question and anybody who can answers.]
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Quote Originally Posted by garevn View Post
    oO ok i forgot to add
    PHP Code:
    $q=$_GET["q"]; 
    at the top, it seems start working now
    LOL! It's always the really HUGE elephants that seem to vanish when you look for them.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    New Coder
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by garevn View Post
    oO ok i forgot to add
    PHP Code:
    $q=$_GET["q"]; 
    at the top, it seems start working now
    You should run $q through the mysql_real_escape_string function before using it in the select statement. Otherwise you leave yourself wide open to a SQL Injection attack.

  • #10
    New to the CF scene
    Join Date
    Apr 2011
    Location
    Georgia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What should you do if you have an elephant in your pocket?!?!?!?!? cpu languages. and i think either return or break.?...

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    LOL! Xorosho!

    No, Prolog is a weird language. No such thing as return or break. The answer is: You don't. But you don't need to, if you wrote the code right. <grin/>

    *******

    Postscript: I admit to using Babelfish to do that translation simply because I didn't want to hunt and peck the Cyrillic characters.

    If I'd written it myself I would have said Что должно делать если у вас слон в кармане?

    And Babelfish translates that as "What must make if in you elephant in the pocket?"

    Which tells me that Babelfish doesn't understand idiomatic language. My Russian is rusty, but I think "у вас" clearly means "you have" in normal speech.

    Ahhh...interesting. If you reverse the condition (which probably is more common speech) to "если у вас слон в кармане, Что делать ?" then Babelfish comes up with "if you have elephant in the pocket, what to make?" which I'd accept as close enough. Fun stuff!
    Last edited by Old Pedant; 04-15-2011 at 01:10 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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