princeofpersia Posted December 26, 2010 Share Posted December 26, 2010 Hi guys I have the code below and have 4 text fields, the issue is i'd like to prevent insert query if textfield is empty, do u know how? if (isset($_POST['register']) && $_POST['register']) { $reference = rand(11111111,99999999); $name1 = addslashes(strip_tags($_POST['name1'])); $name2 = addslashes(strip_tags($_POST['name2'])); $name3 = addslashes(strip_tags($_POST['name3'])); $name4 = addslashes(strip_tags($_POST['name4'])); $addname4=mysql_query("INSERT INTO nearest (stref, name) VALUES('$reference','$name4')"); $addname3=mysql_query("INSERT INTO nearest (stref, name) VALUES('$reference','$name3')"); $addname2=mysql_query("INSERT INTO nearest (stref, name) VALUES('$reference','$name2')"); $addname1=mysql_query("INSERT INTO nearest (stref, name) VALUES('$reference','$name1')"); } thanks Link to comment https://forums.phpfreaks.com/topic/222681-avoid-insert-if-text-field-is-empty-help-pleaseee/ Share on other sites More sharing options...
BlueSkyIS Posted December 26, 2010 Share Posted December 26, 2010 if (somevalue == "") { don't do anything } else { perform the inserts } Link to comment https://forums.phpfreaks.com/topic/222681-avoid-insert-if-text-field-is-empty-help-pleaseee/#findComment-1151584 Share on other sites More sharing options...
princeofpersia Posted December 26, 2010 Author Share Posted December 26, 2010 thanks, it works Link to comment https://forums.phpfreaks.com/topic/222681-avoid-insert-if-text-field-is-empty-help-pleaseee/#findComment-1151591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.