I've been altering code back and forth for an hour or so to get my form to send data to a mysql database if a radio button is checked. Right now it is not filling the table. other tables are getting populated.

Here is the part of the html of the form I cannot get to populate

<p><strong>Monday</strong><input type="radio" name="monday" value="monday"/><br/>
<strong>Start Time (HH:MM): </strong>
<select name="mon_start_hour">
	<option value="12">12</option>
	<option value="01">01</option>
	<option value="02">02</option>
	<option value="03">03</option>
	<option value="04">04</option>
	<option value="05">05</option>
	<option value="06">06</option>
	<option value="07">07</option>
	<option value="08">08</option>
	<option value="09">09</option>
</select>
<select name="mon_start_minute">
	<option value="00">00</option>
	<option value="30">30</option>
</select>
<strong> End Time (HH:MM):</strong>
<select name="mon_end_hour">
	<option value="12">12</option>
	<option value="01">01</option>
	<option value="02">02</option>
	<option value="03">03</option>
	<option value="04">04</option>
	<option value="05">05</option>
	<option value="06">06</option>
	<option value="07">07</option>
	<option value="08">08</option>
	<option value="09">09</option>
</select>
<select name="mon_end_minute">
	<option value="00">00</option>
	<option value="30">30</option>
</select>
<br/>
<strong>Drink Specials:</strong><textarea name="mon_drinks" cols="50" rows="5"></textarea><br/><br/>
<strong>Food Specials: </strong><textarea name="mon_food" cols="50" rows="5"></textarea>

here is my php code

$master_id = mysqli_insert_id($mysqli);

$monday = $_POST["monday"];
if ($monday == "monday") {
	//add to Monday Table
	$mon_start_time = $_POST["mon_start_hour"].":".$_POST["mon_end_minute"];
	$mon_end_time = $_POST["mon_end_hour"].":".$_POST["mon_end_minute"];
	$add_monday_sql = "INSERT INTO Monday (start_time, end_time, food_specials, drink_specials, idrestaurant_info) VALUES ('".$mon_start_time."', '".$mon_end_time."', '".$_POST["mon_food"]."', '".$_POST["mon_drinks"]."', '".$master_id."')";
	$add_monday_res = mysqli_query($mysqli, $add_monday_sql) or die(mysqli_error($msyqli));

I would appreciate any type of help....Thanks in advance

Nothing wrong with the above code. Do you get any errors ?

I don't get any errors. It just doesn't populate the table. This is why it is giving me trouble

First, try print_r to see all the form elements are posted correctly. Try printing the query and see if it executes in mysql console/phpmyadmin.

I saw in your code, there is no form tag, put form tag and keep the method to post, and then check the radio button before posting the data..Then I hope everything will works for you.

i did some updating. the html form part is the same. when i ran the php as is from above i was getting a blank screen. here is my updated code that prints out successful but still doesn't populate the monday table. here is some more of my code. it does populate the restaurant_info table just not the monday table

//insert into Restaurant Name Table
$add_restaurant_sql = "INSERT INTO restaurant_info (name, address, location) VALUES ('".$_POST["restaurant_name"]."', '".$_POST["address"]."', '".$_POST["location"]."')";
$add_restaurant_res = mysqli_query($mysqli, $add_restaurant_sql) or die(mysqli_error($mysqli));

mysqli_free_result($add_restaurant_res);

//get master id for use with other tables
$master_id = mysqli_insert_id($mysqli);

if (isset($_POST["monday"]) && $_POST["monday"] == "yes") {
	//add to Monday Table
	$mon_start_time = $_POST["mon_start_hour"].":".$_POST["mon_start_minute"];
	$mon_end_time = $_POST["mon_end_hour"].":".$_POST["mon_end_minute"];
	$add_monday_sql = "INSERT INTO Monday (start_time, end_time, food_specials, drink_specials, idrestaurant_info) VALUES ('".$mon_start_time."', '".$mon_end_time."', '".$_POST["mon_food"]."', '".$_POST["mon_drinks"]."', '".$master_id."')";
	$add_monday_res = mysqli_query($mysqli, $add_monday_sql) or die(mysqli_error($msyqli));
	
	mysqli_free_result($add_monday_res);
	
}

I think you have to recheck your html code there form tag itself missing, then how the data will be sent to next page, If you already added form tag in your code and also you are not getting the required output, then just try printing the post values in second page, check the values what you are getting

echo "<pre>";
print_r($_POST);
echo "</pre>";

If your required variable is coming till here your code should work, if it is not coming till here, there is some problem with your html form(method should be post in your form)
<form method='post' name='frmname'>

i did some updating. the html form part is the same. when i ran the php as is from above i was getting a blank screen. here is my updated code that prints out successful but still doesn't populate the monday table. here is some more of my code. it does populate the restaurant_info table just not the monday table

//insert into Restaurant Name Table
$add_restaurant_sql = "INSERT INTO restaurant_info (name, address, location) VALUES ('".$_POST["restaurant_name"]."', '".$_POST["address"]."', '".$_POST["location"]."')";
$add_restaurant_res = mysqli_query($mysqli, $add_restaurant_sql) or die(mysqli_error($mysqli));

mysqli_free_result($add_restaurant_res);

//get master id for use with other tables
$master_id = mysqli_insert_id($mysqli);

if (isset($_POST["monday"]) && $_POST["monday"] == "yes") {
	//add to Monday Table
	$mon_start_time = $_POST["mon_start_hour"].":".$_POST["mon_start_minute"];
	$mon_end_time = $_POST["mon_end_hour"].":".$_POST["mon_end_minute"];
	$add_monday_sql = "INSERT INTO Monday (start_time, end_time, food_specials, drink_specials, idrestaurant_info) VALUES ('".$mon_start_time."', '".$mon_end_time."', '".$_POST["mon_food"]."', '".$_POST["mon_drinks"]."', '".$master_id."')";
	$add_monday_res = mysqli_query($mysqli, $add_monday_sql) or die(mysqli_error($msyqli));
	
	mysqli_free_result($add_monday_res);
	
}

the array of data prints out fine. when i go into mysql command line and select * from restaurant_info it returns everything fine but when i try the same thing with the monday table it returns an empty set.

I think you need to check your monday table structure,

Check what is the data type of start_time and end_time in table, try changing those columns data type to text data type. might it solves your problem


the array of data prints out fine. when i go into mysql command line and select * from restaurant_info it returns everything fine but when i try the same thing with the monday table it returns an empty set.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.