Jump to content

Help with php/ajax


Darkmatter5

Recommended Posts

Here are the three snippets of code that I'm using.  I have a text box with a button that launches a function in the javascript and displays a result at a div in the search.php file.  The problem is when I click the button the result I get is "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 '[object HTMLFormElement]' at line 3".  Can someone please help me diagnose this error?

 

search.php

<form><div align="center" class="style7"><span class="style6">
    <label>Search by LastName:
    <input name="LastName" type="text" id="LastName" /></label></span>
    <input name="searchclients" type="button" id="searchclients" onclick="showClientTXT(this.form)" value="Search" />
    </div></form>

 

select_TXTsearchclients.js

// JavaScript Document
var xmlHttp

function showClientTXT(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
	alert ("Browser does not support HTTP Request")
	return
}
var url="http://byrndb01/byrndb/library/get_TXTsearchclients.php"
url=url+"?r1="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
	document.getElementById("results").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}
catch (e)
{
	//Internet Explorer
	try
	{
		xmlHttp=new ActiveXObject("Msxml12.XMLHTTP");
	}
	catch (e)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}
return xmlHttp;
}

 

get_TXTsearchclients.php

<?php
$lastname=$_GET["r1"];

include 'dbconfig.php';
include 'opendb.php';

$query="SELECT ClientID, FirstName, LastName, CompanyName, HomePhone, WorkPhone
	FROM byrnjobdb.clients
	WHERE LastName=$lastname";
$result=mysql_query($query) OR die (mysql_error());

echo "<table border='1'>
  <tr>
  <th>ClientID</th>
  <th>First Name</th>
  <th>Last Name</th>
  <th>Company Name</th>
  <th>Home Phone</th>
  <th>Work Phone</th>
  </tr>";

while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td><a href='addclient.php' target='mainFrame'>" . $row['ClientID'] . "</a></td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['CompanyName'] . "</td>";
echo "<td>" . $row['HomePhone'] . "</td>";
echo "<td>" . $row['WorkPhone'] . "</td>";
echo "</tr>";
}
echo "</table>";

include 'closedb.php';
?>

Link to comment
https://forums.phpfreaks.com/topic/103489-help-with-phpajax/
Share on other sites

1. When you say showClientTXT(this.form) your passing the form object. Thats what [object HTMLFormElement] is.

 

You need to use this.form['LastName'].value to send the value in your LastName textbox.

 

2.

"SELECT ClientID, FirstName, LastName, CompanyName, HomePhone, WorkPhone
	FROM byrnjobdb.clients
	WHERE LastName=$lastname";

 

If you don't put quotes around string values ($lastname), MySQL thinks its something else.

 

"SELECT ClientID, FirstName, LastName, CompanyName, HomePhone, WorkPhone
	FROM byrnjobdb.clients
	WHERE LastName='$lastname'";

Link to comment
https://forums.phpfreaks.com/topic/103489-help-with-phpajax/#findComment-530063
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.