spillage Posted April 25, 2008 Share Posted April 25, 2008 This is my first try at using mysql and have a php script to supply the data to put into a table. This all works but I am trying to stop the insert happening if any of the fields are empty. $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', '$time')"); mysql_close ($con); ?> this allows blank data to be passed and even by putting VALUES('$id'NOT NULL, allow the same. Have set up the fields in navicat as not null also. Any ideas as really lost. Thanks. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2008 Share Posted April 25, 2008 I don't see any logic that checks for empty fields. Quote Link to comment Share on other sites More sharing options...
spillage Posted April 25, 2008 Author Share Posted April 25, 2008 This is what I tried first of all $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'NOT NULL, '$cust.'NOT NULL, '$friend'NOT NULL, '$time'NOT NULL)"); mysql_close ($con); ?> Now I'm probally really missing somthing but as this is first time using databases I'm a little lost. Cheers. Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2008 Share Posted April 25, 2008 Maybe I wasn't clear.... an INSERT statement will always INSERT -- NULL or NOT NULL, it doesn't matter. You need to check the values in PHP. Quote Link to comment Share on other sites More sharing options...
spillage Posted April 25, 2008 Author Share Posted April 25, 2008 Thank for pointing this out. I am very new to php even html and worked out that the following code was needed. Finding it hard to my brain to think the right way. But sure this could be cleaned up allot. if ($friend==(!eregi('^[a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$',$friend))) { exit; } elseif ($friend==null) { exit; } else { $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("promo", $con); mysql_query("INSERT INTO submit VALUES ('$id', '$cust.', '$friend', '$time')"); mysql_close ($con); } Cheers, Spill Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.