HI
I'm working with a php script and connecting via PDO to a database
My php file retrieves all data from datebase when I selected one radio button for example 2GB usb driver.
This is my html code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>form php pdo</title>
</head>
<body>
<h3>Choose capacity for USB flash driver:</h3>
<form action="1php.php" method="post">
2GB
<input type="radio" name="programming[]" value="2GB"><br>
4GB
<input type="radio" name="programming[]" value="4GB"><br>
8GB
<input type="radio" name="programming[]" value="8GB"><br>
16GB
<input type="radio" name="programming[]" value="16GB"><br>
32GB
<input type="radio" name="programming[]" value="32GB"><br>
<input type="submit" name="submit" value="Submit"><br>
</form>
</body>
</html>
And this is my php file
<?php
/*if(isset($_POST['programming'])){
echo "<h4>You Selected:</h4>";
echo "<ul>";
foreach ($_POST['programming'] as $value) {
echo "<li>$value</li>", " usb flash driver. ";
}
echo "</ul>";
}
echo "<br />";*/
echo "<html><body>";
$dsn = 'mysql:host=localhost;dbname=usb;charset=UTF8';
$dbuser = 'root';
$dbpass = '';
$DBH = null;
$usb_flash_driver= "usb_flash_driver";
try{
# a DB Handler to manage the database connection
$DBH = new PDO($dsn, $dbuser, $dbpass);
# SQL query
$sql = 'SELECT * FROM ' . $usb_flash_driver;
# STH means "Statement Handle"
$STH = $DBH->query($sql);
# setting the fetch mode (array indexed by column name)
$STH->setFetchMode(PDO::FETCH_ASSOC);
//echo $STH->columnCount(), $STH->rowCount(), "<br />";
while($row = $STH->fetch()) {
echo "You are selected :<br />";
echo "{$row['name']} {$row['capacity(GB)']} {$row['image']} {$row['description']} {$row['price']}<br />";
}
# close the connection
$DBH = null;
}
catch (PDOException $e){
echo '<b>PDOException: </b>', $e->getMessage();
die();
}
echo "</body></html>";
?>
I’m new to pdo I will be thankful for your help