Jump to content

php mysql NOT NULL


spillage

Recommended Posts

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

@ $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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.