<?php

     //redirect the user to login if session is invalid
     include("validate_session.php");
	$alert =0;

         $userid=$_SESSION["userid"];

         //Connecting to database
         include("db_connect.php");

         foreach ($_POST as $key => $value)
             if  (substr($key,0,8) =="txt_chk_")
             {
			$alert =1;
			 
			  $itemid=substr($key,8,3);
			  $purtime=substr($key,11,8);
			  $purdate=substr($key,19,10);
			  $itemdate=substr($key,8);
						  
              foreach ($_POST as $key1 => $value1)
               if ($key<>$key1)
               {
                 $tempstr= substr($key1,0,strlen($key1)-strlen($itemdate));
                 if (substr($key1,strlen($tempstr))==$itemdate)
                 {
                     if ($tempstr=="txt_qty_")
                          $qty = $value1;

                     if ($tempstr=="txt_price_")
                          $price = $value1;


                     if ($tempstr=="txt_date_")
                           $date = $value1;
						   
					
                 }//end if

               }//end if
	/////////////////////////////////////////////////////////////////////////////////		   
	$Rs=mysql_query("Select * from sales where userid ='$userid' and itemid ='$itemid' and sdate=NOW()");	
	
	if(mysql_num_rows($Rs) > 0)
		{ $rows = mysql_fetch_array($Rs); 
		$newqty = $rows["qty"] + $qty;
		$sql_update ="UPDATE sales set qty=$newqty where userid ='$userid' and itemid ='$itemid' and sdate =NOW()";
				if (!mysql_query($sql_update,$con))
                {
                 die('Error: ' . mysql_error());
                }
		}	
		
		else  
            {    //Buiding the insert statement for sales
				               $sql_insert= "INSERT INTO sales (Userid, itemid,sdate,price,qty) VALUES ('$userid','$itemid',NOW(), $price , $qty)";

                if (!mysql_query($sql_insert,$con))
                {
                 die('Error: ' . mysql_error());
                }

}///////////////////////////////////////////////////////////////////////////////////
                //Building the update statement for basket
                $sql_update="Update basket set status ='s' WHERE userid='$userid' AND itemid='$itemid' AND date='$date $purtime' and ptime='$purtime' and status='p'";
				
				if (!mysql_query($sql_update,$con))
				
                {
                 die('Error: ' . mysql_error());
                }
				
				$sql_delete="DELETE FROM basket WHERE status='p'";
				
				if (!mysql_query($sql_delete,$con))
			{
				die('Error: ' . mysql_error());
			}

             }//endif
			 
						
             mysql_close($con);
			 
		?>
 <html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>

<body>
<?php if ($alert =='0')
{
/* echo $itemid;
 echo "<br>";
echo $purtime;
 echo "<br>";
 echo $purdate;
  echo "<br>";
echo $itemdate;
 echo "<br>";*/
?>
<center>
<h2>Credit Card Details</h2>
<img src="images/creditcard.jpg" width="258" height="126"/>
</center>
<script type="text/javascript">
<!--


function validateNumericCreditCard()
{
	var str="0123456789";
	var sid=document.frm_creditcard.txt_CardNumber.value;
	
	if ((sid.length)!=16)
	{
		alert("Credit card number must contain exactly 16 numbers");
		return false;
	}
	
	for(i=0; i<sid.length; i++)
	{
		if(str.indexOf(sid.charAt(i))==-1)
		{
			alert("Please enter numeric character for Credit Card");
			return false;
		}//end if
	}//end for
	return true;
}

-->
</script>

<form name=frm_creditcard action="congrats.html" onSubmit="return validateNumericCreditCard()">

<table cellpadding="7" align="center">
<tr><td>Card Number: </td>
	<td><input name="txt_CardNumber" size="16" maxlength="16" ></td></tr>
<tr><td>Card Type:</td>
<td><select name="CardType">
	<option value="MasterCard">MasterCard
	<option value="VisaCard">Visa
	<option value="AmExCard">American Express
	<option value="DinersClubCard">Diners Club
	<option value="DiscoverCard">Discover
	<option value="enRouteCard">enRoute
	<option value="JCBCard">JCB
</select></td></tr>
<tr><td colspan="2"><input name="Submit" type="submit" value="Submit" /></td></tr>
</table>
</form>
<? 
}

else
{
echo "<h2 align='center'><b>Error</b></h2>"; 
echo "Please make sure that you have selected at least one item from your basket to buy!";
?>
<br>
<br>

<input type="button" value="OK" name="btn_ok" onClick="window.location='login_pro.php'">
<?
}?>

</body>
</html>

I've got an error on this page and i cant spot what is the error.I think it has something to do with the database. Can someone tell me the mistake in this code please?The error is "Parse error: syntax error, unexpected $end in C:\xampp\htdocs\flower\purchase.php on line 173"

The database name and details are attached to this document. Thank for the help in advance.

I removed codes from line 93 to 103 and from 155 to 162. The mistake is no longer present but the form does not do its work as intended. Let me know asap plz.

I think you miss the bracket(})..make sure you close every bracket

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.