<?php
session_start();
include("connect.php");

$poNo= $_POST['poNo'];
$supName= $_POST['supName'];
$poDate = $_POST['poDate'];
if($_POST["Submit"] == "Submit")
{
if($supName!=""){
$result2 = mysql_query("SELECT supID From supplier WHERE supName = '$supName'");

$num_results = mysql_num_rows($result2);

if($num_results!=1){
echo "<script language='javascript'>alert('Please enter a valid supplier.')</script>";
echo "<script language='javascript'>window.location='addpo.php?po=$poNo'</script>";
}else{
$row = mysql_fetch_array($result2);

$supID = $row['supID'];

	$result = mysql_query("INSERT INTO purchaseorder(poNo, supID, supName, poDate)VALUES('$poNo', '$supID', '$supName', '$poDate')");
	
	
	$db = mysql_close();
	echo "<script language='javascript'>window.location='addstock.php?po=$poNo'</script>";
}
}else{
echo "<script language='javascript'>alert('Please select a supplier.')</script>";
echo "<script language='javascript'>window.location='addpo.php?po=$poNo'</script>";
}
}	
?>