2

我正在尝试创建一个订单状态页面,我将在 phpmyadmin 中手动调整,但是我希望人们能够使用表格输入他们的订单号,然后为该订单号提供适当的名称和状态。

这是 index.php

<?php
$username = "username";
$password = "password";
$hostname = "localhost"; 
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>
<form method="POST" action="action.php">
<input type="text" name="term" />
<input type="submit" value="Submit" name="submit" />
</form>

这是我的 action.php

 <?php
$username = "evo_readle";
$password = "judo08";
$hostname = "localhost"; 
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$term = mysql_real_escape_string($_REQUEST['term']);    
$query = mysql_query("SELECT * FROM orders WHERE number ='%".$term."%'");
$user = mysql_fetch_assoc($query);
echo "Hello User, your name is" .$user['name'];
?>
4

1 回答 1

1

如果要在 SQL 查询中使用通配符,则需要关键字LIKE. 所以

$query = mysql_query("SELECT * FROM orders WHERE number ='%".$term."%'");

会变成:

$query = mysql_query("SELECT * FROM orders WHERE number LIKE '%".$term."%'");

我还可以建议您开始了解为什么不使用mysql_*函数吗?阅读这篇文章

于 2013-01-18T10:59:31.410 回答