I have a database with 3 tables (location,holidays and category)
I can insert the data in to holidays table but locationID and catID are NULL how can I insert the other information in locationID, locationName, country in Location table and catID, catDesc in Category table
I guess that I need to split the String in the (option value='..') and save it in 2/3 different variables and then to insert them in the tables but i don't know how.
Thanks
<?php
include 'database_conn.php';
$holidayTitle=$_POST['holidayTitle'];
$holidayDuration=$_POST['holidayDuration'];
$holidayPrice=$_POST['holidayPrice'];
$locationName=$_POST['locationName'];
$catDesc=$_POST['catDesc'];
if(isset($_POST['submit'])) {
$sql = "INSERT INTO PCH_holidays(holidayTitle, holidayDuration, holidayPrice)
VALUES ('$holidayTitle', '$holidayDuration', '$holidayPrice');";
$sql .= "INSERT INTO PCH_location (locationID)
VALUES ('$locationName');";
$sql .= "INSERT INTO PCH_category (catID)
VALUES ('$catDesc')";
if ($dbConn->multi_query($sql) === TRUE) {
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . $dbConn->error;
}
}
$dbConn->close();
?>
<form action="admin.php" method="POST">
<input type="text" name="holidayTitle" placeholder="Title">
<br>
<input type="text" name="holidayDuration" placeholder="Duration">
<br>
<input type="text" name="holidayPrice" placeholder="Price">
<br>
<select name="locationName">
<option value='l1, Milaidhoo Island, Maldives'>Milaidhoo Island, Maldives</option>
<option value='l2, Rangali Island, Maldives'>Rangali Island, Maldives</option>
<option value='l3, Zanzibar, Tanzania'>Zanzibar, Tanzania</option>
<option value='l4', Boston, USA>Boston, USA</option>
<option value='l5, San Francisco, USA'>San Francisco, USA</option>
<option value='l6, Nairobi, Kenya'>Nairobi, Kenya</option>
<option value='l7, Algarve, Portugal'>Algarve, Portugal</option>
<option value='l8, New York, USA'>New York, USA</option>
<option value='l9, Sorrento, Italy'>Sorrento, Italy</option>
<option value='l10, Verona, Italy'>Verona, Italy</option>
</select>
<br>
<select name="catDesc" >
<option value='c1,Luxury'>>Luxury</option>
<option value='c2,Tour'>Tour</option>
<option value='c3,Safari'>Safari</option>
<option value='c4,Golf'>Golf</option>
<option value='c5,Weddings'>Weddings</option>
<option value='c6,Walking'>Walking</option>
<option value='c7,Opera'>Opera</option>
</select>
<br>
<input type="submit" name="submit" value="send info">
</form>