hi;
I'm new to PHP and AJAX MySQL codes. I found a simple code for
PHP and AJAX MySQL Database communication on :
http://www.w3schools.c om/php/php_ajax_databa se.asp
I downloaded the code and uploaded to my server but it does not work . I script does not display the data from the database.
Can anyone look at this and help me out.
thanks
6 9758 ak1dnar 1,584
Recognized Expert Top Contributor
If you create the user table in ajax_demo database definitely it will work.
Why don't you post the Coding here, that you used in your server.
Me too... I keep getting error message from the HTML page
Line : 2
Char : 21
Error : Expected ';'
Line : 7
Char : 1
Error : Object Expected
=============== =============== =============== =
[PHP]<html>
<head>
<script src="selectuser .js"></script>
</head>
<body><form>
Select a User:
<select name="users" onchange="showU ser(this.value) ">
<option value="1">20000 01</option>
<option value="2">20000 02</option>
<option value="3">20000 03</option>
<option value="4">20000 04</option>
</select>
</form><p>
<div id="txtHint"><b >User info will be listed here.</b></div>
</p></body>
</html>[/PHP]
Im really no idea
Thanks
ak1dnar 1,584
Recognized Expert Top Contributor
Me too... I keep getting error message from the HTML page
Line : 2
Char : 21
Error : Expected ';'
Line : 7
Char : 1
Error : Object Expected
=============== =============== =============== =
<html>
<head>
<script src="selectuser .js"></script>
</head>
<body><form>
Select a User:
<select name="users" onchange="showU ser(this.value) ">
<option value="1">20000 01</option>
<option value="2">20000 02</option>
<option value="3">20000 03</option>
<option value="4">20000 04</option>
</select>
</form><p>
<div id="txtHint"><b >User info will be listed here.</b></div>
</p></body>
</html>
Im really no idea
Thanks
This Error is Coming from your selectuser.js file. You are posting only HTML part.
Try this and if not working post the js file. Note the " ; " by the end of function. - <select name="users" onchange="showUser(this.value);">
Here the JavaScript and PHP files. Im only did some changes on PHP file.
selectuser.js -
var xmlHttpfunction showUser(str)
-
{
-
xmlHttp=GetXmlHttpObject()
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request")
-
return
-
}
-
var url="getuser.php"
-
url=url+"?q="+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("txtHint").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("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
-
getuser.php -
<?php
-
-
include("Database/database.php");
-
-
global $conn;
-
-
$q=$_GET["q"];
-
-
$sql="SELECT * FROM student_recording WHERE Stu_ID = $q";
-
-
$result = $conn->query($sql);
-
-
echo "<table border='1'>
-
<tr>
-
<th>Firstname</th>
-
<th>Class Code</th>
-
<th>Race</th>
-
</tr>";
-
-
while($row = $result->fetch_assoc())
-
{
-
echo "<tr>";
-
echo "<td>" . $row['Stu_Name'] . "</td>";
-
echo "<td>" . $row['Class_Code'] . "</td>";
-
echo "<td>" . $row['Stu_Race'] . "</td>";
-
echo "</tr>";
-
}
-
echo "</table>";
-
-
?>
-
ak1dnar 1,584
Recognized Expert Top Contributor
Here the JavaScript and PHP files. Im only did some changes on PHP file.
I think both of you are using This Sample Application. jafarsalam,
If this is not your problem please post a comment on that. bluez,
Try this Coding.Note that you have merged xmlHttp variable and the ShowUSer function in your JS file.
And the ; Missing by end of xmlHttp Variable Declaration. -
var xmlHttp;
-
-
function showUser(str)
-
{
-
xmlHttp=GetXmlHttpObject()
-
if (xmlHttp==null)
-
{
-
alert ("Browser does not support HTTP Request")
-
return
-
}
-
var url="getuser.php"
-
url=url+"?q="+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("txtHint").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("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
}
-
return xmlHttp;
-
}
-
Thanks ajaxrand...
It's work now. Sorry for never check it properly :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chris Paul |
last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows.
I've set this up countless times on BSD (piece of cake) but I'm trying
to do this on Windows now so that my developer can work on her local
machine.
Everything looks pretty good. OpenLDAP/cygwin works great. PostgreSQL
works great. Apache runs. PHP runs.
But when I try to connect to my PostgreSQL server using PHPPgAdmin, I
|
by: Ivan Marsh |
last post by:
Hey Folks,
I'm having a heck of a time wrapping mind around AJAX.
Anyone know of a simple, straight-forward example for pulling a simple
query from mysql with PHP using AJAX?
As I understand it I need a PHP script that pulls the query and dumps the
data into XML format, that is called by triggering a javascript event that
reads that file with XMLhttprequest.
|
by: d3vkit |
last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was working fine until today. I am trying to implement some ajax with the javascript framework mootools (although I don't see how this is causing the problem it started happening right around this time sooo...)
I am sending info from my login form to the...
|
by: minnie |
last post by:
An AJAX Simple Example for PHP
Article from http://www.joyistar.com
Introduction:
AJAX WebShop 3 Beta2 supports PHP programming by integrating PHP5
development environment. Here we will give an simple example to show
you how to develop web applications by PHP in AJAX WebShop.
1, Notice
We will use Access database in this example. Of course, you can use
others you like. Database name: demo.mdb; Table name: product; Fields:
|
by: wradyn |
last post by:
As an example, my MySQL database has 3 tables: main-area, sub-area, and items. Using PHP I populate my first select-list as follows:
<?php
// Create list containing the Main Areas
echo "Select an Area:";
echo "<select name='area_select' id='area_select' onChange='getArea();'>\n";
while ($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<option value=\'$area_id\'>$name\n";
| |
by: John Doe |
last post by:
Here's my issue: I have an instant messenger type feature for my site, its
basically an ajax IM feature. I run with a mysql backend on the site, i have
a div on my main page that runs a javascript timer to load the php page via
ajax every 15 seconds which checks the "pinguser" table to see if the user
has any chat requests, then echoes them to a div on the page. what i REALLY
want to do is have the ajax page see if there is a ping for the...
|
by: art |
last post by:
Hi,
We have some scripts here where we use some AJAX to populate some of
the page.
Basically the AJAX routine calls a PHP script. That PHP script uses a
bunch of ECHO statements to create the page. Then, we use the
innerHTML to populate the section on the page.
The problem is, we have a small javascript routine in the middile of
|
by: wheatcom |
last post by:
This problem relates to modifying the code in the PHP and AJAX MySql Database Example in http://bytes.com/forum/thread608395.html.
In that example, the value selected in the HTML form is from a drop down menu:
<body><form>
Select a User:
<select name="users" onchange="showUser(this.value)">
<option value="1">2000001</option>
<option value="2">2000002</option>
<option value="3">2000003</option>
|
by: ArizonaJohn |
last post by:
Hello,
Below I have some Ajax and the page it points to. This code works great if $_SESSION has no spaces in it (for example, if it is "elpaso"). However, if $_SESSION has a space in it (for example, "el paso"), then the Ajax fails.
What can I do to make this Ajax work when $_SESSION has a space in it?
Thanks.
Ajax:
<?php
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |