Page 1 of 1

problem in updating the max record

Posted: Sat Jun 23, 2007 5:20 am
by purnendu231172
Hi all,

I am getting the problem in my site.This is the flow of the functionality.
First see the flow , table structure and code , which i am using.i the last i will tell
you the problem...



First page(form.php)
In form.php, the customer is filling the information to purchage something. After filling this
information and submitting , the filled information is going into database table(customer table).
here i am writing the insert command.


second page(confirmation.php)

In confirmation.php, i am displaying the all details filled by customer in by using form.php.here i am writhing

the select command.
Here, i am giving two button, one button is confirm and second is Edit.Forget conform button for now,it will go

to paypal.once i click on the edit button, it will go to third page called confirmation_edit.php


Third page(confirmation_edit.php)

Here customer can edit the information filled by him (using form.php). here i am writing select and update

command for updating the last record.once i clicked on edit button the edited value is updating into customer
table.


------------------------------------------------------------------
This is table structure::::::

Code: Select all

CREATE TABLE `customer` (
  `cust_id` int(15) NOT NULL auto_increment,
  `cust_tiltle` varchar(10) collate latin1_general_ci NOT NULL,
  `cust_first_name` varchar(50) collate latin1_general_ci NOT NULL,
  `cust_last_name` varchar(50) collate latin1_general_ci NOT NULL,
  `cust_dob` varchar(100) collate latin1_general_ci NOT NULL,
  `cust_telephone1` varchar(100) collate latin1_general_ci NOT NULL,
  `cust_telephone2` int(100) NOT NULL,
  `cust_email` varchar(100) collate latin1_general_ci NOT NULL,
  `cust_address` text collate latin1_general_ci NOT NULL,
  `cust_place` varchar(250) collate latin1_general_ci NOT NULL,
  `cust_county` varchar(150) collate latin1_general_ci NOT NULL,
  `cust_postcode` varchar(150) collate latin1_general_ci NOT NULL,
  `cust_country` varchar(100) collate latin1_general_ci NOT NULL,
  `cust_status` int(25) NOT NULL,
  `cust_origin` int(25) NOT NULL,
  `cust_quantity` int(25) NOT NULL,
  `cust_cost` varchar(25) collate latin1_general_ci NOT NULL,
  `cust_date` varchar(50) collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`cust_id`)
)
---------------------------------------------------------------

--------------------------------------------------------------------------

code::::of form.php::::::

Code: Select all

<?php
 include "connection.php";
 if (isset($_POST['contact_title']))
{
    $cust_id=$_POST['cust_id'];

	$quantity=$_POST['selectQty'];
	$costs=$_POST['price'];

	$title=$_POST['contact_title'];
	$fname=$_POST['contact_fname'];
	$sname=$_POST['sname'];
	$phone=$_POST['contact_dtel'];
	$email=$_POST['contact_email'];
	$dob=$_POST['contact_dob_day']. "/" . $_POST['contact_dob_month']. "/" . $_POST['contact_dob_year'];
	//$pass=$_POST['pwd'];
//$date1=date("Y-m-d");
//echo $date1;
			//$pass=$_POST['pwd_two '];
    $add=$_POST['contact_add1'];
	$place=$_POST['contact_town'];
	$county=$_POST['contact_county'];
	$country="united kingdom";
	$pcode=$_POST['contact_pcode'];
	$date1=date("j-n-Y");
	//echo $date1;
	//$date1=date("DD.MM.YYYY");
	//$date1=date('%d/%m/%Y');
	//$date1=date("j, n, Y");
	//$ip = $_SERVER['REMOTE_ADDR'];
	$status=1;
		//$mobile=$_POST['mobile'];
		//$status="pending";
	  $query="INSERT INTO 

customer(cust_tiltle,cust_first_name,cust_last_name,cust_telephone1,cust_email,cust_dob,cust_address,cust_place

,cust_county,cust_postcode,cust_country,cust_quantity,cust_cost,cust_date,cust_status) VALUES 
	

('$title','$fname','$sname','$phone','$email','$dob','$add','$place','$county','$pcode','$country','$quantity',

'$costs','$date1','$status')";
	//echo $query;
 $var=mysql_query($query)or die(mysql_error());


/*
 if (isset($_POST['selectQty']))
{



		$quantity1=$_POST['selectQty'];
	$costs1=$_POST['price'];
	$date1=date("Y-m-d");
$status="pending";
	  $query1="INSERT INTO itemdetails(quantity,costs) VALUES ('$quantity1','$costs1')";
$var1=mysql_query($query1)or die(mysql_error());


*/


if($var)
{
?>
<script>location.href="confirmation.php";</script>
<?
//}
}
	
}
?>
----------------------------------------------------------------------


code of confirmation.php::::::::::::::::::::::::::

Code: Select all

<?php
include 'connection.php';
$qry="select * from customer where cust_id= (SELECT MAX(cust_id) FROM customer);";
$rs=mysql_query($qry) or die("error:". mysql_error());
$itemrow=mysql_fetch_assoc($rs);
$no_of_rows=mysql_num_rows($rs);
$cust_id=$itemrow['cust_id'];

$title=$itemrow['cust_tiltle'];
$fname=$itemrow['cust_first_name'];
$sname=$itemrow['cust_last_name'];
$phone=$itemrow['cust_telephone1'];
$email=$itemrow['cust_email'];
$dob=$itemrow['cust_dob'];

$hno=$itemrow['cust_address'];
$place=$itemrow['cust_place'];
$county=$itemrow['cust_county'];
$country=$itemrow['cust_country'];
$pcode=$itemrow['cust_postcode'];

$quantity=$itemrow['cust_quantity'];
$cost=$itemrow['cust_cost'];
$status=$itemrow['cust_status'];

$sno1=$cust_id;
$query_ord="INSERT INTO order_details(cust_id,ord_qty,ord_cost,wp_date,ord_date,wp_id_addr,ord_status) VALUES 
	('$sno1','$cust_quantity','$cust_cost','$date1','$date1','$ip','$status')";
 $var_ord=mysql_query($query_ord)or die(mysql_error());
if($var)
{
?>
<script>location.href="confirmation_edit.php?cust_id=<?=$sno1 ?>";</script>
<?
}

?>
---------------------------------------------------------------------------

code of confirmation_edit.php::::::::::::::::::::

Code: Select all

<?php
session_start();
include 'connection.php';
//$qry="select * from paypal where sno= (SELECT MAX(sno) FROM paypal);";
$qry="select * from customer where cust_id= (SELECT MAX(cust_id) FROM customer);";
$rs=mysql_query($qry) or die("error:". mysql_error());
$itemrow=mysql_fetch_assoc($rs);
$no_of_rows=mysql_num_rows($rs);
$cust_id=$itemrow['cust_id'];
//echo $sno;
$title=$itemrow['cust_title'];
$fname=$itemrow['cust_first_name'];
$sname=$itemrow['cust_last_name'];
$phone=$itemrow['cust_telephone1'];
$email=$itemrow['cust_email'];
$dob=$itemrow['cust_dob'];
//$pd=$itemrow['pd'];
$hno=$itemrow['cust_address'];
$place=$itemrow['cust_place'];
$county=$itemrow['cust_county'];
$country=$itemrow['cust_country'];
$pcode=$itemrow['cust_postcode'];


  if (isset($_POST['title']))
  {
    $title=$_POST['title'];
	$fname=$_POST['fname'];
	$sname=$_POST['sname'];
	$phone=$_POST['phone'];
	$email=$_POST['email'];
	$dob=$_POST['dob']. "/" . $_POST['contact_dob_month']. "/" . $_POST['contact_dob_year'];
	$pass=$_POST['pass '];
    $add=$_POST['contact_add1'];
	$place=$_POST['town'];
	$county=$_POST['county'];
	$country="united kingdom";
	$pcode=$_POST['pcode'];
	$mobile=$_POST['mobile'];
	$quantity=$_POST['selectQty'];
	$costs=$_POST['price'];
    $sno1=$cust_id;
$update="update customer set cust_tiltle='$title',
							cust_first_name='$fname',
							cust_last_name='$sname',
							cust_telephone1='$phone',
							cust_email='$email',
							cust_dob='$dob',
							cust_quantity='$quantity',
							cust_cost='$costs',
							cust_address='$add',
							cust_place='$place',
							cust_county='$county',
							cust_country='$country',
							cust_postcode='$pcode'
							where cust_id= $sno1";
							$var=mysql_query($update)or die(mysql_error());


if($var)
{
?>
<script>location.href="confirmation.php?cust_id=<?=$sno1 ?>";</script>
<?

}
}
?>
--------------------------------------------------------------------

Now this is the problem i am geting after hosting my site.....

when the customer(sitting in india) is filling the form and going into second page(confirmation.php), and he is

leaving his system as it in the same page(means confirmation.php) for 5 hours.

suppose he filled the following information

fist name : purnendu
seconde name: Ranjan
phone : 9812451245
email : puru@yahoo.com


after some time, second comtomer(sitting in london) is filling the form(using form.php) with different

information like name:Amitab sec name: bachhan phone: 9856895689. after submit this form once he is comnig to

conformation page, he is geting the following information in confirmation page.



fist name : purnendu
seconde name: Ranjan
phone : 9812451245
email : puru@yahoo.com

he shourd get this information:::: name:Amitab, second name: bachhan, phone: 9856895689 in confirmation page..

I used the record of MAX (where cust_id= (SELECT MAX(cust_id) FROM customer);";)..for editing the record

thatswhy problem is coming.

[s]Plz[/s] please any body can give me solution for that problem....


Thanks and regards,

Ranjan
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Sat Jun 23, 2007 7:06 am
by superdezign
Whats makes you think that using the MAX() customer id would even work? Doesn't that destroy the purpose of giving the customer an id in the first place?

Save their unique id into a session or a cookie and access their information through it.