Hi All
I have created a form for a user to register and be able to Logon.I need help with username and password validation code.This is what i have done so far and I'm getting this error:error: Column count doesn't match value count at row 1
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\mmanoko\Validate.php on line 96
Wrong Username or Password.Thanks
Register.php

[<h1 style="color:Fuchsia">Register  Screen!</h1>
<form action="Validate.php" method="post" >
ID Number:<br />
<input type="text" name="Id" /><br />
Name:<br />
<input type="text" name="Name" /><br />
Surname:<br />
<input type="text" name="Surname" /><br />
Email:<br />
<input type="text" name="Email" /><br />
Phone No:<br />
<input type="text" name="Phone" /><br />
Address:<br />
<input type="text" name="Address" /><br />
Password:<br />
<input type="text" name="Password" /><br />

<input type="submit" name="save" value="save" />
</form>]

Login.php

</form>
<table id="shell" bgcolor="Silver" border="2" heigh="50" width="250">
<tr><td>
<table id="inner" bgcolor="white" heigh="50" width="250">
<h1 style="color:Fuchsia">Welcome to my Testing Login Screen!</h1>

<form action="Login.php" method="post" >
Username:<br />
<input type="text" name="Username" /><br />
Password:<br />
<input type="text" name="Password" /><br />
<a href="Register.php">Register here</a><br />
<input type="submit" value="Login"/>
</form>
</table>
</td></tr></table>

Validation.php

<?php
if(isset($_POST['Id']))
{
   $Id   = $_POST['Id'];
 }
   if(isset($_POST['Name']))
   {
   $Name    = $_POST['Name'];
   }
   if(isset($_POST['Surname']))
   {
   $Surname = $_POST['Surname'];
 }
 if(isset($_POST['Email']))
   {
   $Email = $_POST['Email'];
 }
 if(isset($_POST['Phone']))
   {
   $Phone = $_POST['Phone'];
 }
 if(isset($_POST['Address']))
   {
   $Address = $_POST['Address'];
 }
 if(isset($_POST['Password']))
   {
   $Password = $_POST['Password'];
 }
else
{
  $Id       = $_POST['Id'];
  $Name     = $_POST['Name'];
  $Surname  = $_POST['Surname'];
  $Username = $_POST['Email'];
  $Phone    = $_POST['Phone'];
  $Address  = $_POST['Address'];
  $Password = $_POST['Password'];
}

  $Id       = $_POST['Id'];
  $Name     = $_POST['Name'];
  $Surname  = $_POST['Surname'];
  $Username = $_POST['Email'];
  $Phone    = $_POST['Phone'];
  $Address  = $_POST['Address'];
  $Password = $_POST['Password'];
//Connect to the database

$db = mysql_connect("localhost","root","");
if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("mydatabase", $db);
	

if (isset($_POST['save'])) { 

//Insert data into the database 

$query= "INSERT INTO Client(Id,Name,Surname,Email,Phone,Address,Password) VALUES('".$Id."''".$Name."','".$Surname."','".$Email."','".$Phone."','".$Address."','".$Password."')";
$result= mysql_query($query);
if($result = mysql_query($query ,$db)) 
{
   
} else { 
echo "error: ".mysql_error();
// DISPLAY FORM IF FORM HAS NOT BEEN SUBMITTED 
}
}
if(isset($_POST['save'])){
}

// username and password sent from form 
$Username=$_POST['Email']; 
$Password=$_POST['Password']; 


$username = stripslashes($Username);
$password = stripslashes($Password);
$username = mysql_real_escape_string($Username);
$password = mysql_real_escape_string($Password);

$sql="SELECT * FROM Client  WHERE Email='$Username' and Password='$Password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("Username");
session_register("Password"); 
header("Login.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();

mysql_close($db);
?>
$result=mysql_query($sql);
$count=mysql_num_rows($result);

are you sure its grabbing stuff from the db and actually have some thing to count ?

No I am not sure.

#
$query= "INSERT INTO Client(Id,Name,Surname,Email,Phone,Address,Password) VALUES('".$Id."''".$Name."','".$Surname."','".$Email."','".$Phone."','".$Address."','".$Password."')";
#
$result= mysql_query($query);

you have forgot to write comma between '".$Id."' and '".$Name."'

#
$query= "INSERT INTO Client(Id,Name,Surname,Email,Phone,Address,Password) VALUES('".$Id."','".$Name."','".$Surname."','".$Email."','".$Phone."','".$Address."','".$Password."')";
#
$result= mysql_query($query);

Thanks,I saw some few mistakes I'll fix them and test.

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.