【发布时间】:2017-12-01 06:02:42
【问题描述】:
当我使用 pdo php 按下回车键时,如何进入下一个文本框?我需要有人帮我检查我的 PHP 编码。我的数据库名是testphp_db,我的表名是users。
testphp_db.php
<?php
$dsn = 'mysql:host=localhost;dbname=testphp_db';
$username = 'root';
$password = '';
try{
//Connect To MySQL Database
$con = new PDO($dsn,$username,$password);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $ex) {
echo 'Not Connected '.$ex->getMessage();
}
$barcode = '';
$detail = '';
$quantity = '';
function getPosts()
{
$posts = array();
$posts[0] = $_POST['barcode'];
$posts[1] = $_POST['detail'];
$posts[2] = $_POST['quantity'];
return $posts;
}
//Search And Display Database
if(isset($_POST['search']))
{
$data=getPosts();
if(empty($data[0]))
{
echo 'Enter Barcode To Search';
} else {
$searchStmt=$con->prepare('SELECT * FROM users WHERE barcode = :barcode');
$searchStmt->execute(array(':barcode'=>$data[0]
));
if($searchStmt)
{
$user=$searchStmt->fetch();
if(empty($user))
{
echo 'No Data For This Barcode';
}
$barcode=$user[0];
$detail=$user[1];
$quantity=$user[2];
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP (MySQL PDO): Search</title>
</head>
<body>
<form action="testphp_db.php" method="POST">
Barcode: <input type="text" name="barcode" value="<?php echo $barcode;?>"><br><br>
<input type="submit" name="search" value="Search"><br><br>
Detail: <?php echo $detail;?><br><br>
Quantity: <input type="text" name="quantity" value="<?php echo $quantity;?>"><br><br>
</form>
</body>
</html>
当我在我的条形码文本框中插入数字并按 Enter 键时,它将显示产品的详细信息。我的问题是输入的光标消失了,它不能转到数量文本框。
【问题讨论】:
-
您需要提供您的代码,但听起来您的解决方案实际上将使用 Javascript。
-
你能帮我检查一下代码吗,我只是上传代码。