Need Help for HANDLING FORM(posting form data into a different PHP script

this form save as choose.html : it is separated from my car.php. so this means Posting form data to a different PHP script which every time i run this i get an error : Undefined index for ‘selType’ and ‘txtcolor’. please help me i am newbie here and id really like to learn. :’(

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title /></head>
<body>
<h2>Select Your Car</h2>
<form method="post" action="car.php">
Type: <br />
<select name="selType">
<option value="Porsche 911">Porsche 911</option>
<option value="Volkswagen Beetle">Volkswagen Beetle</option>
<option value="Ford Taurus">Ford Taurus</option>
</select><p />
Color: <br />
<input type="text" name="txtColor" /> <p />
<input type="submit" />
</form>
</body>
</html>

[php]

<?php // get form input $type = $_POST['selType']; $color = $_POST['txtColor']; // use form input echo "Your $color $type is ready. Safe driving!"; ?>

[/php]

<?php // get form input $type = $_POST['selType']; $color = $_POST['txtColor']; // use form input echo "Your $color $type is ready. Safe driving!"; ?>

Hello friend,
So, the main case of this error is that the variable $_POST that you trying put in variable is undefined. But this error is just a Notice…

To make right, look…

try use the ternary…

<?php $type = isset($_POST['selType']) ? $_POST['selType'] : ''"; $color = isset($_POST['txtColor']) ? $_POST['txtColor'] : ""; echo "Your $color $type is ready. Safe driving!"; ?>

So, ternary is equal “if, else”, in this case… if ( isset ( $_POST[‘txtColor’] ) ) { $type = $_POST[‘txtColor’] } else { $type = “” }

Thank you, I hope that this code can help you.

Ohhh, I forgot…

The name of this is “validation” :))

thank you so much for this… ill try this right away… :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service