Ajax php mysql - fetch multiple values - php

I want to fetch data from table 'driver' by using sql where (name = '? ') condition
and fill the result into three text boxes .
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script language="JavaScript" type="text/javascript">
function ajax_post(){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "my_parse_file.php";
var fn = document.getElementById("driver_name").value;
// var ln = document.getElementById("last_name").value;
var vars = "driver="+fn;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
document.getElementById("contact_no").value = return_data;
$("#wait").css("display","none");
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
$("#wait").css("display","block");
}
</script>
</head>
<body>
<form action="my_parse_file.php" method="post" id="form2">
<fieldset > <legend>Dispatch</legend>
<table width="50%" align="center">
<tr valign="baseline">
<td align="left">Dispatch_date:</td>
<td><input type="date" name="dispatch_date" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left">Driver_name:</td>
<td><select name="driver_name" id="driver_name" onchange="javascript:ajax_post();">
<?php
do {
?>
<option value="<?php echo $row_drivers['Driver_Name']?>"><?php echo $row_drivers['Driver_Name']?></option>
<?php
} while ($row_drivers = mysql_fetch_assoc($drivers));
$rows = mysql_num_rows($drivers);
if($rows > 0) {
mysql_data_seek($drivers, 0);
$row_drivers = mysql_fetch_assoc($drivers);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td align="left">Driver_id:</td>
<td><input type="text" name="driver_id" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left">Contact No.</td>
<td><input type="text" name="contact_no" id="contact_no" /></td>
</tr>
<tr valign="baseline">
<td align="left">Truck_id:</td>
<td><input type="text" name="truck_id" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="left">Nums. of skids</td>
<td><input type="number" min="0" max="30" id="skids" required="required" />
</td>
</tr>
<tr valign="baseline">
<td align="left"> </td>
<td><input type="submit" value="Insert record" />
<?php ?></td>
</tr>
</table>
</fieldset>
<input type="hidden" name="MM_insert" value="form2" />
</form>
I am trying to fetch data from other php page
<?php echo ' Driver Name' ?>
<?php echo ' Driver ID' ?>
<?php echo ' Contact no' ?>
so please help I am just new to Ajax and php

Encode the output of the PHP file you're fetching with AJAX as JSON using json_encode and then parse hr.responseText as JSON and access the data accordingly.
Have a look here: http://www.json.org/js.html

Related

How to move in a mysql table with ajax and php to the next and previous rows?

After the bad communication and unclear questions from yesterday from my side, I prepared something. I was the first time in a forum like this. It is tough, but good! I realized how professional the people in this forum. I know not one forum that comes near to your quality of informations!
I am not a sweet talker, this is fact! Here is the problem:
I connect to a mysql table but I can not go to the next and next and next row, the same for the previous records.
I still dont understand it deeply. What is wrong on this code? I am really very curious to know it.
When I click on previous come "undefined objects."
When I skip next then comes only one record, and then it freeze. I guess that I am on the end of the table.
I was reading so many posts here, at least 50, but I did not get it. I just did not understand it.
nice greetings from Bangkok
+++
I dont use jquery commands. I use just json parse to fetch the data, but I get not a lot ;)
It is very basic. All what I want to do is get the previous and next rows. Always only one row.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function jsRecordNext()
{
// ... the AJAX request is successful
var updatePage = function( response ) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function( req, status, err ) {
alert("no luck");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'nextarticle.php',
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//previous row
<?php include "accesscontrol.php" ;?>
<?php
$result = mysql_query("SELECT * FROM articles WHERE id<$current_id ORDER BY id DESC LIMIT 1");
$current_id = mysql_insert_id();
$result = mysql_fetch_row($result);
echo json_encode($result);
?>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//next row
<?php include "accesscontrol+.php" ;?> // connection
<?php
$result = mysql_query("SELECT * FROM articles WHERE id>$current_id ORDER BY id ASC LIMIT 1");
$current_id = mysql_insert_id();
$result = mysql_fetch_row($resulat);
echo json_encode($result);
?>
++++++++++++++++++++++++++++++++
this is index.php
<!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" dir="ltr" lang="en-US">
<META HTTP-Equiv="FileTransfer" Content="TransferEvent:url('Javascript:alert('%s')'); Transfer">
<head>
<meta charset="UTF-8" />
<title>SoB - Administration</title>
<link rel="stylesheet" href="../wp-content/themes/Kuraya-Theme/style.css" tppabs="http://www.spiritofbushido.com/wp-content/themes/Kuraya-Theme/style.css">
<link rel="pingback" href="http://www.spiritofbushido.com/xmlrpc.php">
<script type="text/javascript" src="../wp-content/themes/Kuraya-Theme/js/scroll.js" tppabs="www.spiritofbushido.com/wp-content/themes/Kuraya-Theme/js/scroll.js"></script>
<script type="text/javascript" src="../includes/jquery.js"></script>
<script type="text/javascript" src="userinfo.0.0.1.min.js"></script>
<link rel="alternate" type="application/rss+xml" title="Kuraya » Feed" href="http://www.scoobeedo.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="Kuraya » Comments Feed" href="http://www.scoobeedo.com/comments/feed/" />
<link rel="alternate" type="application/rss+xml" title="Kuraya » Join Our E-mail List Comments Feed" href="http://www.scoobeedo.com/email-signup/feed/" />
<link rel='stylesheet' id='shadowbox-css-css' href="../wp-content/uploads/shadowbox-js/src/shadowbox.css-ver=3.0.3.css" tppabs="http://www.scoobeedo.com/wp-content/uploads/shadowbox-js/src/shadowbox.css?ver=3.0.3" type='text/css' media='screen' />
<link rel='stylesheet' id='shadowbox-extras-css' href="../wp-content/plugins/shadowbox-js/css/extras.css-ver=3.0.3.10.css" tppabs="http://www.scoobeedo.com/wp-content/plugins/shadowbox-js/css/extras.css?ver=3.0.3.10" type='text/css' media='screen' />
<link rel='stylesheet' id='contact-form-7-css' href="../wp-content/plugins/contact-form-7/styles.css-ver=3.1.2.css" tppabs="http://www.scoobeedo.com/wp-content/plugins/contact-form-7/styles.css?ver=3.1.2" type='text/css' media='all' />
<script type='text/javascript' src="../../ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js-ver=3.3.2.js" tppabs="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=3.3.2"></script>
<script type='text/javascript' src="../wp-includes/js/comment-reply.js-ver=20090102.js" tppabs="http://www.scoobeedo.com/wp-includes/js/comment-reply.js?ver=20090102"></script>
<link rel='prev' title='東方古玩 蔵屋' href='http://www.scoobeedo.com/%e4%b8%ad%e6%96%87%e7%89%88/' />
<link rel='next' title='Sale 20% – 40% Off Entire Inventory Before Our Newshipment Arrived. Sales End April 30th.' href='http://www.scoobeedo.com/12131-2/' />
<link rel='canonical' href='http://www.scoobeedo.com/email-signup/' />
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<script id="source" language="javascript" type="text/javascript">
<!--
var js_string;
document.getElementById("recordWrite").disabled = true;
function jsRecordPrevious()
{
// ... the AJAX request is successful
var updatePage = function( response ) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function( req, status, err ) {
$( '#recordnumber').html( '-' );
alert("f p");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'previousarticle.php',
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
function jsRecordCurrent()
{
// ... the AJAX request is successful
var updatePage = function( response ) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function( req, status, err ) {
alert("f c");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'currentarticle.php',
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
function jsRecordNext()
{
// ... the AJAX request is successful
var updatePage = function( response ) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function( req, status, err ) {
alert("f n");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'nextarticle.php',
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
function jsShowArticle()
{
js_articles = JSON.parse(json_string);
document.form_articles.newItem.value=js_articles[1];
document.form_articles.newItemNo.value=js_articles[2];
document.form_articles.newMaterial.value=js_articles[3];
document.form_articles.newAge.value=js_articles[4];
document.form_articles.newItemSize.value=js_articles[5];
document.form_articles.newPrice.value=js_articles[6];
document.form_articles.newInfo.value=js_articles[7];
document.form_articles.newInfoRed.value=js_articles[8];
document.form_articles.newArrivalDate.value=js_articles[9];
if (js_articles[10]="Y")
{
document.form_articles.newArrivalDateShown.checked=true;
}
else
{
document.form_articles.newArrivalDateAhown.checked=false;
}
document.form_articles.newMainPicLink.value=js_articles[11];
document.form_articles.newItemCondition.value=js_articles[12];
}
function jsBlankArticle()
{
document.form_articles.newItem.value="";
document.form_articles.newItemNo.value="";
document.form_articles.newMaterial.value="";
document.form_articles.newAge.value="";
document.form_articles.newItemSize.value="";
document.form_articles.newPrice.value="";
document.form_articles.newInfo.value="";
document.form_articles.newInfoRed.value="";
document.form_articles.newArrivalDate.value="";
document.form_articles.newArrivalDateShown.checked=false;
document.form_articles.newMainPicLink.value="";
document.form_articles.newItemCondition.value="";
}
function jsNewArticle()
{
jsBlankArticle();
document.getElementById('formheadline').innerHTML='Article Database - Insert New Item';
document.getElementById('newItem').focus();
document.getElementById("recordWrite").disabled = false;
}
function jsWriteArticle()
{
document.getElementById('formheadline').innerHTML='Article Database - I save the new item';
document.getElementById("recordWrite").disabled = true;
}
function jsResetForm()
{
jsBlankArticle();
document.getElementById('formheadline').innerHTML='Article Database';
document.getElementById("recordWrite").disabled = true;
jsRecordCurrent()
}
jsResetForm();
// -->
</SCRIPT>
</head>
<body class="page page-id-11505 page-template-default" onload="jsRecordCurrent()">
<div id="page-wrap">s
<?php
include('../includes/header.html');
?>
<div id="container-main">
<div id="main-content">
<div class="post" id="post-11505">
<h2 class="title-page">SoB - Administration</h2>
<title>SoB - Administration</title>
<div id="recordnumber"></div>
<div class="entry">
<form method="post" action="<?=$_SERVER['PHP_SELF']?>" name="form_articles">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td align="right">
</td>
<td align="left">
<span id="formheadline"><h2>Article Database</h2></span>
</td>
</tr>
<tr>
<td align="right">
</td>
<td align="left">
<span style="padding-right:20px"><font color="orangered" size="+1"><tt><b>*</b></tt></font>indicates a required field</span>
</td>
</tr>
<br>
<tr>
<td align="right">
<span style="padding-right:20px">Item</span>
</td>
<td>
<input id="newItem" name="newItem" type="text" maxlength="100" size="25"/>
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Item No.</span>
</td>
<td>
<input name="newItemNo" type="text" maxlength="100" size="25" />
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Arrival Date</span>
</td>
<td>
<input name="newArrivalDate" type="date" />
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Show in New Arrivals</span>
</td>
<td>
<input name="newArrivalDateShown" type="checkbox" />
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Material</span>
</td>
<td>
<input name="newMaterial" type="text" maxlength="100" size="25" />
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Condition of item</span>
</td>
<td>
<input id="newItemCondition" name="newItemCondition" type="text" maxlength="100" size="25" />
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Age</span>
</td>
<td>
<input name="newAge" type="text" maxlength="100" size="25" />
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Item Size</span>
</td>
<td>
<input name="newItemSize" type="text" maxlength="100" size="25" />
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Price</span>
</td>
<td>
<input name="newPrice" type="text" maxlength="100" size="25" />
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Info Red</span>
</td>
<td>
<input name="newInfoRed" type="text" maxlength="100" size="25" />
</td>
</tr>
<tr valign="top">
<td align="right">
<span style="padding-right:20px">Infos</span>
</td>
<td>
<textarea wrap="soft" name="newInfo" rows="5" cols="30"></textarea>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">PicLink</span>
</td>
<td>
<input id="newMainPicLink" name="newMainPicLink" type="text" maxlength="100" size="50" />
</td>
</tr>
<br><br>
<tr>
<td align="right" colspan="2">
<hr noshade="noshade" />
<input type="button" name="recordPrevious" value=" < " onclick="jsRecordPrevious()"/>
<input type="button" name="recordNext" value=" > " onclick="jsRecordNext()"/>
<input type="button" name="recordNew" value=" New " onclick="jsBlankArticle()"/>
<input type="button" name="recordEdit" value=" Edit " onclick="jsShowArticle()"/>
<span style="padding-right:20px"></span>
<input type="reset" value="Reset Form" />
<input id="recordWrite" type="button" name="recordWrite" value=" Write " onclick="jsWriteArticle()"/>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php
include('../includes/sidemenu.html');
?>
<br class="clearfloat" />
</div> <!-- End of main container -->
</div><!-- END Page Wrap -->
<?php
include('../includes/footer.html');
?>
</body>
</html>
Hello you lack lots of Logocal and Programming skills, please improve it.
Files() are as below ->
Your index.php
<!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" dir="ltr" lang="en-US">
<META HTTP-Equiv="FileTransfer" Content="TransferEvent:url('Javascript:alert('%s')'); Transfer">
<head>
<meta charset="UTF-8"/>
<title>SoB - Administration</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<style type="text/css">.recentcomments a {
display: inline !important;
padding: 0 !important;
margin: 0 !important;
}</style>
<script id="source" language="javascript" type="text/javascript">
var js_string;
document.getElementById("recordWrite").disabled = true;
function jsRecordPrevious() {
// ... the AJAX request is successful
var updatePage = function (response) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function (req, status, err) {
$('#recordnumber').html('-');
alert("f p");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'previousarticle.php',
data : { currentRecord: $("[name='recordPrevious']").attr("id")},
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
function jsRecordCurrent() {
// ... the AJAX request is successful
var updatePage = function (response) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function (req, status, err) {
alert("f c");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'currentarticle.php',
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
function jsRecordNext() {
// ... the AJAX request is successful
var updatePage = function (response) {
json_string = JSON.stringify(response);
jsBlankArticle();
jsShowArticle();
};
// ... the AJAX request fail
var printError = function (req, status, err) {
alert("f n");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'nextarticle.php',
data : { currentRecord: $("[name='recordNext']").attr("id")},
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
function jsShowArticle() {
js_articles = JSON.parse(json_string);
//Dude , I added it (Pratik)->
$('[name="recordNext"]').attr("id",js_articles[0]);
$('[name="recordPrevious"]').attr("id",js_articles[0]);
document.form_articles.newItem.value = js_articles[1];
document.form_articles.newItemNo.value = js_articles[2];
document.form_articles.newMaterial.value = js_articles[3];
document.form_articles.newAge.value = js_articles[4];
document.form_articles.newItemSize.value = js_articles[5];
document.form_articles.newPrice.value = js_articles[6];
document.form_articles.newInfo.value = js_articles[7];
document.form_articles.newInfoRed.value = js_articles[8];
document.form_articles.newArrivalDate.value = js_articles[9];
if (js_articles[10] = "Y") {
document.form_articles.newArrivalDateShown.checked = true;
}
else {
document.form_articles.newArrivalDateAhown.checked = false;
}
document.form_articles.newMainPicLink.value = js_articles[11];
document.form_articles.newItemCondition.value = js_articles[12];
}
function jsBlankArticle() {
document.form_articles.newItem.value = "";
document.form_articles.newItemNo.value = "";
document.form_articles.newMaterial.value = "";
document.form_articles.newAge.value = "";
document.form_articles.newItemSize.value = "";
document.form_articles.newPrice.value = "";
document.form_articles.newInfo.value = "";
document.form_articles.newInfoRed.value = "";
document.form_articles.newArrivalDate.value = "";
document.form_articles.newArrivalDateShown.checked = false;
document.form_articles.newMainPicLink.value = "";
document.form_articles.newItemCondition.value = "";
}
function jsNewArticle() {
jsBlankArticle();
document.getElementById('formheadline').innerHTML = 'Article Database - Insert New Item';
document.getElementById('newItem').focus();
document.getElementById("recordWrite").disabled = false;
}
function jsWriteArticle() {
document.getElementById('formheadline').innerHTML = 'Article Database - I save the new item';
document.getElementById("recordWrite").disabled = true;
}
function jsResetForm() {
jsBlankArticle();
document.getElementById('formheadline').innerHTML = 'Article Database';
document.getElementById("recordWrite").disabled = true;
jsRecordCurrent()
}
jsResetForm();
</script>
</head>
<body class="page page-id-11505 page-template-default" onload="jsRecordCurrent()">
<div id="page-wrap">
<div id="container-main">
<div id="main-content">
<div class="post" id="post-11505">
<h2 class="title-page">SoB - Administration</h2>
<title>SoB - Administration</title>
<div id="recordnumber"></div>
<div class="entry">
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>" name="form_articles">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td align="right">
</td>
<td align="left">
<span id="formheadline"><h2>Article Database</h2></span>
</td>
</tr>
<tr>
<td align="right">
</td>
<td align="left">
<span style="padding-right:20px"><font color="orangered" size="+1"><tt><b>*</b></tt></font>indicates a required field</span>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Item</span>
</td>
<td>
<input id="newItem" name="newItem" type="text" maxlength="100" size="25"/>
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Item No.</span>
</td>
<td>
<input name="newItemNo" type="text" maxlength="100" size="25"/>
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Arrival Date</span>
</td>
<td>
<input name="newArrivalDate" type="date"/>
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Show in New Arrivals</span>
</td>
<td>
<input name="newArrivalDateShown" type="checkbox"/>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Material</span>
</td>
<td>
<input name="newMaterial" type="text" maxlength="100" size="25"/>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Condition of item</span>
</td>
<td>
<input id="newItemCondition" name="newItemCondition" type="text" maxlength="100"
size="25"/>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Age</span>
</td>
<td>
<input name="newAge" type="text" maxlength="100" size="25"/>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Item Size</span>
</td>
<td>
<input name="newItemSize" type="text" maxlength="100" size="25"/>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Price</span>
</td>
<td>
<input name="newPrice" type="text" maxlength="100" size="25"/>
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Info Red</span>
</td>
<td>
<input name="newInfoRed" type="text" maxlength="100" size="25"/>
</td>
</tr>
<tr valign="top">
<td align="right">
<span style="padding-right:20px">Infos</span>
</td>
<td>
<textarea wrap="soft" name="newInfo" rows="5" cols="30"></textarea>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">PicLink</span>
</td>
<td>
<input id="newMainPicLink" name="newMainPicLink" type="text" maxlength="100"
size="50"/>
</td>
</tr>
<br><br>
<tr>
<td align="right" colspan="2">
<hr noshade="noshade"/>
<input type="button" name="recordPrevious" value=" < "
onclick="jsRecordPrevious()"/>
<input type="button" name="recordNext" value=" > " onclick="jsRecordNext()"/>
<input type="button" name="recordNew" value=" New " onclick="jsBlankArticle()"/>
<input type="button" name="recordEdit" value=" Edit " onclick="jsShowArticle()"/>
<span style="padding-right:20px"></span>
<input type="reset" value="Reset Form"/>
<input id="recordWrite" type="button" name="recordWrite" value=" Write "
onclick="jsWriteArticle()"/>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<br class="clearfloat"/>
</div>
<!-- End of main container -->
</div>
<!-- END Page Wrap -->
</body>
</html>
This is currentarticle.php
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('testDb', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$result = mysql_query("SELECT * FROM articles ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>
This is previousarticle.php
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('testDb', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$current_id = $_REQUEST['currentRecord'];
$result = mysql_query("SELECT * FROM articles WHERE id < ".$current_id." ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>
This is nextarticle.php
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('testDb', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$current_id = $_REQUEST['currentRecord'];
$result = mysql_query("SELECT * FROM articles WHERE id > ".$current_id." ORDER BY id ASC LIMIT 1");
$result = mysql_fetch_row($result);
echo json_encode($result);
?>
I made changes in all files in some extent.So please modify accordingly in your code.And do proper coding from next time.
And you add validation like If its last row , disable NEXT button , if its 1st row , disable PREV button.I solved what you asked.
Thanks!

PHP Form - Having Issues

I've been having some serious problems getting my form to work properly. Below are first the PHP calculations (attireCalculate.php), then the PHP processing file (processAttire.php), and finally my XHTML (attireForm.php). Sorry for how long this all is, but I've been going through it over and over and over and looking all over the web to no avail. I just can't find the problem(s). Nothing happens when I click the submit button.
I should mention that I am new to programming and PHP, so it may be that whatever I am missing is really quite simple. Thanks for your help. I really appreciate it.
attireCalculate.php
<?php
function message($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ, $datAsheQ, $graggyIceQ)
{
$cost = sprintf("%.2lf", calculateCost($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ, $datAsheQ, $graggyIceQ));
$tax = sprintf("%.2lf", calculateTax($cost));
$total = sprintf("%.2lf", calculateTotal($cost, $tax));
$text = "<h1>Product Summary</h1>".
"<h3>The cost of items selected is $".$cost.".<br />".
"The tax applied is $".$tax.".<br />".
"Therefore, the total cost is $".$total.".</h3>";
return $text;
}
function calculateCost($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ, $datAsheQ, $graggyIceQ)
{
return ($ramHatQ+$teemoHatQ)*14.99+($blitzHoodieQ+$galioHoodieQ)*24.99+($datAsheQ+$graggyIceQ)*19.99;
}
function calculateTax($cost)
{
return $cost*0.075;
}
function calculateTotal($cost, $tax)
{
return $cost+$tax;
}
function mailSummary($email, $message)
{
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: EMAIL\r\n";
mail($email, "Product Summary from Riot Store Online", $message, $header);
}
?>
Here is the processAttire.php file. I commented out the bit on tax exemption since there really is no point getting into that if I can't even get the thing to work as it is!
<?php
include 'attireCalculate.php';
$message = message($_POST['ramHatQ'], $_POST['teemoHatQ'], $_POST['blitzHoodieQ'], $_POST['galioHoodieQ'], $_POST['datAsheQ'], $_POST['graggyIceQ']);
echo $message;
if ($_POST['wantMail'])
{
mailSummary ($_POST['email'], $message);
echo "<h2>A summary has been sent to you via e-mail.</h2>";
}
/*
if ($_POST['taxExemptStatus'])
{
calculateCost($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ,
$datAsheQ, $graggyIceQ);
echo "<h2>Your tax-exempt status has been taken into account. Tax has been deducted from total cost.</h2>";
}
else
calculateTax($totalCost);
*/
?>
And here is the XHTML:
<form id="attireForm" onsubmit="return validateAttireForm()"
action="scripts/processAttire.php" method="post">
<fieldset>
<legend>Headwear</legend>
<table id="attireTable" summary="Headwear">
<tr>
<td>Rammus Hat</td>
<td>$14.99</td>
<td><label for="ramHatType">Type: </label></td>
<td><select id="ramHatType" name="ramHatType">
<option>Original</option>
<option>Ninja</option>
</select></td>
<td><label for="ramHatQ">Quantity: </label></td>
<td><input id="ramHatQ" type="text" name="ramHatQ" size="1" value="0" /></td>
</tr>
<tr>
<td>Teemo Hat</td>
<td>$14.99</td>
<td></td>
<td></td>
<td><label for="teemoHatQ">Quantity: </label></td>
<td><input id="teemoHatQ" type="text" name="teemoHatQ" size="1" value="0" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Hoodies</legend>
<table id="attireTable" summary="Hoodies">
<tr>
<td>Blitzcrank Hoodie</td>
<td>$24.99</td>
<td><label for="blitzHoodieQ">Quantity: </label></td>
<td><input id="blitzHoodieQ" type="text" name="blitzHoodieQ" size="1" value="0" /></td>
</tr>
<tr>
<td>Galio Hoodie</td>
<td>$24.99</td>
<td><label for="galioHoodieQ">Quantity: </label></td>
<td><input id="galioHoodieQ" type="text" name="galioHoodieQ" size="1" value="0" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>T-Shirts</legend>
<table id="attireTable" summary="T-Shirts">
<tr>
<td>"Dat Ashe" T-Shirt</td>
<td>$19.99</td>
<td><label for="datAsheQ">Quantity: </label></td>
<td><input id="datAsheQ" type="text" name="datAsheQ" size="1" value="0" /></td>
</tr>
<tr>
<td>"Graggy Ice" T-Shirt</td>
<td>$19.99</td>
<td><label for="graggyIceQ">Quantity: </label></td>
<td><input id="graggyIceQ" type="text" name="graggyIceQ" size="1" value="0" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Record?</legend>
<table summary="Record?">
<tr>
<td><label for="wantMail">Would you like a record sent to you by e-mail? </label></td>
<td><input id="wantMail" type="checkbox" name="wantMail" value="yes" /></td>
</tr>
<tr>
<td><label for="email">E-mail Address: </label></td>
<td><input id="email" type="text" name="email" size="25" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Processing</legend>
<table summary="Processing">
<tr>
<td><label for="taxExemptStatus">Do you have tax-exempt status? </label></td>
<td><input id="taxExemptStatus" type="checkbox" name="taxExemptStatus" value="yes" /></td>
</tr>
<tr>
<td><input type="submit" value="Add to Cart" /></td>
<td><input id="resetAttire" type="reset" value="Reset Selections" /></td>
</tr>
</table>
</fieldset>
</form>
And here is the JavaScript file containing validateAttireForm():
//attireValidate.js
function validateAttireForm()
{
var attireFormObj = document.getElementById("attireForm")
var ramHatQ = attireFormObj.ramHatQ.value;
var teemoHatQ = attireFormObj.teemoHatQ.value;
var blitzHoodieQ = attireFormObj.blitzHoodieQ.value;
var galioHoodieQ = attireFormObj.galioHoodieQ.value;
var datAsheQ = attireFormObj.datAsheQ.value;
var graggyIceQ = attireFormObj.graggyIceQ.value;
var email = attireFormObj.email.value;
var quantities = new Array(ramHatQ, teemoHatQ, blitzHoodieQ, galioHoodieQ, datAsheQ, graggyIceQ);
for (q in quantities)
{
quantityOK = validateQuantity(quantities[q]);
if (quantityOK = false)
{
break;
}
}
if (attireFormObj.wantMail.checked)
emailOK = validateEmail(email);
else
emailOK = true;
return quantityOK && emailOK;
}
function validateQuantity(quantity)
{
if (isNaN(quantity))
{
alert("Error: One or more quantities are abnormal. Please input a number for quantity.")
return false;
}
if (quantity < 0 || quantity > 100)
{
alert("Error: Quantity must be in the range 0-100 units.")
return false;
}
return true;
}
function validateEmail(address)
{
var p = address.search(/^\w+([\.-]?\w+)*#\w+([\.-]?\w+)*(\.\w{2,3})$/);
if (p == 0)
return true;
else
{
alert("Error: Invalid e-mail address.")
return false;
}
}
Instead of mixing PHP and Javascript in the submit action of your form, call processAttire.php in the Javascript itself:
$.get('scripts/processAttire.php', function(data) {
eval(data);
});
That way you'll have control what order your scripts are executed in. Note: You'll need to use JQuery for this.

Dynamic table along with value

JQUERY
<script type="text/javascript" src="jquery-1.5.1.min.js"></script>
<script type="text/javascript">
$('#aggiungi').live('click', function(){
var thisRow = $(this).parent().parent();
// clone and add data
thisRow.clone(true).insertAfter(thisRow).data('is_clone',true);
$(this).val("-");
$(this).attr("id","remove");
var nextRow = thisRow.next();
nextRow.find('input:not(#aggiungi)').val("");
if (thisRow.data('is_clone')){
while(thisRow.data('is_clone')){
thisRow = thisRow.prev();
}
}else{
nextRow.children(":first").remove();
}
currRowSpan = thisRow.children(":first").attr("rowspan");
thisRow.children(":first").attr("rowspan", currRowSpan+1);
});
$('#remove').live('click', function(){
var thisRow = $(this).parent().parent(),
prevRow = thisRow.prev();
if (thisRow.data('is_clone')){
while(prevRow.data('is_clone')){
prevRow = prevRow.prev();
}
}else{
prevRow = thisRow.next()
.removeData('is_clone')
.children(":first")
.before(thisRow.children(":first"))
.end();
}
currRowSpan = prevRow.children(":first").attr("rowspan");
prevRow.children(":first").attr("rowspan", currRowSpan-1);
thisRow.remove();
});
</script>
PHP
<form action="grading.php" method="post">
<table width-"100%" id="tableRealizzazione">
<tr>
<th></th>
<th style="padding:12px;text-align:center;">Personale</th>
<th style="padding:12px;text-align:center;">Percentage</th>
<th style="padding:12px;text-align:center;">Marketing point</th>
<th style="padding:12px;text-align:center;">Add/Remove</th>
</tr>';
echo '<tr class="even">
<td></td>
<td style="padding:12px;"><input type="text" value="" id="Personale" name="Personale"></td>
<td style="padding:12px;">
<input type="text" id="from" name="from" size="5%"> -
<input type="text" id="to" name="to" size="5%"> %
</td>
<td style="padding:12px;"><input type="text" class="totaliCostiGestione" id="marketpt" name="marketpt"></td>
<td style="padding:12px;"><input type="text" name="programid" value ="34" size="10%"></td>
<td style="padding:12px;"><input type="button" value="+" id="aggiungi"/></td>';
echo '</tr>';
echo '<tr><td><input type="submit" name="submit" value="submit"></td></tr>';
echo '</table>
</form>
When I fill the values of all text boxes and click submit, it prints only the last row and the the last row with value 34 not repeating for all the rest rows.
Here is my code in Fiddle
http://jsfiddle.net/gansai/PA9JF/
That is because you have to make arrays from your form:
eg:
<input type="text" id="from" name="from[]" size="5%"> -
to clone values you have to add:
newRow = thisRow.clone(true).insertAfter(thisRow).data('is_clone',true);
$(newRow+"[name^=programid]").val($(thisRow+"[name^=programid]").val());
Like this JSFiddle
then in PHP:
foreach($_POST['marketpt'] as $num => $val){
$Personale = $_POST[$num]['Personale'];
$from = $_POST[$num]['from'];
$to = $_POST[$num]['to'];
$marketpt = $_POST[$num]['marketpt'];
$programid = $_POST[$num]['programid'];
// process variables, eg: insert in database
}

Pass back values to form to populate it? (lots of values)

I need to pass back a large string of results to a form, so that the form can read those results from the URL and then populate the form with them. Problem is, the link ends up being:
&key=value&key=value ... until it can't process anymore (I assume a URL has a length limit?) resulting in my form not being able to fully populate. I need another way to pass values back to my form file.
VIEW.php file (basically just a table of values right as they are from the database, with the first column "id" being a link. When I click on "id", it goes back to my add.php(form page) and populates the form with the data matching that id)
<table border="0" cellpadding="0" cellspacing="0" id="table">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>MANUFACTURER</th>
<th>MODEL</th>
<th>DESCRIPTION</th>
<th>ON HAND</th>
<th>REORDER</th>
<th>COST</th>
<th>PRICE</th>
<th>SALE</th>
<th>DISCOUNT</th>
<th>DELETED</th>
<th></th>
</tr>
</thead>
<tbody>
<?php } ?>
<?php
// loop to fetch data
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>
<a href='molszewski1_a2_add.php'>$row[id]</a></td>";
echo "<td>$row[name]</td>";
echo "<td>$row[manufac]</td>";
echo "<td>$row[model]</td>";
echo "<td>$row[descrip]</td>";
echo "<td>$row[onhand]</td>";
echo "<td>$row[reorder]</td>";
echo "<td>$row[cost]</td>";
echo "<td>$row[price]</td>";
echo "<td>$row[sale]</td>";
echo "<td>$row[discont]</td>";
echo "<td>$row[deleted]</td>";
$status = "$row[deleted]";
echo "<td><a href='molszewski1_a2_delete.php?id=$row[id]&flag=$status&sort=$sort'>";
$status = "$row[deleted]";
if ($status == 'n') {
$flag = "restore";
echo "delete";
} else if ( $status == 'y') {
$flag = "delete";
echo "restore";
}
echo "</a></td>";
echo "</tr>";
} ?>
<?php { ?>
</tbody>
</table>
ADD.php (form page where the form is supposed to fetch the data and populate it)
<?php
// If no form has been submitted, present form
if (empty($_GET))
{
add_form();
}
// if a form has been submitted
else
{
// if form_validity() == 1, proceed to connect
if (form_validity() == 1)
{
// connect to mysql + database
connect();
$saleItem = "n";
$discountItem = "n";
if( array_key_exists( 'saleItem', $_GET ) && $_GET['saleItem'] == 'y' )
{ $saleItem = "y"; }
if( array_key_exists( 'discountItem', $_GET ) && $_GET['discountItem'] == 'y' )
{ $discountItem = "y"; }
// get values from form, insert into database
$sql=("INSERT INTO inventory (name,
manufac,
model,
descrip,
onhand,
reorder,
cost,
price,
sale,
discont,
deleted)
VALUES ('$_GET[itemName]',
'$_GET[manufacturer]',
'$_GET[model]',
'$_GET[description]',
'$_GET[numberOnHand]',
'$_GET[reorderLevel]',
'$_GET[cost]',
'$_GET[sellingPrice]',
'$saleItem',
'$discountItem', 'n')");
// if the query doesn't work, display error message
if (!(mysql_query($sql))) { die ("could not query: " . mysql_error()); }
add_form();
// redirect to view.php after form submission
// use php instead
echo "<meta http-equiv='REFRESH' content='0;url=molszewski1_a2_view.php'>";
}
else
{
// if form is not valid (form_validity returns 0), display error messages
add_form();
}
}
?>
FUNCTIONS.php (all my functions for stuff like the form)
<?php function page_navigation(){ ?>
<div class="center">
<input type="button" value="ADD" />
<input type="button" value="VIEW" />
<input type="button" value="VIEW DELETED" />
<input type="button" value="VIEW ACTIVE" />
<br />
<br />
</div>
<?php } ?>
<?php function add_form() { ?>
<form action="molszewski1_a2_add.php" method="get" id="form">
<table width="529px">
<tr>
<td>ITEM NAME</td>
<td><input name="itemName" size="30" type="text" value="<?php echo $_GET["itemName"] ?>"/></td>
</tr>
<tr>
<td>MANUFACTURER</td>
<td><input name="manufacturer" size="30" type="text" value="<?php echo $_GET["manufacturer"] ?>"/></td>
</tr>
<tr>
<td>MODEL</td>
<td><input name="model" size="30" type="text" value="<?php echo $_GET["model"] ?>"/></td>
</tr>
<tr>
<td>DESCRIPTION</td>
<td><textarea name="description" rows="3" cols="20"><?php echo $_GET["description"] ?></textarea></td>
</tr>
<tr>
<td>ON HAND</td>
<td><input name="numberOnHand" size="30" type="text" value="<?php echo $_GET["numberOnHand"] ?>"/></td>
</tr>
<tr>
<td>REORDER LEVEL</td>
<td><input name="reorderLevel" size="30" type="text" value="<?php echo $_GET["reorderLevel"] ?>"/></td>
</tr>
<tr>
<td>COST</td>
<td><input name="cost" size="30" type="text" value="<?php echo $_GET["cost"] ?>"/></td>
</tr>
<tr>
<td>SELLING PRICE</td>
<td><input name="sellingPrice" size="30" type="text" value="<?php echo $_GET["sellingPrice"] ?>"/></td>
</tr>
<tr>
<td>SALE ITEM</td>
<td>
<input type="checkbox" name="saleItem" value="y" <?php if( isset( $_GET['saleItem'] ) ){ ?> checked="checked" <?php } ?> />
</td>
</tr>
<tr>
<td>DISCOUNTED ITEM</td>
<td>
<input type="checkbox" name="discountItem" value="y" <?php if( isset( $_GET['discountItem'] ) ){ ?> checked="checked" <?php } ?> />
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="save" name="submit" id="submit" /></td>
</tr>
</table>
</form>
<?php } ?>
Use method="post" and $_POST (instead of $_GET).
POST requests can be much larger than GET requests as GET requests are limited by the maximum length of a URL. POST requests are limited by the size of the max_post_size ini-value which is usually a few megabytes.

You have an error in your SQL syntax;

G'Day
I have a php page that I want to edit an entry but for the life of me I can not figure out why it is coming up with this erro.
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 '= po_postcode = '4060', email ='-', phone = '732997688', fax = '' WHERE id='1'' at line 1
HELP I am desperate and going insane. (Similar Code works on another page but not this one)....
Can someone PLEASE HELP.
{
<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($id, $name, $po_street, $po_suburb, $po_state, $po_postcode, $email, $phone, $fax, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<table width="347" border="0" align="center">
<tr valign="baseline">
<td align="right" nowrap="nowrap"><p align="center"><img src="hartwell_banner.JPG" width="624" height="134" /></p>
</tr>
</table>
<table align="center">
<tr valign="baseline">
<td width="290" align="right" nowrap="nowrap"><div align="left"><h2 align="left"><p align="left">Enter a New Contact</p></h2></div></td>
<td width="290" align="center" nowrap="nowrap"><div align="left"><h2 align="center"><p align="center">Return to Index</p>
</h2>
</div></td>
</tr>
</table>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<table align="center">
<tr valign="baseline">
<td width="98" align="right" nowrap="nowrap"><div align="left">ID:</div></td>
<td width="329"><input type="text" name="id" value="<?php echo $id; ?>" size="40" readonly = "readonly" /> * </td>
</tr>
<tr valign="baseline">
<td width="98" align="right" nowrap="nowrap"><div align="left">Name:</div></td>
<td width="329"><input type="text" name="name" value="<?php echo $name; ?>" size="40" /> * </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">Postal Street </div></td>
<td><input type="text" name="po_street" value="<?php echo $po_street; ?>" size="40" /> * </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">Postal Suburb</div></td>
<td><Input type ="text" name="po_suburb" value="<?php echo $po_suburb; ?> " size="30" maxlength="50" >*</td>
<tr valign="baseline">
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">State</div></td>
<td><Input type ="text" name="po_state" value="<?php echo $po_state; ?>" size="5" maxlength="3" /> * </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">Postal Postcode</div></td>
<td><Input type ="text" name="po_postcode" value="<?php echo $po_postcode; ?>" size="5" maxlength="4"/> * </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">Email:</div></td>
<td><input type="text" name="email" value="<?php echo $email; ?>" size="40" /> * </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">Phone:</div></td>
<td><input name="phone" type="text" value="<?php echo $phone; ?>" size="12" maxlength="10" /> * </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><div align="left">Fax:</div></td>
<td><input name="fax" type="text" value="<?php echo $fax; ?>" size="12" maxlength="10" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td> <input type="submit" name="submit" value="Submit"> * Denotes Required Field<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?> </td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" nowrap="nowrap"><div align="center"><img src="hartwell_costs.JPG" alt="" width="340" height="147" /></div></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (isset($_POST['id']))
{
// get form data, making sure it is valid
$id = mysql_real_escape_string(htmlspecialchars($_POST['id']));
$name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
$po_street = mysql_real_escape_string(htmlspecialchars($_POST['po_street']));
$po_suburb = mysql_real_escape_string(htmlspecialchars($_POST['po_suburb']));
$po_state = mysql_real_escape_string(htmlspecialchars($_POST['po_state']));
$po_postcode = mysql_real_escape_string(htmlspecialchars($_POST['po_postcode']));
$email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
$phone = mysql_real_escape_string(htmlspecialchars($_POST['phone']));
// check that firstname/lastname fields are both filled in
if ($id == '' || $name == '' || $po_street == '' || $po_suburb == ''|| $po_state == '' || $po_postcode == ''|| $email == '' || $phone == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($id, $name, $po_street, $po_suburb, $po_state, $po_postcode, $email, $phone, $fax, $error);
}
else
{
// save the data to the database
mysql_select_db($database_hartwell, $hartwell);
mysql_query("UPDATE contact SET id= '$id', name='$name', po_street ='$po_street', po_suburb = '$po_suburb', po_state = '$po_state', = po_postcode = '$po_postcode', email ='$email', phone = '$phone', fax = '$fax' WHERE id='$id'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: view.php");
}
}
else
{
//if the 'id' isn't valid, display an error
echo 'ID Not Valid!';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
mysql_select_db($database_hartwell, $hartwell);
$result = mysql_query("SELECT * FROM contact WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$id = $row['id'];
$name = $row['name'];
$po_street = $row['po_street'];
$po_suburb = $row['po_suburb'];
$po_state = $row['po_state'];
$po_postcode = $row['po_postcode'];
$email = $row['email'];
$phone = $row['phone'];
$fax = $row['fax'];
// show form
renderForm($id, $name, $po_street, $po_suburb, $po_state, $po_postcode, $email, $phone, $fax,'');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'No ID Value!';
}
}
?>
The error is right there in your query, just like the error message says:
, = po_postcode = '$po_postcode',
^
|
+ this doesn't belong here
remove the equal sign here:
'$po_state', = po_postcode
mysql_query("UPDATE contact SET id= '$id', name='$name', po_street ='$po_street', po_suburb = '$po_suburb', po_state = '$po_state', po_postcode = '$po_postcode', email ='$email', phone = '$phone', fax = '$fax' WHERE id='$id'")
So the problem is here = po_postcode = '$po_postcode',

Categories