Hi How are you , I want from this script to
*don’t send data to the database if the name field is empty,
but the problem here is if I leave the name field empty it sends data to the database and it shows the message "the field name is empty please fill it"at the same time ,
I don’t want the script to send any thing to the data base if the field name is empty
please any help and I appreciate if someone can explain and give me the easiest way to do this.
<?php
error_reporting(E_ALL ^ E_NOTICE);
//1-connecting to localhost
if(!$connect=mysql_connect('localhost','root','')){
exit('unable to connect to the data base');}
// select database
if (!mysql_select_db('topic')){
exit ('unable to locate database');}
// define avariable into php
$name=isset($_POST["name"]) ? $_POST['name'] : "";
$area=isset($_POST["area"]) ? $_POST['area'] : "";
// inserting data into data base
$insert="INSERT INTO hiji SET
name='".mysql_real_escape_string($name)."' ,
area='".mysql_real_escape_string($area)."'";
if(!$a=mysql_query($insert)) {
exit( 'error query'.mysql_error());
}
//fetching data from database
$db_search = mysql_query("SELECT name,area FROM omar");
if (@mysql_num_rows($db_search) > 0) {
//here I had amastake that I wasnt able to bring data from area because I haventselected area in mysql_query area
while($data = mysql_fetch_array($db_search))
{ Print "<b>Name:</b>".$data['name'] . "<br/>" ;
Print "<b>Area:</b>".$data['area'] . "<br/>" ;
}
}
//if the field form is empty or not
if(empty($name)){
echo"the field name is empty please fill it";
}
if ( empty($name))
{
return false;
}