Question

1.5 Mark Question I wo You have the following two tables in a MySQL database called it230 order statuses user PK int(11) varchar(30) PK varchar(32) varchar(32) user name You also have the following track.php page that allows a user to enter an order chtnl> <body> cforn action-track.php method-post Please enter your order number to track the status of your order cinput type-text nane-order_nunber>br> cinput type-subnit value-Track <fon> c/body </html> <?php if isset(S POST order_number1)) Sconn- mysqli connect( localhost, root, it23e) POST[order_nunber qSELECT status FROM arder statuses HERE order_nuber- Sresult nysqli query(sconn, $sql); If (mysqli-num-rows($result) > ?)( ro ysqli fetch assac(Sresult) echo Your order is: .Sron status1: else ( echo We apologize, your order was not found nysqli close($conn); 2> number and then connects to the database to return the status of that order Suppose that a user types the following into the order number field in the page 1. What will happen? [0.25 mark] 2. What do we call this type of attack? [0.25 mark] 3.Re-write track.php so, it prevents this attack. [1 mark] 1 union select concat(user_name password) as status from users;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. present database dump will cometo web page.

2.SQL Injection.

3.To avoid the sql injection attack use the prepared statements instead of normal query.....find code snippet of track .php under below.....

<?php
if(isset($_POST["ordernumber"])){
$ordernumber = $_POST["ordernumber"];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "it230";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $conn->prepare("SELECT status FROM order_statuses WHERE order_number=?");
$stmt->bind_param("s", $ordernumber);
$stmt->execute();
$result = $stmt->get_result();
if($result->num_rows === 0) {
echo "we apologize,your order was not found";
}
else{
$row = $result->fetch_assoc();
echo "your order is : ".$row['status'];
}

$stmt->close();
$conn->close();
?>

Add a comment
Know the answer?
Add Answer to:
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT