spillage Posted April 25, 2008 Share Posted April 25, 2008 So after dabling with a flat file I am now trying to use a database. By using eregi I have sorted out writing to the file if a field is incorect or blank. when using mysql I thought using NOT NULL would do the same but if the field is blank it still writes to the database. This is my first time trying to use mysql with php and not sure where I am going wrong so any help would be appreciated. @ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+'); echo "<p>Your email is: ".$cust.'</p></br>'; if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($friend)))) { echo "<p>Please enter your friends valid email below:</p></br>"; } else { echo "<p>Thank you.</p>"; echo "<p>Your friends email has been submitted.</p>"; echo "<p>Please submit another email or close your browser.</p></br>"; fwrite ($fp,$output, strlen($output)); fclose($fp); } $friend= addslashes($friend); $con=mysql_connect("localhost","root", ""); if (!con) { die('could not connect: '.mysql_error()); } mysql_select_db("promoemail", $con); mysql_query("INSERT INTO email VALUES ('$id', '$cust.', '$friend' NOT NULL, '$time')"); mysql_close ($con); ?> Thanks Spill Link to comment https://forums.phpfreaks.com/topic/102896-php-mysql-not-null/ Share on other sites More sharing options...
dezkit Posted April 25, 2008 Share Posted April 25, 2008 friendly bump 4 u Link to comment https://forums.phpfreaks.com/topic/102896-php-mysql-not-null/#findComment-527192 Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 @ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+'); echo "<p>Your email is: ".$cust.'</p></br>'; if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($friend)))) { echo "<p>Please enter your friends valid email below:</p></br>"; $friend = NULL; } else { echo "<p>Thank you.</p>"; echo "<p>Your friends email has been submitted.</p>"; echo "<p>Please submit another email or close your browser.</p></br>"; fwrite ($fp,$output, strlen($output)); fclose($fp); } $friend= addslashes($friend); $con=mysql_connect("localhost","root", ""); if (!con) { die('could not connect: '.mysql_error()); } mysql_select_db("promoemail", $con); if (!is_null($friend)) { mysql_query("INSERT INTO email VALUES ('$id', '$cust.', '$friend', '$time')"); } mysql_close ($con); Notice how I set friend = NULL if they didn't enter a valid friend. Link to comment https://forums.phpfreaks.com/topic/102896-php-mysql-not-null/#findComment-527201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.