Jump to content

limit database entries?


weeman09

Recommended Posts

hey guys i have created a guest list as you can see below i have added a function that should make the database stop adding new records once it hits my specified number of rows. the count comes up and the echo shows but it still adds the record and it shouldn't! help please :)

 

heres my code:

 


<?php

$first_name=$_POST['first_name']; 
$last_name=$_POST['last_name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$password=$_POST['password'];
$repassword=$_POST['repassword'];

if (($first_name == "") or ($last_name == "") or ($email == "") or ($password == ""))
{
echo"<p>Required Field (s) missing....!!!! Go Back and Try Again...!!!</p>";
}
elseif (!(strstr($email, "@")) or !(strstr($email, ".")))
{
echo"<p>Invalid Email....!!!! Go Back and Try Again...!!!</p>";
}
elseif ($password != $repassword)
{
echo"<p>Password Miss Match...!!! Go Back and Try Again...!!!!</p>";
}
else
{
[color=green]/Connect to the server and add a new record 
require_once('conn_db.php');
$query = mysql_query("SELECT COUNT(*) as pcount FROM cust")or die(mysql_error());
$row= mysql_fetch_assoc($query);
echo 'current count:'.$row['pcount']; 
if ($row['pcount'] >5){
echo "guest list is full";
}


$query = "INSERT INTO cust Values ('$first_name', '$last_name', '$phone', '$email', '$password')"; 
    mysql_query($query) or die ("unable to insert the record");
    mysql_close();
   	echo "<p><b>Record Addedd Successfully.....!!!!</p>";
    echo"<p> <a href=login.php>Click Here to Login to the Member Page</a></b></p>";
    $message = "Thankyou for registering with us\
    Your deatils are: \nName: $_POST[first_name] \nEmail: $_POST[email] /nPhone: $_POST[phone] \nPassword: $_POST[password]\n";
    mail ($email, "Website Email", $message);
    }
    ?> [/color]

[code]

Link to comment
https://forums.phpfreaks.com/topic/192724-limit-database-entries/
Share on other sites

<?php

$first_name=$_POST['first_name']; 
$last_name=$_POST['last_name'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$password=$_POST['password'];
$repassword=$_POST['repassword'];

if (($first_name == "") or ($last_name == "") or ($email == "") or ($password == ""))
{
echo"<p>Required Field (s) missing....!!!! Go Back and Try Again...!!!</p>";
}
elseif (!(strstr($email, "@")) or !(strstr($email, ".")))
{
echo"<p>Invalid Email....!!!! Go Back and Try Again...!!!</p>";
}
elseif ($password != $repassword)
{
echo"<p>Password Miss Match...!!! Go Back and Try Again...!!!!</p>";
}
else
{
[color=green]/Connect to the server and add a new record 
require_once('conn_db.php');
$query = mysql_query("SELECT COUNT(*) as pcount FROM cust")or die(mysql_error());
$row= mysql_fetch_assoc($query);
echo 'current count:'.$row['pcount']; 

if ($row['pcount'] >5)
{
echo "guest list is full";
}
else
{

$query = "INSERT INTO cust Values ('$first_name', '$last_name', '$phone', '$email', '$password')"; 
    mysql_query($query) or die ("unable to insert the record");
    mysql_close();
      echo "<p><b>Record Addedd Successfully.....!!!!</p>";
    echo"<p> <a href=login.php>Click Here to Login to the Member Page</a></b></p>";
    $message = "Thankyou for registering with us\
    Your deatils are: \nName: $_POST[first_name] \nEmail: $_POST[email] /nPhone: $_POST[phone] \nPassword: $_POST[password]\n";
    mail ($email, "Website Email", $message);
   }
}
    ?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.