Mesajde iluc » Mar Ian 27, 2015 12:45 am
Poti sa te folosesti de functia mysql_num_rows(), ca sa verifici daca mai ai acel username in baza de date.
Cod: Selectaţi tot
<?php
include "db.php";
if (isset($_POST['submit']));
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
// verifici daca ai acelasi username in baza de date
$c = mysql_query("SELECT username FROM users WHERE username = '$username'");
// mysql_num_rows() este functia care il gaseste
$num_rows = mysql_num_rows($c);
// conditia este sa nu il mai avem, atunci mergem mai departe
if ($num_rows == 0 )
}
$reg=mysql_query("INSERT INTO users(username, password, email) VALUES ('$username', '$password', '$email')");
if($reg)
{
echo "Ai fost inregistrat " .$username. ", bun venit! ";
}else
{
echo "A intervenit o problema.";
}
} else {
echo "Acest username a mai fost folosit, va rugam sa alegeti alt username.";
}
?>