我对 PHP/MySQL 非常陌生,我不知道最好的工具集或如何正确调试。
这是我正在处理的代码片段。我有两个主要问题。
1:我注意到转义序列不起作用。在页面显示中忽略所有 \n。
2:我的代码没有进入while循环,因此没有显示结果。当我在 phpMyAdmin 上运行相同的查询时,我得到一个结果。
这是输出:
我在你的数据库中!echoinside post我们有一个结果表存在名称: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">
<input type="submit" name="submit" value="Search">
</form>
<p><a href="index.html">HOME</a></p>
</body>
</html>
任何建议都会非常有帮助。