stublackett Posted December 3, 2008 Share Posted December 3, 2008 Hi, I've got a form setup, Where the user can tick to make the car they are adding to the site Car Of The Week... This will then input a value of 1 into the Database. That works when the box is ticked, But when its not ticked I'm getting PHP Errors of the variable being undefined... How do I change that undefined to a 0? <form action="addcar.php" method="post" enctype="multipart/form-data"> <h2>Add a new car</h2> <ul> <li><label>Car Name : </label><input type="text" name="carname" tabindex="1" /></li> <li><label>Cars' Description : </label><textarea name="description" cols="40" rows="5" tabindex="2"></textarea></li> <li><label>Price : </label><input name="carsprice" type="text" tabindex="3" id="carsprice" /> <li> <li><label>Feature 1 : </label><input name="feature1" type="text" tabindex="4" /><em>Car feature i.e ABS</em></li> <li><label>Feature 2 : </label><input name="feature2" type="text" tabindex="5" /><em>Car feature i.e ABS</em></li> <li><label>Feature 3 : </label><input name="feature3" type="text" tabindex="6" /><em>Car feature i.e ABS</em></li> <li><label>Feature 4 : </label><input name="feature4" type="text" tabindex="7" /><em>Car feature i.e ABS</em></li> <li><label>Feature 5 : </label><input name="feature5" type="text" tabindex="8" /><em>Car feature i.e ABS</em></li> <li><label>Image 1 : </label><input name="image1" type="file" /><em>* This is the main image that will appear on the site</em></li> <li><label>Image 2 : </label><input type="file" name="image2" /></li> <li><label>Image 3 : </label><input type="file" name="image3" /></li> <li><label>Image 4 : </label><input type="file" name="image4" /></li> <li><label>Make Car Of The Week : </label><input name="caroftheweek" type="checkbox" value="1" /> </li> <li> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="reset" name="reset" id="reset" value="Reset" /> </li> </ul> </form> The Form Field is titled caroftheweek Cheers Quote Link to comment https://forums.phpfreaks.com/topic/135318-solved-form-handling-dealing-with-check-boxes/ Share on other sites More sharing options...
balistic Posted December 3, 2008 Share Posted December 3, 2008 just run a check first thing when submitting if ($caroftheweek!=1) { $caroftheweek=0; } or if (!isset($caroftheweek)) { $caroftheweek=0; } Quote Link to comment https://forums.phpfreaks.com/topic/135318-solved-form-handling-dealing-with-check-boxes/#findComment-704828 Share on other sites More sharing options...
stublackett Posted December 3, 2008 Author Share Posted December 3, 2008 Jackpot! Works a treat Thanks Quote Link to comment https://forums.phpfreaks.com/topic/135318-solved-form-handling-dealing-with-check-boxes/#findComment-704839 Share on other sites More sharing options...
balistic Posted December 3, 2008 Share Posted December 3, 2008 you're welcome Quote Link to comment https://forums.phpfreaks.com/topic/135318-solved-form-handling-dealing-with-check-boxes/#findComment-704841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.