0

I am trying to get information from my database that contains a foreign key that relate to another table,

I am trying to enter details of an order and then have the customer ID of that order enter automatically from the customer table.

[B]Customer Table
[/B]
CREATE TABLE IF NOT EXISTS `customer` (
  `CustomerID` int(11) NOT NULL DEFAULT '0',
  `Customer Name` varchar(50) NOT NULL,
  `Customer Address` varchar(60) NOT NULL,
  `Customer Address1` varchar(60) NOT NULL,
  `Customer Address2` varchar(60) NOT NULL,
  `County` varchar(15) NOT NULL,
  `Customer Postcode` int(6) DEFAULT NULL,
  `Customer Tel No` int(11) NOT NULL,
  `Customer Email` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`CustomerID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
[B]Order Table
[/B]
CREATE TABLE IF NOT EXISTS `order` (
  `OrderID` int(10) NOT NULL,
  `OrderDateTime` datetime DEFAULT NULL,
  `CustomerID` int(11) DEFAULT NULL,
  `Delivery_Date` datetime DEFAULT NULL,
  `Actual_Delivery` datetime DEFAULT NULL,
  PRIMARY KEY (`OrderID`),
  KEY `Order_FK1_customer` (`CustomerID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

I have come up with the following code but it says that there is a error with it

<?php
include ("db.php");
include ("functions.php");



$ODateTime=$_POST["datetime"];
$Cid=getCustomerID($_POST["cid"]);
$ODeliveryDate=$_POST["deliverydate"];
$OActualDelivery=$_POST["actualdelivery"];

$str1="insert into order(OrderDateTime,CustomerID, ,DeliveryDate, ActualDelivery) values('$ODateTime','$Cid','$ODeliveryDate','$ActualDelivery')";

mysql_query($str1);
print ($str1);


?>
3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by markdh
0

The problem is in PHP or in MySQL ? … You provided a code with many include files that you didn’t provide so no one can say what you are doing. Explain it in few words and how you are trying to achieve it.

0

I'm not sure if you copied the code incorrectly but you've got an extra , between CustomerID and DeliveryDate.

Insert into order(OrderDateTime,CustomerID, ,DeliveryDate, ActualDelivery) values('$ODateTime','$Cid','$ODeliveryDate','$ActualDelivery')

Alternatively it could be that your insert statement isn't populating it's values correctly. I'd recommend either echoing the DB query to the screen or e-mailing it to yourself to debug it further.

Edited by markdh: incorrect lang selected

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.