如何从 microsoft web 表达式 4 连接到 phpmyadmin localhost 数据库

Posted

技术标签:

【中文标题】如何从 microsoft web 表达式 4 连接到 phpmyadmin localhost 数据库【英文标题】:How to connect to phpmyadmin localhost database from microsoft web expression 4 【发布时间】:2022-01-14 01:31:35 【问题描述】:

如何连接到它一直说的数据库

致命错误:未捕获的错误:在 C:\xampp\htdocs\5Dec2021\Order.php:90 中找不到类“msqli”堆栈跟踪:在 C:\xampp\htdocs\5Dec2021\Order 中抛出 #0 main .php 在第 90 行 当我转到 http://localhost/5Dec2021/Menu.html 时它工作正常我可以点击按钮并回答文本框Here但在我提交后它变成This

这是我的 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>

这是我的 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

【问题讨论】:

您是否已经尝试过调用类 mysqli 而不是 msqli ? 是的,我已经用谷歌搜索并尝试了一些东西,其中 1 个正在更改为 mysqli,但它没有工作同样的错误 你的意思是说“找不到类“mysqli”? 对不起,我以为你写了我尝试过的 my_mysqli,但它应该是同样的错误,但我刚刚尝试了 mysqli,它显示imgur.com/Gp3aHwX 现在有更多错误 【参考方案1】:

我不得不将我的 Xampp 端口更改为 4306,因为它不起作用,所以我必须在 localhost 旁边添加:4306

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

【讨论】:

以上是关于如何从 microsoft web 表达式 4 连接到 phpmyadmin localhost 数据库的主要内容,如果未能解决你的问题,请参考以下文章

如何从 Microsoft.Sharepoint.Client.Web 中填充 Web 类?

从 C# 连接到 OpenOffice 数据库

如何使用节点 js/Oauth 连接到交换 Web 服务

如何使用 JetBrains DataGrip 连接到远程 Microsoft Azure 数据库

无法从 NET Core 2.2 Web API 连接到 docker sql server

如何引用 Microsoft.Web.Administration?