0% found this document useful (0 votes)
16 views5 pages

If Die Else If: Mysqli

This PHP code connects to a vehicle_details database, defines a form to collect vehicle data from users, calculates a total price based on fuel type and air conditioning options, inserts the submitted data into the database, and displays the stored data in a table. It connects to MySQL, defines a form with fields for vehicle details, calculates a total cost based on options, inserts the data into a database table, and outputs the stored records in a table.

Uploaded by

Dark Mirrow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

If Die Else If: Mysqli

This PHP code connects to a vehicle_details database, defines a form to collect vehicle data from users, calculates a total price based on fuel type and air conditioning options, inserts the submitted data into the database, and displays the stored data in a table. It connects to MySQL, defines a form with fields for vehicle details, calculates a total cost based on options, inserts the data into a database table, and outputs the stored records in a table.

Uploaded by

Dark Mirrow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

<?

php
$conn = new mysqli("localhost","root","","vehicle_details");
if($conn-> connect_error){
die("connection failed :". $conn -> connection_error);
}
else
if(isset($_POST['submit'])){
$name = $_POST['name'];
$mobile_no = $_POST['mnumber'];
$email = $_POST['email'];
$address = $_POST['address'];
$fuel_type = $_POST['fuel_type'];
$vehicle_number = $_POST['vnumber'];
$With_ac = $_POST['air'];
$Total = 0;

if($fuel_type == 'petrol'&& With_ac== 'yes' ){


$Total += 10000;}
elseif ($fuel_type == 'petrol'&& With_ac== 'no'){
$Total +=6000;}

elseif ($fuel_type == 'diesel'&& With_ac== 'yes'){


$Total +=9000;}
else{
$Total +=5000;
}

$stmt = $conn-> prepare("INSERT INTO vehicle_details


VALUES('',?,?,?,?,?,?,?,?)");
$stmt->
bind_param("sissssss",$name,$mobile_no,$email,$address,$fuel_type,$vehicle_number
,$With_ac,$Total );
$stmt->execute();
echo"<script>alert('Name saved')</script>";
//echo"<script>window.location.href="new.php";</script>";

}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<style>
fieldset {background-color: blueviolet;
margin:auto;
width:50%;
border:3px solid;
padding:10px;}

body { background-color:skyblue;
alignmnet}

table { background-color:white;
font-color:pink;}

form input{background-color:yellow;}

form textarea{background-color:yellow;}

form select{background-color:yellow;}

</style>

<title>Form</title>
</head>
<body>
<fieldset ><legend> Vehicle Details</legend>
<form style="text-align:center" method="post" autocomplete="off"
action="" >

<br>
<br>
<br>
<!-- name-->

Name : <input type="text" name="name"


placeholder="Name"class="textBox" autofocus="on" required>

<!-- name-->
<br>
<br>
<br>
<!---Phone No.------>

Mobile Number : <input type="text" required name="mnumber" maxlength="10"


placeholder="Mobile Number" class="textBox">

<!---Phone No.---->
<br>
<br>
<br>
<!---Email ID---->

Email ID : <input type="email" required name="email"


placeholder="Email" class="textBox">

<!--Email ID----->

<br>
<br>
<br>
<!---Home Address------>

Home Address : <textarea cols="30" rows="4" name="address">


</textarea>

<!---Home Address------>
<br>
<br>
<br>
<!---Fuel Type------>

Fuel Type <select name="fuel_type">


<option>Petrol</option>
<option>Diesel</option>
</select>

<!---Fuel Type------>
<br>
<br>
<br>
<!---Vehicle Number------>

Vehicle Number : <input type="text" required name="vnumber"


placeholder="Vehicle Number" class="textBox">

<!---Vehicle Number------>
<br>
<br>
<br>
<!---Air Conditioning----->
Air Conditioning:
<input type="radio" name="air" value="yes" required> with
AC
<input type="radio" name="air" value="no" required> without
AC

<!---Air Conditioning--->

<br>
<br>
<br>
<!---Submit Button------>

<input type="Submit" name="submit" class="submit"


value="SUBMIT">

<!---Submit Button----->

</fieldset>
</form>

<br>
<br>
<br>
<br>
<table border="1" >
<tr>
<th> Name </th>
<th> Mobile number </th>
<th> Email </th>
<th> Home address</th>
<th> Fuel type </th>
<th> Vehicle number </th>
<th> Air condition </th>
<th> Total </th>
</tr>
<?php $i = 1;
$rows = mysqli_query($conn,"SELECT * FROM vehicle_details ORDER BY
id DESC");
foreach($rows as $row): ?>
<tr>
<td><?php echo $row["Name"];?></td>

<td><?php echo $row["Mobile_No"];?></td>


<td><?php echo $row["email"];?></td>

<td><?php echo $row["Address"];?></td>

<td><?php echo $row["Fuel_type"];?></td>

<td><?php echo $row["Vehicle_Number"];?></td>

<td><?php echo $row["with_AC"];?></td>

<td><?php echo $row["Total"];?></td>

</tr>
<?php endforeach ; ?>
</table>

</body>
</html>

You might also like