Jump to content

Recommended Posts

Hello,

 

I've been developing an order script for learning purposes. Yesterday it was doing exactly as it should but i had to stop working on it and when i came back to it today it doesn't input any data into my database. Now i can't remember what i changed/did to the script before i stopped working on it.

 

I have been looking over it for hours now but i still can't spot what is wrong with it. The script is meant to display items (complete) which the user can select and type their desired quantity (complete). When they have selected what they want to order they click 'next' and their choices are displayed for conformation. (complete) To confirm the order they can click 'Confirm', the script appears to work but doesn't add any new entries into the database at all..

 

Im not sure what to do, could someone take a look and see if there is anything glaringly obvious?

 

<?php
session_start(); 
error_reporting(0);
include_once('odbc/odbc.php'); 
require_once('operate.php');

// check to see if user is logged in
checkUser();

$cust_name = $_SESSION['userName'];
$recordupdate = ""; 

// if 'next' is clicked item numbers & quantities user has picked are displayed, along with a 'Confirm' button to proceed with the next part of the script.
if (isset($_POST['update']) && ($_POST['update']==="Next")) {

  $orderid = array();
  $quantity = array();
  

  foreach($_POST['orderid'] as $id){
	$orderid[] = $id;
	$quantity[] = $_POST['quantity'][$id];

	 }
  
  $orderid = implode(',', $orderid);
  $quantity = implode(',', $quantity);
  
  //print out the item numbers and quantities here. At present they print out correctly, but nothing gets inputted into the database once 'Confirm' is clicked.
   
  print "Order Number $orderid<br />";
  
  print "Quantity     $quantity";
  
  print "<form name=\"the_forma\" id=\"the_forma\" method=\"post\" action=\"?id=products\">";
  print "<input name=\"updatea\" type=\"submit\" value=\"Confirm\">";
  print "</form>";
   
  }
  
if (isset($_POST['updatea'])==="Confirm") {

	$date = date('d m y');

	$conn = odbc_connect('CentralProduct', 'root', '') or die('Could not Connect to ODBC Database!');

	// execute SQL Statement

	$sql = "INSERT INTO [Order1] ([CustomerName], [OrderDate], [OrderNotes], [Quantity]) VALUES ('$cust_name', '$date', '$orderid', '$quantity')";

	$rs = odbc_exec($conn, $sql);

	if ($rs===false) {
		$recordupdate = "<span class=\"main\">The record was successfully inserted.</span>"; 
	}  
  
}

?>
<html>
<head>
<title>W D Smith & Sons</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css"></style>
</head>
<form name="the_form" id="the_form" method="post" action="?id=products">

<?php
// connect to access database and find the table 'Product1'
$sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName") or die (odbc_errormsg());

// define variables - use lowercase for variables names
$prevcat = "";


while($row = odbc_fetch_array($sql2))
{
	$category = $row["CategoryName"];
	$productid = $row["ProductId"];
	$productname = $row["ProductName"];
	$price = $row["Price"];
	$type = $row["Type"];
	$habit = $row["Habit"];
	$colour = $row["Colour"];
	$status = $row["Status"];


	// find out if category has changed
	// if so, print it, and it's contents
	if ($category != $prevcat)  {
		echo "<p class='title'><u>{$category}</u></p>"; 
	}

	echo  "<p class=main2>
	<strong>{$productname}</strong> - 
	({$colour} {$status} Item#{$productid}) 
	<span class=address1>£{$price} <input name=\"orderid[]\" value=\"{$productid}\" type=\"checkbox\"/> 
	<input name=\"quantity[{$productid}]\" type=\"text\" size=\"3\" maxlength=\"3\" /></span></p>";	

	$prevcat = $category;
}
?>
<hr />
	 <? echo $recordupdate; ?>
	 <input name="update" type="submit" value="Next" />
	</p>
  </p>
</div>
</form>
</body>
</html>
<?php
odbc_close($conn);
?>

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/89527-script-problems/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.