user registration and login page with php and HTML

Hi
Maybe wanting to be a female web developer is getting to me. Really pushing tho.
I urgently need assistance. I am soo new to php and struggling * have cried, slept and still crying*
I have created a user registration page where the user registers, the information is sent to the database and from there if the information is correct the user is linked to the login page.
From the login page the user is able to able to insert data into the insert page, this page will also list the existing businesses that have inserted.
The admin(user) will be able to delete or edit the data inserted.

Problem.

  1. Do i need to create a separate index.php page and a register page, how do i link the register page and the index.php page?? The index.php page contains my logo, and my form. My registration page contains my registration.php script.
  2. Do i also create a separate page for my login.php form that just has my script and another page that has the html form? This applies to my insert and update page as well.
  3. My coding doesnt seem rite as when i test the site(pages) when i click register it opens the register.php pgae instead of processing the script.

Note:

The register and login page inserts the data into the ‘users table’ in the web25d1 database and the insert and list pages insert data into the business table in the web25d1 database.

Index page - justt the html

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index.php</title>
</head>

<body>

  <table width="800" border="0" cellspacing="3" cellpadding="3">  
    <tr>    
      <th scope="col" bgcolor="#ffffff">
        <img src="header.jpg" alt="business_online" width="846" height="148" align="left" />      </th>  
    </tr>
  </table>
  <table width="856" border="0" cellspacing="3" cellpadding="3" bgcolor="#6699CC">  
    <tr>    
      <th width="257" scope="col">
        <a href="register.php" target="_blank" class="nav">REGISTER</a>      </th>    
      <th width="176" scope="col">    
        <a href="login.php" target="_blank">LOGIN</a>      </th>    
      <th width="190" scope="col">      
        <a href="insert.php" target="_blank" class="nav">INSERT</a>      </th>    
      <th width="194" scope="col">
        <a href="list.php" target="_blank" class="nav">LIST</a>      </th>            
    </tr>       
  </table>   
  <p><br/>
    <strong class="h1">Welcome to Business Online, Please fill in your details below to register.</strong><br/>   
    </p>
<form name="form1" method = "post" action="register.php">  
  
  <div align="left">
    <table width="300" border="0" cellspacing="3" cellpadding="3">    
      <tr>      <td>Title: </td>      <td>        
          <select name = "dropdown" value ="title">          
            <option value"registration.php">              </option>          
            <option value = "1"> Mr              </option>          
            <option value = "2"> Mrs              </option>          
            <option value = "3"> Ms              </option>          
            <option value = "4" > Miss              </option>          
            <option value = "5" > Prof              </option>          
            <option value = "6"> Dr              </option>          
            <option value = "7"> Mnr              </option>          
            <option value = "8"> Mev              </option>                   
            </select>              </td>      
      </tr>    
      <tr>      <td>Name: </td>      <td>
          <input type = "text" name = "name" maxlength = "50"></td>      
      </tr>    
      <tr>      <td>Surname:</td>      <td>
          <input type = "text" name = "surname" maxlength = "50"></td>      
      </tr>    
      <tr>      <td>username:</td>      <td>
          <input type = "text" name = "username" maxlength = "30"></td>      
      </tr>    
      <tr>      <td>password:</td>      <td>
          <input type = "password" name = "password" maxlength = "10"></td>      
      </tr>    
      <tr>      <td>confirm password:</td>      <td>
          <input type = "password" name = "password2" maxlength = "10"></td>      
      </tr>    
      <tr>      <td>
          <div align="center"> 
            
            <input name="Submit" type="submit" value="Register">        
            </div></td>      
      </tr>  
    </table>
  </div>
<div align="left"></div></form>  
    <div align="center">  
    </div>
  </body>
  </html>


</body>
</html>



  • The register page that has to link with the index page(home page)
    [php]
<?php include("connect.php"); if(isset($_POST['submit'])){ // Perform the verification on the nation //Check that the passwords match $pass1 = $_POST ['pass1']; $pass2 = $_POST ['pass2']; if ($pass1 == $pass2){ }else { echo "Sorry, your passwords don not match.
" } ; $title = mysql_escape_string($_POST ['title']); $fname = mysql_escape_string($_POST ['fname']); $sname = mysql_escape_string($_POST ['sname']); $uname = mysql_escape_string($_POST ['uname']); $pass1 = mysql_escape_string($pass1); $pass2 = mysql_escape_string($pass2); $pass1 = md5($pass1); $sql = mysql_query("SELECT* FROM `users` WHERE `username` = '$uname'") ; if (mysql_num-rows($sql)>0){ echo "Sorry, that user already exists."; exit(); } mysql_query("INSERT INTO `users`(`id`, `title`,`fname`, `sname`, `uname`, `pass`)VALUES (NULL , '$title', '$fname', '$sname', '$uname', '$pass')") or die(mysql_error()); } else{ echo "Sorry, your passwords do not match.
"; exit (); } }else { $form = <<<EOT Title:
Name:
Surname:
Username:
Password:
Confirm Password:
EOT; echo $form ; } ?>

[/php]

  • The login page

[php]

<?php include('conect.php') or die ("Cannot find the config file."); if(isset($_POST['submit'])){ $uname = mysql_escape_string($_POST['uname']); $pass = mysql_esacpe_string($_POST ['pass']); $pass = md5($pass); $sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname' AND `pass` = '$pass'"); if(mysql_num_rows($sql)> 0 ){ echo "You are now logged in."; exit(); }else { echo "Wrong username and password combination"; } } else { $form = <<<EOT Username:
Password:
EOT; echo $form; } ?>

[/php]

  • The insert page

[php]

<?php include('connect.php') or die ("Cannot find the connect file file."); //Connect to the server and select database mysql_connect ("127.0.0.1", "root", "") or die("cannot connect"); mysql_select_db("$web25db1") or die ("cannot select DB"); //Get values from form $name = $_POST ['bname']; $business_type = $_POST ['btype']; $address = $_POST ['address']; $email = $_POST ['email']; $contact_number = $_POST ['cnumber']; $conact_person ['cperson']; //Insert data in the database $sql= "INSERT INTO $business(`bname`,`btype`, `address`,`email`, `cnumber`,`cperson`) VALUES ('$name', '$business_type', '$address', '$email', '$contact_number', '$contact_person')"; //If successfully insert data into database, display message" Business details added". if($result){ echo" Business details updated"; echo "
"; echo " Back to main page "; } else { echo "ERROR"; } ?> <?php //close connection mysql_close (); ?>

[/php]

  • The list page

[php]

<?php require ('conect.php') or die ("Cannot find the config file."); //Connect to the server and select database mysql_connect ("127.0.0.1", "root", "") or die("cannot connect"); mysql_select_db ($web25db1) or die ("cannot select DB"); //select record from mysql $sql = "SELECT * FROM $business_details"; $result = mysql_query($sql); ?> <?php while($rows=mysql_fetch_array($result)){ ?>
<tr>
<td bgcolor = "#ffffff"><?echo $rows ['id']; ?> </td>
  <td bgcolor = "#ffffff"><?echo $rows ['bname']; ?> </td>
    <td bgcolor = "#ffffff"><?echo $rows ['btype']; ?> </td>
      <td bgcolor = "#ffffff"><?echo $rows ['address']; ?> </td>
        <td bgcolor = "#ffffff"><?echo $rows ['email ']; ?> </td>
          <td bgcolor = "#ffffff"><?echo $rows ['cnumber']; ?> </td>
            <td bgcolor = "#ffffff"><?echo $rows ['cperson']; ?> </td>
            <td bgcolor = "#ffffff"><a href = list_ac.php?id= <? echo $rows ['id']; ?> ">Delete </a><br/><a href = delete_ac.php?id= <? echo $rows ['id']; ?> ">Edit </a></td>
            <?php
			//close while loop

}

?>

Business List
Id Name Business Type Address Email Contact Number Contact Person Action
<?php //close connection; mysql_close (); ?>

[/php]

Its a bit messy, I apologize for that. I hope you will able to understand and assist.

Thank you soo much.

i am taking a look on my localhost. i will post back within half hour

if you want back up your originals files and then try to use my codes instead of yours.

register.php
[php]<?php
include("…/connect_db.php");
if(isset($_POST[‘submit’]))
{

// Perform the verification on the nation
//Check that the passwords match

$pass1 = $_POST ['pass1'];
$pass2 = $_POST ['pass2'];

if ($pass1 == $pass2)
{
}else 
{
echo "Sorry, your passwords do not match. <br/>";
exit ();
}

$title = mysql_escape_string($_POST ['title']);
$fname = mysql_escape_string($_POST ['fname']);
$sname = mysql_escape_string($_POST ['sname']);
$uname = mysql_escape_string($_POST ['uname']);
$pass1 = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);

$pass1 = md5($pass1);

$sql = mysql_query(“SELECT* FROM users WHERE uname = ‘$uname’”) ;

if (mysql_num_rows($sql)>0){
echo “Sorry, that user already exists.”;

exit();
}
mysql_query(“INSERT INTO users(title,fname, sname, uname, pass)VALUES (’$title’, ‘$fname’, ‘$sname’, ‘$uname’, ‘$pass1’)”) or die(mysql_error()); //$pass1

}else { //form was missing the select fields those option tag
$form = <<<EOT

Title:

title1
title2
title3
title4


Name:

Surname:

Username:

Password:

Confirm Password:

</form>

EOT;
echo $form ;
}
?>[/php]

login.php
[php]

<?php include("../connect_db.php"); if(isset($_POST['submit'])){ $uname = mysql_escape_string($_POST['uname']); $pass = mysql_escape_string($_POST ['pass']); //typo here $pass = md5($pass); $sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname' AND `pass` = '$pass'"); if(mysql_num_rows($sql)> 0 ){ echo "You are now logged in."; exit(); }else { echo "Wrong username and password combination"; } } else { $form = <<<EOT Username:
Password:
EOT; echo $form; } ?>[/php]

list.php
[php]

<?php include("../connect_db.php"); //Connect to the server and select database ///Id Name Business Type Address Email Contact Number Contact Person Action //select record from mysql $sql = "SELECT * FROM business_details"; $result = mysql_query($sql); ?> <?php while($rows=mysql_fetch_array($result)){ ?>
<tr>
<td bgcolor = "#ffffff"><?echo $rows ['id']; ?> </td>
  <td bgcolor = "#ffffff"><?echo $rows ['bname']; ?> </td>
    <td bgcolor = "#ffffff"><?echo $rows ['btype']; ?> </td>
      <td bgcolor = "#ffffff"><?echo $rows ['address']; ?> </td>
        <td bgcolor = "#ffffff"><?echo $rows ['email']; ?> </td>
          <td bgcolor = "#ffffff"><?echo $rows ['cnumber']; ?> </td>
            <td bgcolor = "#ffffff"><?echo $rows ['cperson']; ?> </td>
            <td bgcolor = "#ffffff"><a href = list_ac.php?id= <? echo $rows ['id']; ?> ">Delete </a><br/><a href = delete_ac.php?id= <? echo $rows ['id']; ?> ">Edit </a></td>
<?php //close while loop }

?>

Business List
Id Name Business Type Address Email Contact Number Contact Person Action
<?php //close connection; mysql_close (); ?>[/php]

insert.php
[php]<?php

include("…/connect_db.php");

//Connect to the server and select database

//Get values from form
$name = $_POST [‘bname’];
$business_type = $_POST [‘btype’];
$address = $_POST [‘address’];
$email = $_POST [‘email’];
$contact_number = $_POST [‘cnumber’];
$conact_person [‘cperson’];

//Insert data in the database
$sql= “INSERT INTO $business(bname,btype, address,email, cnumber,cperson)
VALUES (’$name’, ‘$business_type’, ‘$address’, ‘$email’, ‘$contact_number’, ‘$contact_person’)”;

//If successfully insert data into database, display message" Business details added".
if($result){
echo" Business details updated";
echo “
”;
echo " Back to main page ";
}
else {
echo “ERROR”;
}
?>

<?php //close connection mysql_close (); ?>[/php]

index.php
[php]

index.php
business_online
REGISTER LOGIN INSERT LIST


Welcome to Business Online, Please fill in your details below to register.

Title: Mr Mrs Ms Prof Dr Mnr Mev
Name:
Surname:
username:
password:
confirm password:
        <input name="Submit" type="submit" value="Register">        
        </div></td>      
  </tr>  
</table>
[/php]

what you need yo modifies is the name of the connect_db.php located at the top of the each file.

i anotated some errors as i found them.

[ol][li]semicolon goes inside the } not after[/li]
[li]missing fields on select drop down[/li]
[li]dropdown named incorrectly[/li]
[li]mysql_num_rows not mysql_num-rows[/li]
[li]in you select query u had username and in you insert you have uname[/li]
[li]id can not be null if you had auto increasement in ur database just dont include in your query[/li][/ol]

it should works now if you encounter any errors let me know. for faster repplies you can talk to me on skype i am always online
skype: wilson_382

wilson382 gave you a +1 on tackling this one!!!

Thanx alot for the help will test it out. Not sure what you mean by modify my connect_db .php page. Please explain

for testing purpose in my localhost my db config file is named connect_db.php so you change it back to your db config file if i recall correctly it was connect.php

Sponsor our Newsletter | Privacy Policy | Terms of Service