How to connect to phpmyadmin localhost database from microsoft web expression 4

129 views Asked by At

How to connect to the database it keeps saying

Fatal error: Uncaught Error: Class "msqli" not found in C:\xampp\htdocs\5Dec2021\Order.php:90 Stack trace: #0 {main} thrown in C:\xampp\htdocs\5Dec2021\Order.php on line 90 It works fine when I go to the http://localhost/5Dec2021/Menu.html I can click on the buttons and answer the textboxes Herebut after i submit it become like This

THIS IS MY HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
<form method="post" action="Order.php">







    <table border="1" style="width: 100%">
        <tr>
            <th colspan="2" style="height: 25px">Pizza Shop 2.0</th>            
        </tr>
        <tr>
            <td style="width: 310px">Name:</td>
            <td>
            <input name="Text1" id="Name" type="text" style="width: 299px" /></td>
        </tr>
        <tr>
            <td style="width: 310px">Pizza Topping:</td>
            <td><input name="Checkbox1[]" type="checkbox" id="supreme"value="Supreme" />Supreme<br>
                <input name="Checkbox1[]" type="checkbox" id="vegetarian" value="Vegetarian" />Vegetarian<br>
                <input name="Checkbox1[]" type="checkbox" id="haiwaian" value="Haiwaian" />Haiwaian
            </td>           
        </tr>
        <tr>
            <td style="width: 310px">Pizza Sauce:</td>
            <td><select name="Select1" id="dropdown" style="width: 296px">
                <option selected="selected" value="0">-</option>
                <option value="Ketchup">Ketchup</option>
                <option value="Bolognese">Bolognese</option>
                <option value="CheeseSpread">Cheese Spread</option>
            </select></td>
        </tr>
        <tr>
            <td style="height: 23px; width: 310px;">Optional Extra:</td>
            <td style="height: 23px">
            <input name="Checkbox2[]" type="checkbox" id="extra" value="Extra cheese" />Extra Cheese <br> 
            <input name="Checkbox2[]" type="checkbox" id="gluten" value="Gluten free base" />Gluten Free Base
            </td>
        </tr>
        <tr>
            <td style="width: 310px" colspan="2">Delivery Instruction:<br>
            <textarea name="TextArea1" style="width: 608px; height: 127px"></textarea></td>
        </tr>
        <tr>
            <td style="width: 310px" colspan="2"><input name="submit" type="submit" value="submit" /></td>
        </tr>
    </table>







</form>


</body>

</html>

THIS IS MY PHP

<?php 
//variable declaration
$name=$_POST['Text1'];
$p=0;
$p2=0;

if (isset($_POST['Checkbox1']))
{
    $top=$_POST['Checkbox1'];
    $c=count($top);
    
    for ($i=0; $i<$c;$i++)
    {
        If($top[$i]=="Supreme")
        {
            $p=$p+15;
        }
        If($top[$i]=="Vegetarian")
        {
            $p=$p+11;
        }
        If($top[$i]=="Haiwaian")
        {
            $p=$p+12;
        }
                
    }       

}

if (isset($_POST['Select1']))
{
    $sauce=$_POST['Select1'];
    
        If($sauce=="0")
        {
            $p2=$p2+0;
        }   
        If($sauce=="Ketchup")
        {
            $p2=$p2+4;
        }
        If($sauce=="Bolognese")
        {
            $p2=$p2+3;
        }
        If($sauce=="CheeseSpread")
        {
            $p2=$p2+5;
        }
                            
}

$p3=0;

if (isset($_POST['Checkbox2']))
{
    $extra=$_POST['Checkbox2'];
    $c=count($extra);
    
    for ($i=0; $i<$c; $i++)
    {
        If($extra[$i]=="Extra cheese")
        {
            $p3=$p3+10;
        }
        If($extra[$i]=="Gluten free base")
        {
            $p3=$p3+5;
        }
                                
    }       

}
$delivery =$_POST['TextArea1'];
$total=0;
$total=$p+$p2+$p3;
$top=implode(" ",$_POST['Checkbox1']); // HAVE TO IMPLODE IF CAN BE MULTIPLE VALUES.
$extra=implode(" ",$_POST['Checkbox2']);
date_default_timezone_set("Asia/Kuala_Lumpur");
$date=date("d-m-Y H:i:sa");

echo "<h1>Billing statement</h1>";
echo "<br>";
echo "Hi ".$name;
echo "<br>";
echo "Total bill RM: ".$total;

//database configuration (pizzatime is the folder of the table name)
$con= new msqli("localhost","root","","pizzatime");
//is the connection working? connection error
if($con->connect_error)
{
    die("Warning!Connection Failed!".$con->connect_error);
}

//if connection is ok (orderpizza is the table name, and INSERT INTO IS THE COLUMN NAMES WHILE THE VALUES ARE THE CONTAINERS OF THE BUTTONS/CHECKBOX/... 
$database="INSERT INTO orderpizza(Time,Name,Top,Sauce,Extra,Delivery,Total) VALUES
('$date','$name','$top','$sauce','$extra','$delivery','$total')";

if($con->query($database)===TRUE)
{
    echo "<br>";
    echo "<alert>'Successfully save into the database'</alert>;";
}
else
{
    echo "Error".$con->connect_error;
}

$con->close();

?>

This is database I created in localhost phpmyadmin

1

There are 1 answers

0
Resshantan Morgan On

I had to change my Xampp port to 4306 because it wasn't working so I have to add :4306 next to the localhost

//database configuration (pizzatime is the folder of the table name)
$con = new msqli("localhost**:4306**","root","","pizzatime");