Creating customer view shopping website
hai
i hv tried in AJAX.
i hv some error..
can you help me ?
i hv attached two files "order1.html" & "answer.php" order1.html (1.99K)
Number of downloads: 1 answer.php (1.01K)
Number of downloads: 0
in "order.html" two radio buttons are there, if single radio button is clicked and corresponding value from database should be fetched and be displayed.
in answer.php file corresponding values of capacity is fetched and displayed..
to my view i hv not found any wrong in code.
but nothing is displayed..
if you found any error in my code..
please convey it to me and help me
with regards
sivasankari
ORDER.HTML
<html>
<head>
<script language="javascript" type="text/javascript">
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.myForm.time.value = ajaxRequest.responseText;
}
}
// if "single" radio button is clicked
var sdoor = document.getElementById('single').value;
// if "double" radio button is clicked
var ddoor = document.getElementById('double').value;
if(sdoor == "single") {
// if value of radio button is single
var queryString = "?door=" + sdoor;
ajaxRequest.open("GET", "answer.php" + queryString, true);
ajaxRequest.send(null); }
if(ddoor == "double") {
// if value of radio button is double
var queryString = "?door=" + ddoor;
ajaxRequest.open("GET", "answer.php" + queryString, true);
ajaxRequest.send(null); }
}
</script>
</head>
<body>
<!-- form having two radio buttons
if a radio button "single" is clicked means
capacity of each door's field "single" is fetched from database and echoed -->
<form name='myForm'>
<p>(i) Door option : ***************
<input type='radio' name='door' value='single' id="single" onclick='ajaxFunction()'>Single</input>
<input type='radio' name='door' value='double' id="double" >Double</input> </p>
</form>
</body>
</html>
answer.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "test";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$door = $_GET['door'];
// Escape User Input to help prevent SQL Injection
//$door = mysql_real_escape_string($door);
//build query
// Assume "fridge" is a table contains two fields door and capactiy
// values of two table seen like below
// door, capacity
//single, 190
//double,210
//single, 200
// if single radio button is clicked, 190 and 200 should be displayed
$query = "SELECT * FROM fridge";
//Execute query
$result = mysql_query($query) or die(mysql_error());
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
if($row['door'] == $door)
{
$display_string .= "$row[capacity]";
}
}
echo "Query: " . $query . "<br />";
echo $display_string;
?>
hai
i hv tried in AJAX.
i hv some error..
can you help me ?
i hv attached two files "order1.html" & "answer.php" order1.html (1.99K)
Number of downloads: 1 answer.php (1.01K)
Number of downloads: 0
in "order.html" two radio buttons are there, if single radio button is clicked and corresponding value from database should be fetched and be displayed.
in answer.php file corresponding values of capacity is fetched and displayed..
to my view i hv not found any wrong in code.
but nothing is displayed..
if you found any error in my code..
please convey it to me and help me
with regards
sivasankari
ORDER.HTML
<html>
<head>
<script language="javascript" type="text/javascript">
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.myForm.time.value = ajaxRequest.responseText;
}
}
// if "single" radio button is clicked
var sdoor = document.getElementById('single').value;
// if "double" radio button is clicked
var ddoor = document.getElementById('double').value;
if(sdoor == "single") {
// if value of radio button is single
var queryString = "?door=" + sdoor;
ajaxRequest.open("GET", "answer.php" + queryString, true);
ajaxRequest.send(null); }
if(ddoor == "double") {
// if value of radio button is double
var queryString = "?door=" + ddoor;
ajaxRequest.open("GET", "answer.php" + queryString, true);
ajaxRequest.send(null); }
}
</script>
</head>
<body>
<!-- form having two radio buttons
if a radio button "single" is clicked means
capacity of each door's field "single" is fetched from database and echoed -->
<form name='myForm'>
<p>(i) Door option : ***************
<input type='radio' name='door' value='single' id="single" onclick='ajaxFunction()'>Single</input>
<input type='radio' name='door' value='double' id="double" >Double</input> </p>
</form>
</body>
</html>
answer.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "test";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$door = $_GET['door'];
// Escape User Input to help prevent SQL Injection
//$door = mysql_real_escape_string($door);
//build query
// Assume "fridge" is a table contains two fields door and capactiy
// values of two table seen like below
// door, capacity
//single, 190
//double,210
//single, 200
// if single radio button is clicked, 190 and 200 should be displayed
$query = "SELECT * FROM fridge";
//Execute query
$result = mysql_query($query) or die(mysql_error());
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
if($row['door'] == $door)
{
$display_string .= "$row[capacity]";
}
}
echo "Query: " . $query . "<br />";
echo $display_string;
?>