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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.