tronicsmasta Posted May 5, 2008 Share Posted May 5, 2008 Anyone have any idea why this doesn't work? when $_POST['name'] is empty, it submits nothing to the database for name... $name = isset($_POST['name']) ? $_POST['name'] : 'Anonymous'; thanks, Quinton Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/ Share on other sites More sharing options...
joecooper Posted May 5, 2008 Share Posted May 5, 2008 personally i would use IF's IF(isset($_POST['name'])){ $name=$_POST['name']; }else{ $name="Anonymous"; } Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533140 Share on other sites More sharing options...
Barand Posted May 5, 2008 Share Posted May 5, 2008 it's always going to be set unless it's an unchecked checkbox or radio button. $name = !empty($_POST['name']) ? $_POST['name'] : 'Anonymous'; Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533141 Share on other sites More sharing options...
tronicsmasta Posted May 5, 2008 Author Share Posted May 5, 2008 awesome! good call on the isset... haha... I don't mind using if else but it adds more lines to the code therefore increasing processing by .23 milliseconds haha thanks for your guys' help! Quinton Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533147 Share on other sites More sharing options...
joecooper Posted May 5, 2008 Share Posted May 5, 2008 lol. thats how i would do it anyway. just imo looks neater and easier to follow. but its down to your preference Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533148 Share on other sites More sharing options...
tronicsmasta Posted May 5, 2008 Author Share Posted May 5, 2008 it is very easy to follow you 2 guys posted at the same time... help much appriciated! Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533152 Share on other sites More sharing options...
Barand Posted May 5, 2008 Share Posted May 5, 2008 personally i would use IF's IF(isset($_POST['name'])){ $name=$_POST['name']; }else{ $name="Anonymous"; } But it still gives the same wrong result as the original problem code. Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533155 Share on other sites More sharing options...
tronicsmasta Posted May 5, 2008 Author Share Posted May 5, 2008 personally i would use IF's IF(isset($_POST['name'])){ $name=$_POST['name']; }else{ $name="Anonymous"; } now that i look at it, this: IF(isset($_POST['name'])){ $name=$_POST['name']; }else{ $name="Anonymous"; } should be this: if (!$_POST['name']) { $name="Anonymous"; } else { $name=$_POST['name']; } Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533158 Share on other sites More sharing options...
Barand Posted May 5, 2008 Share Posted May 5, 2008 I'd still go for the more efficient ternary $name = $_POST['name'] ? $_POST['name'] : 'Anonymous'; // or $name = !$_POST['name'] ? 'Anonymous' : $_POST['name']; Link to comment https://forums.phpfreaks.com/topic/104134-solved-if-field-empty-submits-empty-field/#findComment-533160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.