Hi all ,

I am a new in PHP my code don't save information in db and password confirmation code doesn't work correctly

this is my simple code :

<?php
// decleration for varible 
$name=$_POST['nameTxt'];
$username=$_POST['userNameTxt'];
$passTxt=$_POST['passTxt']; 
$passConTxt=$_POST['passConTxt']  ;
$email=$_POST['email'];
$website=$_POST['website'];
$errors=0;
$submit=$_POST['btn_done'];    
// connection to mysql 
$con=mysqli_connect('localhost','root','root');
if(!$con){
    die('Could not connection '.mysqli_error());
} //if $con

//select DB :
$db=mysqli_select_db('reg')
or die (mysqli_error());
// .....

if($submit){
    if(!isset($name) || trim($name) == ''){
        ++$errors;
    echo"Please enter the name <br>";
    }//if name

    //  username if blank :
    if(!isset($username) || trim($username) == ''){
        ++$errors;
        echo'Please enter the username <br>';
    }//if username

// email 
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    // echo "email address is not valid <br>";
    ++$errors;

    echo'Please enter a valid email<br>';
}// end if email    
//duplicate email
 //DETERMINE WHETHER THE EMAIL ADDRESS HAS ALREADY BEEN REGISTERED

$q = "SELECT id FROM store WHERE email = '$email'";
        $result = mysql_query ($q);
if (mysql_num_rows($result) !== 0){
    ++$errors;
    echo"email is already exists<br>";}

// website :

if(!filter_var( $website,FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED))
  { ++$errors;
    echo'Please enter a valid website '.'<br>';
  }
  //end if website
  ////////////////////////////

  ///////////////////////////
  // password :
    if (strlen($_POST['passTxt']<6)){
    ++$errors;
    echo'password should be more than 6 <br>';
  }// if password   
  //password confirmation
  elseif(0 !==strcmp($_POST['passTxt'], $_POST['passConTxt'])){
    ++$errors;
  echo'password does not match <br>';
  }//if password confirmation

  elseif(0===$errors){
    $query="insert into store values('','$name','$username','$passTxt','$passConTxt','$email','$website')";
$data=mysqli_query($query) or die(mysqli_error('ooooooooooooooooooooooooooo'));
if ($data){echo "DONE ! <br>";}
  }//
}
//submit

Please suggest where i am making a mistakes!

Recommended Answers

All 5 Replies

You are using MySQLi so you must use

$con=mysqli_connect('localhost','root','root','reg');

mysqli_connect(Host,User,Password,Database);
to connect to database, then when run a query

$data=mysqli_query($con,$query);

mysql_num_rows() should be replaced by mysqli_num_rows();
MySQLi use the $con as first parameter, so use as above.

Thank you i fixed it but still not adding to db :( !

IF trying the above still not saving in the db there there must be some problem in you data type of tables row. check them!

Are the error part working? Tell more about it
Test with echo at different lables.

no problems in DB ,,, i found it
i changed this st.
if(0 !==strcmp($_POST['passTxt'], $_POST['passConTxt']))
with this:
elseif($_POST['passTxt']!=$_POST['passConTxt'] )

and this
if(0===$errors)
with
if(0==$errors)

it's work now ^_^

Thanks all for your time :)

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.