here order_ID ,Bill may b null,a customer dont need to fill in the form ,,,here is the php code ,,,,,it is not working.....i dont know how to insert tuple with null values into table by using php.i cant find the errors.
create table Orders(
Order_ID number(10) primary key,
Cust_id number(5),
Order_date date,
Bill number(5,2),
CONSTRAINT fk_cust FOREIGN KEY (Cust_ID) REFERENCES Customer(Cust_ID)
);
CREATE SEQUENCE ord_seq;
CREATE OR REPLACE TRIGGER table_res
BEFORE INSERT ON Orders
FOR EACH ROW
BEGIN
SELECT ord_seq.NEXTVAL INTO :new.Order_ID FROM dual;
END;
/
<?php
$conn=oci_connect("system","123","localhost/orcl");
ob_start();
$current_file=$_SERVER['SCRIPT_NAME'];
$massage= "";
if(isset($_POST['Cust_id'])&&
isset($_POST['Order_date']))
{
$Cust_id= $_POST['Cust_id'];
$Order_date = $_POST['Order_date'];
if(!empty($Cust_id)&&!empty($Order_date))
{
$sql = "insert into Orders values('".NULL."','".$Cust_id."','".$Order_date."','".NULL."')";
$stid = oci_parse($conn,$sql);
$r = @oci_execute($stid);
if($r)
{
echo ' data is inserted...<br>';
}
else
{
echo 'data was not inserted...<br>';
}
}
else
{
$massage = "please fill up all the form correctly<br>";
}
}
?>
<html>
<head>
<title>Create FoodItem Table</title>
<style>
body
{
background:orange;
}
</style>
<head>
<body>
You dont need to fill Order_ID and Bill<br><br>
<?php echo $massage;?>
<hr color="green">
<form action="<?php echo $current_file;?>" method="POST">
Cust_id:<br> <input type="text" name ="Cust_id" ><br><br>
Order_date:<br> <input type="text" name="Order_date" ><br><br>
<input type ="submit" value="Submit Order"><br><br>
//<a href="EmployeeTableshow.php">Home</a>
</form>
</body>
</html>
insert null values like this
$sql="insert into Orders values(NULL,'".$Cust_id."','".$Order_date."',NULL)";
Inserting a NULL value on your primary key is probably not what you want. Either insert a unique value for your key:
$sql = "insert into Orders values('". $someUniqueValueThatYouCreated . "','".$Cust_id."','".$Order_date."','".NULL."')";
--or--
alter your table structure with, say, an auto_increment:
Order_ID int(10) primary key auto_increment,
and then modify your insert:
$sql = "insert into Orders (Cust_id, Order_date, Bill) values('".$Cust_id."','".$Order_date."','".NULL."')";