1. Write a file named <lastname>4a.php. This file should create a form that send
ID: 3833328 • Letter: 1
Question
1. Write a file named <lastname>4a.php. This file should create a form that sends its action to <lastname>4b.php. The form should contain a select whose options contain values that are the sale ids, and the options should display the sale ids.
2. Write a file named <lastname>4b.php. This file should display all data for the chosen sale. This should include the saledate and the customer id.
3. Write a file named <lastname>4c.htm. This file should contain a form that sends its action to <lastname>4d.php. The form contains text fields for all fields of the SALES table except the saleid. Make sure you choose a customer id that exists (a number between 1 and 101).
4. Write a file named <lastname>4d.php. The file should then insert the new record in the SALES table.
Make sure that you upload your files into the public_html directory of your cislinux account.
Explanation / Answer
4a.php
<form action="#" method="post" Action ="4b.php" >
<select name="SalesIds">
<option value="1">SaleID1</option>
<option value="2">SaleID2</option>
<option value="3">SaleID3</option>
<option value="4">SaleID4</option>
<option value="5">SaleID5</option>
</select>
<input type="submit" name="submit" value="Select the SaleID" />
</form>
<?php
if(isset($_POST['submit'])){
$selected_val = $_POST['SalesIds']; // Storing Selected Value In Variable
echo "You have selected :" .$selected_val; // Displaying Selected Value
}
?>
4b.php
<?php
$saleId = $_POST['SalesIds'];
$usertable = "";
$database = new PDO( 'mysql:host=localhost;dbname=DB_NAME', 'DB_USER_NAME', 'DB_USER_PASS' );
$statement = $database->prepare('SELECT * FROM $usertable where sId=$saleId"');
$statement->execute();
$count = $statement->rowCount();
if( $count > 0 ) {
$R = $statement->fetchAll( PDO::FETCH_ASSOC );
for( $x = 0; $x < count($R); $x++ ) {
echo "<tr>";
echo "<td>" . $R[ $x ]['sId'] . "</td>";
echo "<td>" . $R[ $x ]['sDate'] . "</td>";
echo "<td>" . $R[ $x ]['cId'] . "</td>";
echo "</tr>";
}
}
else { echo "Error!"; }
?>
4c.php
<html>
<body>
<form action="4d.php" method="post">
Customer Id : <input type="text" name="cId">
Sales Date (MM/DD/YYYY) : <input type="text" name="sDate">
<input type="submit">
</form>
</body>
</html>
4d.php
<html>
<body>
<?php
$con = new PDO( 'mysql:host=localhost;dbname=DB_NAME', 'DB_USER_NAME', 'DB_USER_PASS' );
$usertable = "";
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$sql="INSERT INTO usertable (cId, sDate) VALUES ('$_POST[cId]','$_POST[sDate]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.