Sir, i am using these codes

<?php
    $myusername=""; 
    $mypassword=""; 
    $myemail=""; 
    $mymobile=""; 
    $mycountry=""; 
    $mycity=""; 
    $myage=""; 
    $mygender=""; 
    $myphoto=""; 

if(isset($_POST['save'])){
    require_once("connect.php");

    function clean($str){
    $cstr=trim($str);
    $cstr=addslashes($str);
    $cstr=htmlspecialchars($str);
    return $cstr;
    }

    $myusername=clean($_POST['username']); 
    $mypassword=clean($_POST['password']); 
    $myemail=clean($_POST['email']); 
    $mymobile=clean($_POST['mobile']); 
    $mycountry=clean($_POST['country']); 
    $mycity=clean($_POST['city']); 
    $myage=clean($_POST['age']); 


    if(empty($myusername))
    {
        echo ('<script>alert("User name must not be empty")</script>');
        echo '<script>document.getElementById("form1.username").focus()</script>';
        }
        elseif (empty($mypassword))
        {
        echo ('<script>alert("Password must not be empty")</script>');
        }
        elseif (empty($email))
        {
        echo ('<script>alert("Email must not be empty")</script>');
        }
        elseif(empty($mymobile))
        {
        echo ('<script>alert("Mobile must not be empty")</script>');
    }
    else
    {
        $query="SELECT * FROM admin where username $myusername"; 
        $result=mysqli_query($con,$query)or die ("Error". mysqli_error($con)) ;  
        $count=mysqli_num_rows($result); 

        if($count==1)
        {
            echo ('<script>alert("This user name is already exists, please select an other")</script>');
        }
        else
        {

        $query = "INSERT INTO admin (username,password ,email,mobile,country,city,age ,photo )
        VALUES ($myusername,$mypassword ,$myemail, $myemail, $mymobile,$mycity,$myage ,$myphoto)";
        $result=mysqli_query($con, $query) or die (mysqli_error());

        if(!$result)
        {
         echo ('<script>alert("User name is not registered")</script>');
        }
        }
    }
}

?>

I fill all textboxes but it allways run this line:

echo ('<script>alert("Email must not be empty")</script>');

What I am doing wrong?

Member Avatar for diafol

Try

    if(!mysqli_num_rows($result))
    {
     echo ('<script>alert("User name is not registered")</script>');
    }

Line 50 is missing an =

Line 61: single quotes are missing from your query for string data.

line 40
use $myemail insted of $email:

elseif (empty($myemail))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.