How can I go to the next textbox when I press enter using pdo php? I need someone to help me to check my PHP coding. My database name is testphp_db, my table name is 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>
When i insert number on my Barcode textbox and press enter, it will show the Detail of the product. My problem is the cursor for typing is disappear and it cannot go to Quantity textbox.