PHP - 无法拆分String并将数据保存到数据库中

I have a database with 3 tables (location,holidays and category)

This is holidays table

This is location table

This is category table

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>

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.

That's pretty much it.

To split the string into 3 variables using your post data:

list($locationID, $locationName, $country) = explode(",", $_POST['locationName']);

Then change your SQL accordingly.

INSERT INTO PCH_location (locationID, locationName, country)
    VALUES ('$locationID', '$locationName', '$country');

Repeat same thing with category table.

Note the comments you'll receive plenty about SQL security i.e. Prepared statements. The above should address your error.

If you are using drop downs for location and category, the values of the options should be the ID's of the respective options, not the description/name. IOWs, they should be numbers which you can then save directly to your holiday table. No parsing/manipulation required.

You have:

<option value='l1, Milaidhoo Island, Maldives'>Milaidhoo Island, Maldives</option>

But it should be:

<option value='1'>Milaidhoo Island, Maldives</option>

NOTE

Since you are storing the keys to the other two tables, you should not also store the text from these tables in the holiday table. If the name gets changed, you would have to do an update to the holiday table to update the descriptions. Not the best use of a relational database. Not a normalized structure.