thebigchief Posted November 2, 2010 Share Posted November 2, 2010 After a few hours of serching the net for a perfect sollution I have decided to give up completely and ask for some help. if (isset($_POST['new'])) { $query = "INSERT INTO tickets SET "; if ( isset($_POST['hdtn']) ) { $query .= "hdtn='".$_POST['hdtn']."',"; } Can anyone tell me how to set this field as mandatory? Link to comment https://forums.phpfreaks.com/topic/217544-making-a-field-mandatory/ Share on other sites More sharing options...
revraz Posted November 2, 2010 Share Posted November 2, 2010 if (isset($_POST['new'])) { $query = "INSERT INTO tickets SET "; if ( isset($_POST['hdtn']) ) { if (empty($_POST['hdtn'])) { die ("Error: Enter HDTN"); } $query .= "hdtn='".$_POST['hdtn']."',"; } Link to comment https://forums.phpfreaks.com/topic/217544-making-a-field-mandatory/#findComment-1129368 Share on other sites More sharing options...
Anti-Moronic Posted November 2, 2010 Share Posted November 2, 2010 First, don't use die() in the above example and NEVER simply enter unfiltered user data into a sql query. It should be if(isset($_POST['new'])){ $query = "INSERT INTO tickets SET "; if(empty($_POST['hdtn'])){ echo "Error: Enter HDTN"; return; } $query .= "hdtn='".mysql_real_escape_string($_POST['hdtn'])."',"; } Link to comment https://forums.phpfreaks.com/topic/217544-making-a-field-mandatory/#findComment-1129373 Share on other sites More sharing options...
thebigchief Posted November 2, 2010 Author Share Posted November 2, 2010 Guys........... Thanks SO much, this solved hours of work for me Link to comment https://forums.phpfreaks.com/topic/217544-making-a-field-mandatory/#findComment-1129398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.