gpt4 book ai didi

php - 调试 PHP/MySQL

转载 作者:行者123 更新时间:2023-11-27 22:36:54 24 4
gpt4 key购买 nike

我是 PHP/MySQL 的新手,我不知道最好的工具集或如何正确调试。

这是我正在处理的代码片段。我有两个主要问题。

1:我注意到转义序列不起作用。在页面显示中将忽略所有\n。

2:我的代码没有进入 while 循环,因此没有显示结果。当我在 phpMyAdmin 上运行相同的查询时,我得到了一个结果。

这是输出:

I'm in your db!echoinside postWe have a result table exists name: outside post

<?php
$mysqli = new mysqli("****", "*****", "******", "******");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo "I'm in your db!";
echo "echo";
if( $_POST["submit"] ) {
echo "inside post";
if (!($stmt = $mysqli->prepare("SELECT Cust_name FROM SERVICE_TICKET WHERE Ticket_num=?"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
if (!$stmt->bind_param("i", $_POST['ticket'])) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->bind_result($Cust_name)) {
echo "Binding output parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
else {
echo "We have a result";
echo "<table><br/>";
echo "table exists";
printf("<br/>\n\n\n\n\nname: %s", $Cust_name);
while ($stmt->fetch()){
echo "in while loop";
echo "<tr>\n<td>".$Cust_name."</td>\n</tr>";
}
echo "</table>";
}

}
echo "outside post";
?>

为表单添加 html:

<head>
<title>Bicycle Store Service Ticket</title>
<link rel="stylesheet" type="text/css" href="web.css" />
</head>
<body>
<h1>ACME BICYCLE SHOP</h1>
<h3 align="center">GET IN GEAR!</h3>

<form action="search_service.php" method="post">
<h3>CHECK A SERVICE TICKET</h3>

<h4>Ticket Number: <input type="text" ticket="ticket">&nbsp;&nbsp;

<input type="submit" name="submit" value="Search">
</form>

<p><a href="index.html">HOME</a></p>
</body>
</html>

任何建议都会非常有帮助。

最佳答案

问题 #1:转义序列可以工作,但在 HTML 中换行符是“无关紧要的空白”,因此不会显示。您可以使用 <br> 添加换行符标签。

问题 #2: 看起来您的查询返回了一个空结果集(没有指定编号的工单),因此第一次调用 $stmt->fetch()返回 false。

编辑:在您的 HTML 中输入“ticket”的行应该如下所示:

<h4>Ticket Number: </h4><input type="text" name="ticket">&nbsp;&nbsp;

所以是name="ticket"而不是 ticket="ticket" , 和 <h4>标签应该关闭。

关于php - 调试 PHP/MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13444986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com