Jump to content

[SOLVED] insert into where not null


spillage

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.