<?php
#=======================================================================
# Write data to a database table
#=======================================================================
    $firstname  = readline('Enter firstname: ');          #prompt user 
    $lastname   = readline('Enter lastname: ');                
    $address    = readline('Enter your address: ');
    $flavor     = readline('Enter ice cream flavor: ');                 
    $topping    = readline('Enter ice cream topping: ');                
    $creditCard = readline('Enter your credit card: ');

//----- Write data into Database ---------------------------------------------

    $host   = 'localhost';
    $DBname = 'demo2';
    $DBuser = 'demo2';
    $DBpswd = 'demo2';
 
    try {
        $connect = mysqli_connect($host,$DBuser,$DBpswd,$DBname);   #connect to db server
    }
    catch(Exception $e) {
//      die('Could not connect: ' . $e->getMessage());            
        die('Could not connect: ' . mysqli_connect_error());
    }

    $insert = "INSERT INTO cust_order
               (order_id,firstname,lastname,address,flavor,topping,creditCard,cust_id) 
                VALUES(0,'$firstname','$lastname','$address',
                         '$flavor',   '$topping', '$creditCard', 1)";

//print($insert);                                                   #for debugging        

    $result = mysqli_query($connect, $insert);                      #issue the query                        

    if (! $result) 
        die('Could not execute insert: ' . mysqli_error($connect));
       
    mysqli_close($connect);                                         #close connection

    print "Order Processed Successfully!!! \n";

//=============================================================================

?>