...

View Full Version : Resolved Query failed ?



krasi_e_d
02-19-2012, 02:57 PM
Hello, guys

With this 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($result, MYSQL_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

Mahdi Eftekhari
02-19-2012, 03:25 PM
You need to enclose $guest_id in a single quotation mark.
Try this and if it does not help let me know.


$query = "SELECT * FROM loyalty WHERE PERSON_NAME = '$guest_id'";

Thanks
Mahdi Eftekhari

cercos
02-19-2012, 07:32 PM
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)

krasi_e_d
02-19-2012, 08:22 PM
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.

cercos
02-19-2012, 09:24 PM
Post a copy of your database structure

myfayt
02-19-2012, 10:42 PM
Try this


$query = "SELECT * FROM loyalty WHERE PERSON_NAME='$guest_id'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$person_name = $row["PERSON_NAME"];

krasi_e_d
02-20-2012, 06:44 AM
Post a copy of your database structure


`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`
);

krasi_e_d
02-20-2012, 07:15 AM
Try this


$query = "SELECT * FROM loyalty WHERE PERSON_NAME='$guest_id'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$person_name = $row["PERSON_NAME"];

Doesn't solve it.

cercos
02-20-2012, 07:23 AM
Change the PERSON NAME in your database to PERSON_NAME with an underscore

krasi_e_d
02-20-2012, 08:50 AM
Change the PERSON NAME in your database to PERSON_NAME with an underscore

Doesn't solve it.

This is my codes:

uploadtest.php


<?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
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($result, MYSQL_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
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());
}
}
?>

tangoforce
02-20-2012, 11:02 AM
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 '..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum