0

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?

4
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by pzuurveen
0

Try

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

Line 50 is missing an =

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

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.