Form not sending through to Feenix MySQL - php

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ShipOnline System</title>
</head>
<body>
<h1>ShipOnline System Request Page</h1>
<form method="post" action="request.php">
<fieldset>
<fieldset>
<legend>Item Information:</legend>
<p><label for="description">Description:</label>
<input type="text" name= "description" id="description" maxlength="100" size="20" required="required"/></p>
<p><label for="weight">Weight (kg):</label>
<select name="weight" id="weight" required="required">
<option value="">Please Select</option>
<option value="weight">0-2</option>
<option value="weight">3</option>
<option value='weight'>4</option>
<option value='weight'>5</option>
<option value='weight'>6</option>
<option value='weight'>7</option>
<option value='weight'>8</option>
<option value='weight'>9</option>
<option value='weight'>10</option>
<option value='weight'>11</option>
<option value='weight'>12</option>
<option value='weight'>13</option>
<option value='weight'>14</option>
<option value='weight'>15</option>
<option value='weight'>16</option>
<option value='weight'>17</option>
<option value='weight'>18</option>
<option value='weight'>19</option>
<option value='weight'>20</option>
</select></p>
</fieldset>
<fieldset>
<legend>Pick-up Information:</legend>
<p><label for="pickupAddress">Street Address:</label>
<input type="text" name= "pickupAddress" id="pickupAddress" maxlength="40" size="30" required="required"/></p>
<p><label for="pickupSuburb">Suburb:</label>
<input type="text" name= "pickupSuburb" id="pickupSuburb" maxlength="40" size="20" required="required"/></p>
<p><label for="date">Preferred date:</label>
<select name="day" id="date" required="required">
<option value="">Day</option>
<option value="day">1</option>
<option value="day">2</option>
<option value="day">3</option>
<option value='day'>4</option>
<option value='day'>5</option>
<option value='day'>6</option>
<option value='day'>7</option>
<option value='day'>8</option>
<option value='day'>9</option>
<option value='day'>10</option>
<option value='day'>11</option>
<option value='day'>12</option>
<option value='day'>13</option>
<option value='day'>14</option>
<option value='day'>15</option>
<option value='day'>16</option>
<option value='day'>17</option>
<option value='day'>18</option>
<option value='day'>19</option>
<option value='day'>20</option>
<option value='day'>21</option>
<option value='day'>22</option>
<option value='day'>23</option>
<option value='day'>24</option>
<option value='day'>25</option>
<option value='day'>26</option>
<option value='day'>27</option>
<option value='day'>28</option>
<option value='day'>29</option>
<option value='day'>30</option>
<option value='day'>31</option>
</select>
<select name="month" id="date" required="required">
<option value="">Month</option>
<option value='month'>1</option>
<option value='month'>2</option>
<option value='month'>3</option>
<option value='month'>4</option>
<option value='month'>5</option>
<option value='month'>6</option>
<option value='month'>7</option>
<option value='month'>8</option>
<option value='month'>9</option>
<option value='month'>10</option>
<option value='month'>11</option>
<option value='month'>12</option>
</select>
<select name="year" id="date" required="required">
<option value="">Year</option>
<option value='year'>2018</option>
<option value='year'>2019</option>
<option value='year'>2020</option>
<option value='year'>2021</option>
</select></p>
<p><label for="time">Prefered time:</label>
<select name="time" id="time" required="required">
<option value="">Please Select</option>
<option value="time">7:30-8:30</option>
<option value="time">8:30-9:30</option>
<option value="time">9:30-10:30</option>
<option value="time">10:30-11:30</option>
<option value="time">11:30-12:30</option>
<option value="time">12:30-13:30</option>
<option value="time">13:30-14:30</option>
<option value="time">14:30-15:30</option>
<option value="time">15:30-16:30</option>
<option value="time">16:30-17:30</option>
<option value="time">17:30-18:30</option>
<option value="time">18:30-19:30</option>
<option value="time">19:30-20:30</option>
</select></p>
</fieldset>
<fieldset>
<legend>Delivery Information:</legend>
<p><label for="receiver">Receiver Name:</label>
<input type="text" name= "receiver" id="receiver" maxlength="40" size="20" pattern="^[a-zA-Z ]+$" required="required"/></p>
<p><label for="deliveryAddress">Street Address:</label>
<input type="text" name= "deliveryAddress" id="deliveryAddress" maxlength="40" size="30" required="required"/></p>
<p><label for="deliverySuburb">Suburb:</label>
<input type="text" name= "deliverySuburb" id="deliverySuburb" maxlength="40" size="20" required="required"/></p>
<p><label for="state">State:</label>
<select name="state" id="state" required="required">
<option value="">Please Select</option>
<option value="state">VIC</option>
<option value="state">NSW</option>
<option value="state">QLD</option>
<option value="state">NT</option>
<option value="state">WA</option>
<option value="state">SA</option>
<option value="state">TAS</option>
<option value="state">ACT</option>
</select></p>
</fieldset>
<br/>
<input type= "submit" value="Request"/>
</fieldset>
</form>
<p>Home</p>
</body>
</html>
PHP:
<?php
require_once ("settings.php"); //connection info
$conn = #mysqli_connect($host,
$user,
$pwd,
$sql_db
);
$requestID = trim($_POST["requestID"]);
$customerID = trim($_POST["customerID"]);
$requestDate = trim($_POST["requestDate"]);
$description = trim($_POST["description"]);
$weight = trim($_POST["weight"]);
$pickupAddress = trim($_POST["pickupAddress"]);
$pickupSuburb = trim($_POST["pickupSuburb"]);
$date = trim($_POST["date"]);
$time = trim($_POST["time"]);
$receiver = trim($_POST["receiver"]);
$deliveryAddress = trim($_POST["deliveryAddress"]);
$deliverySuburb = trim($_POST["deliverySuburb"]);
$state = trim($_POST["state"]);
$sql_table="Request";
$query = "insert into $sql_table (description, weight, pickupAddress, pickupSuburb, date, time, receiver, deliveryAddress, deliverySuburb, state) values ('$description', '$weight', '$pickupAddress', '$pickupSuburb', '$date', '$time', '$receiver', '$deliveryAddress', '$deliverySuburb', '$state')";
//execute the query -we should really check to see if the batabase exists first.
$result = mysqli_query($conn, $query);
//checks if the exeution was succcessful
if (!$result) {
echo "<p class=\"wrong\">Something is wrong with your request please go back and check your details</p>";
// would not show in a production script
} else {
// display an operation successful message
echo "<p class=\"ok\">Thank you! Your request number is requestID. The cost is <cost>. We will pick-up the item at $time on $date.</p>";
} // if successful query operation
// close the database connection
mysqli_close($conn);
// if successful database connection
?>
I have a similar PHP document to this one which works perfectly. I believe the that I keep getting the message "Something is wrong with your request please go back and check your details" because of the 'date', 'time' or the drop boxes which are 'weight' and 'state' but I tried removing them and nothing changed I kept getting that there was something wrong. I can't seem to figure out what is causing the form to not successfully send. Could someone please try and find the error?

Related

Hide and show HTML Select Options

I'm writing a registration page in with PHP:
<form action="" method="post">
<input type="text" id="lname" name="fname" placeholder="First Name" required>
<input style='margin:8px;'type="text" id="fname" name="lname" placeholder="Last Name" required>
<br>
<br>
<input type="emailtext" id="email" name="email" placeholder="Email Address" required>
<br>
<div class="selectdiv" required>
<p class="boldlabel">I am a</p>
<input type="radio" id="tutor" name="tutororstudent" value="tutor" required>
<label for="tutor">Tutor</label><br>
<input type="radio" id="student" name="tutororstudent" value="student">
<label for="student">Student</label><br>
<div class="innerdiv">
<p class="boldlabel">Grade level</p>
<select name="grade">
<option value="1">1st Grade</option>
<option value="2">2nd Grade</option>
<option value="3">3rd Grade</option>
<option value="4">4th grade</option>
<option value="5">5th Grade</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th grade</option>
<option value="13">Undergrad/grad</option>
<option value="14">Post College</option>
</select>
</div>
</div>
<input style='margin:16px;'type="password" id="pwd" name="pwd" placeholder="Password" required>
<input type="submit" value="Register">
</form>
I want the div "innerdiv" to only show up if the user selects the student radio button. How do I do this in PHP? How do I hide it until the user selects the student radio button?
You only can achieve that using javascript:
add id to your innerdiv.
<div class="innerdiv" id="innerdiv" style="display:none">
<p class="boldlabel">Grade level</p>
<select name="grade">
<option value="1">1st Grade</option>
<option value="2">2nd Grade</option>
<option value="3">3rd Grade</option>
<option value="4">4th grade</option>
<option value="5">5th Grade</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th grade</option>
<option value="13">Undergrad/grad</option>
<option value="14">Post College</option>
</select>
</div>
bottom of your page, put this:
<script>
let student = document.getElementById('student');
student.addEventListener('click', display);
let tutor = document.getElementById('tutor');
tutor.addEventListener('click', () => div.style.display = "none");
let div = document.getElementById('innerdiv');
function display(){
if(student.checked) {
div.style.display = "block";
}
}
</script>

How to process and submit form data to a different web page with PHP?

I am setting up a web page that outputs the form data that has been input from a different page, and I'm having trouble getting that data to process and submit. I want the second web page to have the output outlined in the HTML code below. The first section of HTML is the first page known as reservations.html and I want to submit to the contactform.php page.
<form class="reservation-form" action="contactform.php" method="post" ng-submit="processForm()">
<fieldset>
<legend>Contact Information</legend>
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" class="form-control" ng-model="formData.firstname" ><br><br>
<label for="middlename">Middle Name:</label>
<input type="text" id="middlename" name="middlename" class="form-control" ng-model="formData.middlename"><br><br>
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" class="form-control" ng-model="formData.lastname"><br><br>
<label for="phone"> Phone Number: </label>
<input type="tel" name="phone" class="form-control" ng-model="formData.phone"><br><br>
<label for="email">Email Address: </label>
<input type="email" name="email" class="form-control" ng-model="formData.email"><br><br>
</fieldset>
<fieldset>
<legend>Travel Information</legend>
<label for="locations">Current Locations:</label>
<select name="locations" id="locations" onchange="activites('locations', 'activitiesList')" ng-model="formData.locations">
<option value="australia">Brisbane</option>
<option value="canada">Vancouver</option>
<option value="newyork">New York City</option>
<option value="germany">Berlin</option>
<option value="mexico">Cancun</option>
</select><br><br>
<label for="depart-date">Departure Date: </label>
<input type="date" name="depart-date" id="depart-date" ng-model="formData.departuredate"><br><br>
<label for="return-date">Return Date: </label>
<input type="date" name="return-date" id="return-date" ng-model="formData.returndate"><br><br>
<label for="needed">Options</label><br>
<input type="checkbox" name="needed" value="flight" ng-model="formData.flight"> Flight<br>
<input type="checkbox" name="needed" value="hotel" ng-model="formData.hotel"> Hotel<br>
<input type="checkbox" name="needed" value="car" ng-model="formData.car"> Rental Car<br><br>
</fieldset>
<div id="activities" class="">
<label class="">Choose an Activity</label>
<select id="activitiesList" name="activities" ng-model="formData.activities">
</select>
</div>
<fieldset>
<legend>Billing Information</legend>
<label for="line1">Address Line 1:</label>
<input type="text" id="line1" name="line1" ng-model="formData.line1"><br><br>
<label for="line2">Address Line 2:</label>
<input type="text" id="line2" name="line2" ng-model="formData.line2"><br><br>
<label for="city">City: </label>
<input type="text" name="city" ng-model="formData.city"><br><br>
<label for="state">State: </label>
<select name="state" id="state" ng-model="formData.state">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District Of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select><br><br>
<label for="zip">Zip Code: </label>
<input type="text" name="zip" id="zip" ng-model="formData.zip"><br><br>
</fieldset>
<button ng-click="submit()" style="color:black;font-size:1em;">
<b>Submit</b>
</button><br><br>
<button ng-click="reset()" style="color:black;font-size:1em;">
<b>Reset</b>
</button><br><br>
</form>
<?php
if (isset($_POST['submit'])) {
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$locations = $_POST["locations"];
$depart = $_POST["depart-date"];
$return = $_POST["return-date"];
$options = $_POST["options"];
$line1 = $_POST["line1"];
$line2 = $_POST["line2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$departDB = strtotime($depart);
$returnDB = strtotime($return);
$departDB = date('Y-m-d', $departDB);
$returnDB = date('Y-m-d', $returnDB);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Form</title>
</head>
<body>
<h1>Thank You</h1>
<p>Here is the information you have submitted:</p>
<ol>
<li><em>First Name:</em> <?php echo $_POST["firstname"]?></li>
<li><em>Middle Name:</em> <?php echo $_POST["middlename"]?></li>
<li><em>Last Name:</em> <?php echo $_POST["lastname"]?></li>
<li><em>Phone Number:</em> <?php echo $_POST["phone"]?></li>
<li><em>Email:</em> <?php echo $_POST["email"]?></li>
<li><em>Location:</em> <?php echo $_POST["locations"]?></li>
<li><em>Departure Date:</em> <?php echo $_POST["depart-date"]?></li>
<li><em>Return Date:</em> <?php echo $_POST["return-date"]?></li>
<li><em>Options Selected:</em> <?php echo $_POST["options"]?></li>
<li><em>Address Line 1:</em> <?php echo $_POST["line1"]?></li>
<li><em>Address Line 2:</em> <?php echo $_POST["line2"]?></li>
<li><em>City:</em> <?php echo $_POST["city"]?></li>
<li><em>State:</em> <?php echo $_POST["state"]?></li>
<li><em>Zip Code:</em> <?php echo $_POST["zip"]?></li>
</ol>
</body>
</html>
There is no form tag AND Submit button
<form method="POST" action="">
...
<input type="text" name="firstname" value="">
.. And all other fields ..
...
<input type="submit" name="submit" value="send">
</form>

PHP Script adding new records, but fields are all blank

I'm utilizing an html form and php to add data to a MySQL database. I've been able to establish a connection, and have the php script add a new record to the database, however, all fields are always empty. I've looked at solutions here and elsewhere, redone my script a few times, and still come up with the same issue.
Any help would be appreciated, php is new to me.
HTML
<label for="custFirstName">First Name</label>
<input type="text" id="custFirstName" placeholder="John">
<label for="custLastName">Last Name</label>
<input type="text" id="custLastName" placeholder="Doe">
<label for="custStreet">Street Address</label>
<input type="text" id="custStreet" placeholder="1234 Cedar Street">
<label for="custCity">City</label>
<input type="text" id="custCity" placeholder="Beverly Hills">
<label for="custState">State</label>
<select id="custState">
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PA">PA</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VT">VT</option>
<option value="VA">VA</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
<label for="custZipcode">Zip Code</label>
<input type="text" id="custZipcode" placeholder="90210">
<label for="custTX">Telephone Number</label>
<input type="text" id="custTX" placeholder="555-555-5555">
<label for="custEmail">Email Address</label>
<input type="email" id="custEmail" placeholder="name#example.com">
<button type="submit" name="submit">Submit</button>
</form>
PHP
<?php
$con = mysqli_connect('localhost','root','');
if(!con) {
echo 'Error: Not connected to the server.';
}
if(!mysqli_select_db($con,'dBaseName')) {
echo 'Error: Database is not selected';
}
if(isset($_POST['submit'])) {
$custFirstName = $_POST['custFirstName'];
$custLastName = $_POST['custLastName'];
$custStreet = $_POST['custStreet'];
$custCity = $_POST['custCity'];
$custState = $_POST['custState'];
$custZipcode = $_POST['custZipcode'];
$custTX = $_POST['custTX'];
$custEmail = $_POST['custEmail'];
$sql = "INSERT INTO Customer (custFirstName,custLastName,custStreet,custCity,custState,custZipcode,custTX,custEmail) VALUES ('$custFirstName','$custLastName','$custStreet','$custCity','$custState','$custZipcode','$custTX','$custEmail')";
if(!mysqli_query($con,$sql)) {
echo 'Error: There was a problem adding the record to the database.';
}
else {
echo 'Your information was successfully added to the database.';
}
}
header("refresh:2; url=http://www.success.html");
?>
You are using wrong tags, instead of id you need to use name. For example:
<input type="text" id="custZipcode" name="custZipcode" placeholder="90210">
You need to use "name" attribute in all your input and select tag, e.g:
<input type="text" name="custFirstName" id="custFirstName" placeholder="John">
Thanks

How should I make the php script for a contact form from multiple select dependencies

Before anyone yells Repost, there aren't many cases like mine that I've seen.I have a contact form that has the possibility to have a main Select option, a sub-Select option and then a sub-Select option of that one. Overall, There are 27 options to choose from and I think I could make the php give me all 27 of those and then do a "yes they selected this one but not that one" type of report, but I digress.How do I have the php script for my contact form send only what is selected from a possible three-tiered select menu? EDIT: I'm totally willing to use something other than PHP to help facilitate this, I just need help with the PHP script as well.Edit: To be clear, I'm try to create and populate a php script, not valdiate the form/check that all required sections are filled out.Code
<form action="sending.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Name:<br>
<input name="name" type="text" value="" size="30"/><br>
Email:<br>
<input name="email" type="text" value="" size="30"/><br>
Service:<br>
<select name="service" id="service" class="service">
<option>Select a Service</option>
<option value="screen" data-target="devices" id="screen">Screen Replacement</option>
<option value="comp" data-target="comp" id="comp">Computer Work</option>
<option value="misc" data-target="misc" id="misc">Miscellaneous</option>
</select>
<div style="display:none" id="service-devices">
<select name="devices" id="devices" class="devices">
<option>Select a Device</option>
<option value="iphone" data-target="iphones" id="iphone">iPhone</option>
<option value="ipad" data-target="ipads" id="ipad">iPad</option>
<!--<option value="watch" id="watch">Apple Watch</option> -->
<option value="android" id="android">Android</option>
</select>
<div style="display:none" id="devices-iphones">
<select name="iphone" id="iphone" class="iphone">
<!--<option value="iphone6s" id="iphone6s">iPhone 6S</option> -->
<!--<option value="iphone6splus" id="iphone6splus">iPhone 6S Plus</option>-->
<option>Select a Model</option>
<option value="iphone6" id="iphone6">iPhone 6</option>
<option value="iphone6plus" id="iphone6plus">iPhone 6 Plus</option>
<option value="iphone5s" id="iphone5s">iPhone 5S</option>
<option value="iphone5c" id="iphone5c">iPhone 5C</option>
<option value="iphone5" id="iphone5">iPhone 5</option>
<option value="iphone4s" id="iphone4s">iPhone 4S</option>
<option value="iphone4" id="iphone4">iPhone 4</option>
</select>
</div>
<div style="display:none" id="devices-ipads">
<select name="ipad" id="ipad" class="ipad">
<option>Select a Model</option>
<option value="ipadmini3" id="ipadmini3">iPad Mini 3</option>
<option value="ipadmini2" id="ipadmini2">iPad Mini 2</option>
<option value="ipadair" id="ipadair">iPad Air</option>
<option value="ipad4" id="ipad4">iPad 4</option>
<option value="ipad3" id="ipad3">iPad 3</option>
<option value="ipadmini" id="ipadmini">iPad Mini</option>
<option value="ipad2" id="ipad2">iPad 2</option>
</select>
</div>
</div>
<div style="display:none" id="service-comp">
<select name="compwork" id="compwork" class="compwork">
<option value="desktopcreation" id="desktopcreation">Desktop Creation</option>
<option value="desktopbuild" id="desktopbuild">Desktop Build</option>
<option value="hardwareupgrades" id="hardwareupgrades">Hardware Upgrades</option>
<option value="datarecovery" id="datarecovery">Data Recovery/Transfer</option>
<option value="spywareremoval" id="spywareremoval">Spyware/Adware Removal</option>
<option value="virusremoval" id="virusremoval">Virus Removal</option>
</select>
</div>
<div style="display:none" id="service-misc">
<select name="miscellaneous" id="miscellaneous" class="miscellaneous">
<option value="networksecurity" id="networksecurity">Network Security</option>
<!--<option value="webdesign" id="webdesign">Website Design</option>-->
</select>
</div><br>
Message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Submit Request"/>
</form>
I assume that you do have jquery to display the relevant select boxes upon selection of devices etc... I have made a few changes in your html form, like adding id="form" in your form tag. Also added value="" for options like "Please select Service".. Here is the code. Hope this helps.. Refer to this as well..
Jquery form submit to check empty fields
<form id="form" action="sending.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
Name:<br>
<input name="name" type="text" value="" size="30"/><br>
Email:<br>
<input name="email" type="text" value="" size="30"/><br>
Service:<br>
<select name="service" id="service" class="service">
<option value="">Select a Service</option>
<option value="screen" data-target="devices" id="screen">Screen Replacement</option>
<option value="comp" data-target="comp" id="comp">Computer Work</option>
<option value="misc" data-target="misc" id="misc">Miscellaneous</option>
</select>
<div style="display:none" id="service-devices">
<select name="devices" id="devices" class="devices">
<option value="">Select a Device</option>
<option value="iphone" data-target="iphones" id="iphone">iPhone</option>
<option value="ipad" data-target="ipads" id="ipad">iPad</option>
<!--<option value="watch" id="watch">Apple Watch</option> -->
<option value="android" id="android">Android</option>
</select>
<div style="display:none" id="devices-iphones">
<select name="iphone" id="iphone" class="iphone">
<!--<option value="iphone6s" id="iphone6s">iPhone 6S</option> -->
<!--<option value="iphone6splus" id="iphone6splus">iPhone 6S Plus</option>-->
<option value="">Select a Model</option>
<option value="iphone6" id="iphone6">iPhone 6</option>
<option value="iphone6plus" id="iphone6plus">iPhone 6 Plus</option>
<option value="iphone5s" id="iphone5s">iPhone 5S</option>
<option value="iphone5c" id="iphone5c">iPhone 5C</option>
<option value="iphone5" id="iphone5">iPhone 5</option>
<option value="iphone4s" id="iphone4s">iPhone 4S</option>
<option value="iphone4" id="iphone4">iPhone 4</option>
</select>
</div>
<div style="display:none" id="devices-ipads">
<select name="ipad" id="ipad" class="ipad">
<option value="">Select a Model</option>
<option value="ipadmini3" id="ipadmini3">iPad Mini 3</option>
<option value="ipadmini2" id="ipadmini2">iPad Mini 2</option>
<option value="ipadair" id="ipadair">iPad Air</option>
<option value="ipad4" id="ipad4">iPad 4</option>
<option value="ipad3" id="ipad3">iPad 3</option>
<option value="ipadmini" id="ipadmini">iPad Mini</option>
<option value="ipad2" id="ipad2">iPad 2</option>
</select>
</div>
</div>
<div style="display:none" id="service-comp">
<select name="compwork" id="compwork" class="compwork">
<option value="desktopcreation" id="desktopcreation">Desktop Creation</option>
<option value="desktopbuild" id="desktopbuild">Desktop Build</option>
<option value="hardwareupgrades" id="hardwareupgrades">Hardware Upgrades</option>
<option value="datarecovery" id="datarecovery">Data Recovery/Transfer</option>
<option value="spywareremoval" id="spywareremoval">Spyware/Adware Removal</option>
<option value="virusremoval" id="virusremoval">Virus Removal</option>
</select>
</div>
<div style="display:none" id="service-misc">
<select name="miscellaneous" id="miscellaneous" class="miscellaneous">
<option value="networksecurity" id="networksecurity">Network Security</option>
<!--<option value="webdesign" id="webdesign">Website Design</option>-->
</select>
</div><br>
Message:<br>
<textarea name="message" rows="7" cols="30"></textarea><br>
<input type="submit" value="Submit Request"/>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$('select').change(function(){
var boxid = $(this).children('option:selected').attr('data-target');
alert(boxid);
if(boxid == "devices") {
var divId = "service-" + boxid;
}
document.getElementById(divId).style.display = "block";
});
$("form").submit(function(){
// $(':input[value=""]').attr('disabled', true);
$("input[type='text'],select,input[type='password'],textarea",this).each(function() {
if($(this).val().trim() == "") {
$(this).attr('disabled', true);
}
})
});
});
</script>

Upload images PHP to MySQL and retrieve correct images to each form

I have to re-explain my situation they said.
my html form:
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="carform.css"/>
<head>
</head>
<body>
<form action="connection.php" method="post" class="smart-green">
<h1> Car listing
<span>Please fill all the text in the fields.</span>
</h1>
<label>
<span>Make:</span>
<select id="category">
<option value="Alfa Romeo">Alfa Romeo</option>
<option value="Aston Martin">Aston Martin</option>
<option value="Audi">Audi</option>
<option value="Austin">Austin</option>
<option value="Bentley">Bentley</option>
<option value="BMW">BMW</option>
<option value="Buddy">Buddy</option>
<option value="Buick">Buick</option>
<option value="Cadillac">Cadillac</option>
<option value="Chevrolet">Chevrolet</option>
<option value="Chrysler">Chrysler</option>
<option value="Citroen">Citroen</option>
<option value="Dacia">Dacia</option>
<option value="Daewoo">Daewoo</option>
<option value="Daihatsu">Daihatsu</option>
<option value="Dodge">Dodge</option>
<option value="Ferrari">Ferrari</option>
<option value="Fiat">Fiat</option>
<option value="Fisker">Fisker</option>
<option value="Ford">Ford</option>
<option value="GMC">GMC</option>
<option value="Honda">Honda</option>
<option value="Hummer">Hummer</option>
<option value="Hyundai">Hyundai</option>
<option value="Infiniti">Infiniti</option>
<option value="Isuzu">Isuzu</option>
<option value="Iveco">Iveco</option>
<option value="Jaguar">Jaguar</option>
<option value="Jeep">Jeep</option>
<option value="Kewet">Kewet</option>
<option value="Kia">Kia</option>
<option value="Koenigsegg">Koenigsegg</option>
<option value="Lada">Lada</option>
<option value="Lamborghini">Lamborghini</option>
<option value="Lancia">Lancia</option>
<option value="Land Rover">Land Rover</option>
<option value="Lexus">Lexus</option>
<option value="Lincoln">Lincoln</option>
<option value="Lotus">Lotus</option>
<option value="Maserati">Maserati</option>
<option value="Maybach">Maybach</option>
<option value="Mazda">Mazda</option>
<option value="McLaren">McLaren</option>
<option value="Mercedes-Benz">Mercedes-Benz</option>
<option value="Mercury">Mercury</option>
<option value="MG">MG</option>
<option value="MINI">MINI</option>
<option value="Mitsubishi">Mitsubishi</option>
<option value="Morgan">Morgan</option>
<option value="Morris">Morris</option>
<option value="Nissan">Nissan</option>
<option value="Oldsmobile">Oldsmobile</option>
<option value="Opel">Opel</option>
<option value="Peugeot">Peugeot</option>
<option value="Piaggio">Piaggio</option>
<option value="Plymouth">Plymouth</option>
<option value="Pontiac">Pontiac</option>
<option value="Porsche">Porsche</option>
<option value="Renault">Renault</option>
<option value="Reva">Reva</option>
<option value="Rolls Royce">Rolls Royce</option>
<option value="Rover">Rover</option>
<option value="Saab">Saab</option>
<option value="Seat">Seat</option>
<option value="Skoda">Skoda</option>
<option value="Smart">Smart</option>
<option value="Ssangyong">Ssangyong</option>
<option value="Subaru">Subaru</option>
<option value="Suzuki">Suzuki</option>
<option value="Tazzari">Tazzari</option>
<option value="Tesla">Tesla</option>
<option value="Think">Think</option>
<option value="Toyota">Toyota</option>
<option value="Triumph">Triumph</option>
<option value="Volkswagen">Volkswagen</option>
<option value="Volvo">Volvo</option>
<option value="Others">Others</option>
</select>
</label>
<label>
<span>Title:</span>
<input id="title" type="text" name="title">
</label>
<label>
<span>Price:</span>
<input id="price" type="text" name="price">$
</label> <label>
<span>Description:</span>
<textarea id="description" name="description" rows="20" cols="60"></textarea>
</label>
<label>
<span> </span>
<input type="button" class="button" value="Send"/>
</label>
</form>
</body>
</html>
and my php:
<?php
$con = mysqli_connect("", "", "", "");
if (mysqli_connect_errno()) {
echo "Failed to connect to mysqli: ".mysqli_connect_error();
}
$cat = mysqli_real_escape_string($con, $_POST['category']);
$tit = mysqli_real_escape_string($con, $_POST['title']);
$pri = mysqli_real_escape_string($con, $_POST['price']);
$des = mysqli_real_escape_string($con, $_POST['description']);
$sql = "INSERT INTO forsale (Category, Title, Price, Description) VALUES ('$cat', '$tit', '$pri', '$des')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
echo "1 record added";
mysqli_close($con);
?>
Now what I am missing is having uploading maximum of 12 images for this form per Id and being able to retrieve all the images that belongs to eash posting
your code if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
you are missing a closing curly brace like this, not sure if this is your onle problem but it certainly is a problem.
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));}

Categories