I am very new to PHP/MySQL and I don't know the best toolset or how to properly debug.
Here is the code snippet I'm working on. I have two main issues.
1: I'm noticing that escape sequences are not working. All of the \n are ignored in the page display.
2: My code is not entering the while loop, and therefore not displaying the result. When I run the same query on phpMyAdmin, I get one result.
This is the output:
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";
?>
Adding html for the form:
<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>
Any advice would be super helpful.