Hey,
I created a simple user register script which later stores the data in a mysql database. What I did initially was that a small code would count the number of rows in the database and then automatically increase the variable by 1 to set the user id. For example if there are 8 records the new user's ID is 9.
After sometime I created another script meant to delete a record, now the problem if is if I delete a record whose ID is 6, so the total no. of records is now 8 (initially there were 9 records) but the record with ID as 9 already exists. Now during the execution of the script, it won't register the user because of that thing. How do I solve that problem?
Here's my register.php script.
P.S I am newbie.
<?php
include("header.html");
include("nav.html");
include("sidebars.html");
?>
<div id="content">
<?php
$errors=array();
if(isset($_POST['submitted'])){
if(empty($_POST['fname'])){
$errors[]="You forgot to enter first name";
}
else{
$fn=$_POST['fname'];
}
if(empty($_POST['lname'])){
$errors[]="You forgot to enter last name";
}
else{
$ln=$_POST['lname'];
}
if(empty($_POST['email'])){
$errors[]="You forgot to enter email";
}
else{
$email=$_POST['email'];
}
if(empty($_POST['usern'])){
$errors[]="You forgot to enter username";
}
else{
$usern=$_POST['usern'];
}
if(!empty($_POST['pass1']))
{
if(($_POST['pass1'])==($_POST['pass2']))
{
$pass=$_POST['pass1'];
}
else
{
$errors[]="The two passwords do not match";
}
}
else
{
$errors[]="You forgot to enter a password";
}
}
$result="";
if(empty($errors)){
require_once("connect.php");
$q1="SELECT * FROM users";
$r=mysql_query($q1,$dbc);
$num=mysql_num_rows($r);
$id=$num+1;
$query="INSERT INTO users VALUES ('$id','$usern',SHA1('$pass'),'$fn','$ln','$email')";
$result = mysql_query($query, $dbc) or die(mysql_error());
}if($result){
echo "You are now a registered user";
}
else{
echo "You could not be registered beacuse :-"."<br>";
foreach($errors as $msg){
echo $msg."<br>";
}
}
?>
</div>
<?php
include("footer.html");
?>