hi all,
i am doing a shopping cart example.after the shopping is complete it is mandatory for the user
to fill his details.so that it will go in to database.
i have written my both php and javascript code but the "billing.php" is not taking in the database
PHP Code:
<?php
include("db.php");
include(
"functions.php");
if(
$_REQUEST['command']=='update')
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$phone=$_REQUEST['phone'];
$result=mysql_query("insert into customers values('','$name','$email','$phone')");
$customerid=mysql_insert_id();
$date=date('Y-m-d');
$result=mysql_query("insert into orders values('','$date','$customerid')");
$orderid=mysql_insert_id();
    
$max=count($_SESSION['cart']);
for(
$i=0;$i<$max;$i++)
{
  
$pid=$_SESSION['cart'][$i]['productid'];
  
$q=$_SESSION['cart'][$i]['qty'];
  
$price=get_price($pid);
  
mysql_query("insert into order_detail values($orderid,$pid,$q,$price)");
}
 die(
'Thank You! Your Order Has Been Placed!');
}
?>
below is my javascript code.....
Code:
<!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">
<head>
<title>Billing Information</title>
<script type="text/javascript">
function checkName(form)
 {
  var eobj=document.getElementById('realnameerror');
  var sRealName = form.realname.value;
  var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;
  var error=false;
  eobj.innerHTML='';
  if (sRealName == '') 
  {
   error='Error: Username cannot be blank!';
   form.realname.focus();
  }
  else if (sRealName.length < 4) 
  {
    error="UserName should be atleast 4 characters long";
  }
  else if (!oRE.test(sRealName))
  {
   error="Incorrect format.";
  }
  if (error)
  {
   form.realname.focus();
   eobj.innerHTML=error;
   return false;
  }
  return true;
 }

function checkEmail(form)          /* for email validation */
{                               
 var eobj=document.getElementById('emailerror');
 eobj.innerHTML='';
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value))
 {
  return true;
 }
 eobj.innerHTML='Invalid E-mail Address! Please re-enter.';
 return false;
}

function validPhone(form)          /* phone no validation */
 {
 var eobj=document.getElementById('phonenoerror');
 var valid = '0123456789';
 var phone = form.phoneno.value;
 var error=false;
 var i=0;
 var temp;
 eobj.innerHTML='';
 if (phone == '')
 {
  error='This field is required. Please enter phone number';
 }
 else if (!phone.length > 1 || phone.length < 10)
 {
  error='Invalid phone number length! Please try again.';
 }
 else 
 {
  for (i=0; i < phone.length; i++)
  {
   temp = '' + phone.substring(i, i + 1);
   if (valid.indexOf(temp) == -1)
   {
    error='Invalid characters in your phone. Please try again.';
   }
  }
 }
 if (error)
 {
  form.phoneno.focus();
  eobj.innerHTML=error;
  return false;
 }
 return true;
}

function validate() 
{
 var form = document.forms['form'];
 var ary=[checkName,checkEmail,validPhone];
 var rtn=true;
 var z0=0;
 for (var z0=0;z0<ary.length;z0++)
 {
  if (!ary[z0](form))
  {
    rtn=false;
  }
 }
 return rtn;
 form.command.value='update';
 form.submit(); 
}
</script>
</head>
<body>
<form  name="form" method="post" onsubmit="return validate()">
 <div align="left">
   <h1 align="left">Billing Information</h1>
    Order Total:<b><?php echo "$" . get_order_total() ?></b><br>
    Cust Name:<input type="text" name="realname"> <span id="realnameerror" ></span><br>
    Email:<input type="text" name="email"> <span id="emailerror" ></span><br>
    Phone:<input type="text" name="phone" maxlength="10"> <span id="phonenoerror" ></span><br>
       <input type="submit" value="submit" />
 </div>
</form>
</body>
</html>
can u help me to identify where i went wrong....