handling form

I have this choose.html code from the ebook

Select Your Car

Type:
Porsche 911 Volkswagen Beetle Ford Taurus

Color:

and a php script car.php:

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

im using eclipse for this. every time i try to run this i get an error :

undefined index ---- for selType and txtcolor…

please help me with this … Posting form data to a different PHP script

<?php // get form input [s]$type = $_POST['selType']; $color = $_POST['txtColor'];[/s] // 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…

We need to do a validation, to that 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. :wink:

Good luck! 8)

Sponsor our Newsletter | Privacy Policy | Terms of Service