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

Thread: Query failed ?

  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Query failed ?

    Hello, guys

    With this code:
    PHP Code:
    $query "SELECT * FROM loyalty WHERE PERSON_NAME = $guest_id";
    $result mysql_query($query) or die('Query failed: ' mysql_error());
        while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) { 
    $person_name $row ["PERSON_NAME"]; 
    I have error:
    Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PERSON NAME VALUES ' at line 1
    Last edited by krasi_e_d; 02-20-2012 at 12:25 PM.

  • #2
    New Coder
    Join Date
    Feb 2012
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    You need to enclose $guest_id in a single quotation mark.
    Try this and if it does not help let me know.
    Code:
    $query = "SELECT * FROM loyalty WHERE PERSON_NAME = '$guest_id'";
    Thanks
    Mahdi Eftekhari

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    40
    Thanks
    0
    Thanked 9 Times in 9 Posts
    If Mahdi's solution doesn't solve it make sure your column name in the database and in your query match (PERSON_NAME, is it all caps in the db? I'm pretty sure table fields are case sensitive)

  • #4
    New Coder
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cercos View Post
    If Mahdi's solution doesn't solve it make sure your column name in the database and in your query match (PERSON_NAME, is it all caps in the db? I'm pretty sure table fields are case sensitive)
    Your and Mahdi's doesn't solve it.

  • #5
    New Coder
    Join Date
    Feb 2012
    Posts
    40
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Post a copy of your database structure

  • #6
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,420
    Thanks
    68
    Thanked 102 Times in 101 Posts
    Try this

    PHP Code:
    $query "SELECT * FROM loyalty WHERE PERSON_NAME='$guest_id'";
    $result mysql_query($query) or die(mysql_error());
        while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) { 
    $person_name $row["PERSON_NAME"]; 
    Been a sign maker for 7 years. My business:
    American Made Signs

  • #7
    New Coder
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cercos View Post
    Post a copy of your database structure
    Code:
    `id` ,
    `vaucher_num` ,
    `line_name` ,
    `titular_name` ,
    `price` ,
    `doc_num` ,
    `arrival` ,
    `departure` ,
    `adult_count` ,
    `child_count` ,
    `doc_date` ,
    `qty` ,
    `id_guest` ,
    `id_person` ,
    `PERSON NAME` ,
    `id_person_titular` 
    );

  • #8
    New Coder
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by myfayt View Post
    Try this

    PHP Code:
    $query "SELECT * FROM loyalty WHERE PERSON_NAME='$guest_id'";
    $result mysql_query($query) or die(mysql_error());
        while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) { 
    $person_name $row["PERSON_NAME"]; 
    Doesn't solve it.

  • #9
    New Coder
    Join Date
    Feb 2012
    Posts
    40
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Change the PERSON NAME in your database to PERSON_NAME with an underscore

  • #10
    New Coder
    Join Date
    Feb 2012
    Posts
    19
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cercos View Post
    Change the PERSON NAME in your database to PERSON_NAME with an underscore
    Doesn't solve it.

    This is my codes:

    uploadtest.php

    PHP Code:
    <?php
    set_time_limit
    (9600);
    error_reporting(0);
    ?>
    <form enctype="multipart/form-data" action="generatortest.php" method="POST" class="style2">
    <tr>
            <td class="style1">Document ID: </td>
            <td class="style1"> <font size="2"> <input name="guest_id" type="text" ></font></td>
        
    <table style="width: 100%">
        <td class="style1">Database:</td>
            <td class="style1">
                    <select name="database">
                    <option value="1">Bolero</option>
                    </select>
            </td>
        </tr>
        </tr>    
            <tr>
            <td class="style1">&nbsp;</td>
            <td class="style1">
    <font size="2">
    <input type="submit" value="Generate" /></font></td></form>
        </tr>
        <tr>
            <td class="style2">&nbsp;</td>
            <td class="style1"></td>
        </tr>
        </table>
    generatortest.php
    PHP Code:
    <?php
    set_time_limit
    (9600);
    //error_reporting(0);

    // Includes
    //include("include/numbertotext.php");
    //include("include/html_to_doc.inc.php");
    include("listtest.php");
    include(
    "config/db.php");
    //Variables
    $guest_id $_REQUEST['guest_id'];
    $database $_REQUEST['database'];

    if (
    $database == 1) { $ibase_host='******.FDB';  }

    //Functions
    insert_db($guest_id,$ibase_host);

    //Get Document Main Values
    $query "SELECT * FROM loyalty WHERE PERSON_NAME='$guest_id'";
    $result mysql_query($query) or die(mysql_error());
        while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) { 
    $person_name $row["PERSON_NAME"]; 
        }
        
        
    ?>
    <!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-Language" content="en-us" />
    <meta http-equiv="Content-Type" content="text; charset=utf-8" />
    <title>Loyalty <?php echo $guest_id;?></title>
    <style type="text/css">
    .style1 {
        text-align: center;
        font-family: Verdana;
        font-size: 8pt;
    }
    .style2 {
        font-family: Verdana;
        font-size: 8pt;
        border-width: 0;
        background-color: #E6E6E6;
    }
    .style3 {
        text-align: center;
        font-family: Verdana;
        font-size: 8pt;
        background-color: #E6E6E6;
    }
    .style5 {
        font-family: Verdana;
        font-size: 8pt;
    }
    .style6 {
        text-align: left;
        font-family: Verdana;
        font-size: 8pt;
    }
    .style7 {
        border-width: 0;
        text-align: center;
        font-family: Verdana;
        font-size: 8pt;
        background-color: #E6E6E6;
    }
    .style8 {
        text-align: left;
        font-family: Verdana;
        font-size: 8pt;
        background-color: #E6E6E6;
    }
    .style9 {
        text-align: right;
        font-family: Verdana;
        font-size: 8pt;
    }
    .style10 {
        text-align: right;
        font-family: Verdana;
        font-size: 8pt;
        background-color: #E6E6E6;
    }
    .style11 {
        font-family: Verdana;
        font-size: 8pt;
        background-color: #E6E6E6;
    }
    </style>
    </head>
    <body>
    <table style="width: 100%">
    <td colspan="2" class="style1">Customer<?php echo $person_name?></td>
    <table>
    </body>

    </html>
        ?>
    listtest.php
    PHP Code:
    <?php
    function insert_db($id_person_titular,$ibase_host) {
    include(
    "config/db.php");
    //mysql_query("DELETE FROM loyalty WHERE id>=0");
    $dbh ibase_connect($ibase_host$ibase_user$ibase_pass);


        
    $stmt1 "SELECT * FROM PERSON_DATA WHERE ID_PERSON_DATA = '$id_person_titular'";
                        
    $sth1 ibase_query($dbh$stmt1);
                        while (
    $row1 ibase_fetch_object($sth1)) {
                        
    $person_name =  $row1->PERSON_NAME;
                        }
                        
                        
        {                
        
    $query "INSERT INTO loyalty PERSON_NAME VALUES '$person_name'";
        
    $result mysql_query($query) or die('Query failed: ' mysql_error());
        }
        }
        
    ?>

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by krasi_e_d View Post
    Doesn't solve it.
    Instead of keep saying that, how about you provide the latest error message from mysql_error() with each reply?

    Also, try wrapping PERSON_NAME with back ticks like this `PERSON_NAME` in your SQL query.

    Backticks can normally be found on the key underneath the escape key (on UK keyboards) and are NOT the same as a comma '..
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    krasi_e_d (02-20-2012)


  •  

    Posting Permissions

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