Hey guy, I want to know if there is a way of using PHP in JavaScript. I have no idea how can i get the variables from PHP into JavaScript. I am making a pizza application, the php file is a confirmation page. The user can either go back to change the data or proceed from this page. What the teacher wants the proceed button to do is to put the data into the database. I do not know if there is other way of doing this as am new to PHP and JavaScript. What i am thinking of is that when the user presses "Proceed", the button invokes the insert() method in the JavaScript and that method will insert data into the database. So, in order to do that i need to get the info from the PHP script. Kindly help Thanks
<?
echo "<div class='topMargin'><center><h1><strong>Order confirmation </strong></h2></center></div>";
$date = date("Y-m-d");
echo '<div class="margin">';
$cost=0;
$counter=0;
echo "<center>";
echo "Personal data:<br/>";
if (!isset($_POST["name"])){
echo "Name filed empty";
}else {
$name=$_POST["name"];
}
if (!isset($_POST["phoneNumber"])){
echo "Enter a phone number";
}else{
$phone=$_POST["phoneNumber"];
}
echo $name."<br/>";
echo $phone."<br/>";
echo "**********************<br/>";
echo "Address:<br/>";
if(!isset($_POST["unitNumber"])){
echo "Enter Unit number<br/>";
}else {
$unitNum=$_POST["unitNumber"];
}
if(!isset($_POST["streetName"])){
echo "Enter street name<br/>";
}else {
$streetName = $_POST["streetName"];
}
if(!isset($_POST["city"])){
echo "Enter city name<br/>";
}else {
$city = $_POST["city"];
}
if(!isset($_POST["zip"])){
echo "Enter zip code<br/>";
}else{
$zipCode = $_POST["zip"];
}
if (!isset($_POST["province"])){
echo "Enter province name<br/>";
}else {
$province=$_POST["province"];
}
echo $unitNum." ";
echo $streetName."<br/>";
echo $city.", ";
echo $zipCode." ".$province."<br/>";
if(!isset($_POST["size"])){
echo "Choose pizza size<br/>";
}else {
$pizzaSize = $_POST["size"];
}
isset($_POST["delivery"]) ? $delivery = $_POST["delivery"] : $delivery = "";
isset($_POST["box"]) ? $topping = $_POST['box'] : $topping = "";
echo "**********************<br/>";
echo "Your order:<br/>";
echo "Pizza size: ";
switch($pizzaSize){
case "Small":
echo $pizzaSize." ($5)<br/>";
break;
case "Medium":
echo $pizzaSize." ($10)<br/>";
break;
case "Large":
echo $pizzaSize." ($15)<br/>";
break;
}
if($topping!=""){
echo "<br/>Toppings:<br/>";
foreach($topping as $toppingName){
$counter++;
echo "<li>".$toppingName." ($1)<br/>";
}
echo "<br/>";
}
if($pizzaSize=="Small")
{
if($delivery=="yes")
{
$cost=5+5+$counter;
}else{
$cost=5+$counter;
}
}else if($pizzaSize=="Medium")
{
if($delivery=="yes")
{
$cost=10+5+$counter;
}else{
$cost=10+$counter;
}
}else if ($pizzaSize=="Large")
{
if($delivery=="yes")
{
$cost=15+5+$counter;
}else{
$cost=15+$counter;
}
}
if ($delivery!="yes"){
$delivery=="no";
}
if($delivery=="yes"){
echo "Home delivery ($5 extra)<br/>";
}else if ($delivery=="no"){
echo $delivery;
echo "You chose pick-up<br/>";
}
echo "*******************";
echo "<br/>Total Cost= $".$cost;
echo "<br/>*******************";
echo '</div>';
$db = mysql_connect("localhost", "root");
mysql_select_db("pizza",$db);
$query = "INSERT INTO table (id, name,number,unit,street,city,zip,province,size,toppings,delivery,date) VALUES ('',
'$name','$phone','$unitNum','$streetName','$city','$zipCode','$province','$pizzaSize','$delivery','$date')";
$result = mysql_query($query);
echo $result;
if (!$result) {
$error = "Sorry could not record score";
}else {
echo "working";
}
?>
here is my php code.
P.S. this is in a separate PHP file