<?php
include("xxxxx.php");
// connect to the mysql server
$link = mysql_connect("$server", "$db_user","$db_pass")
or die ("Could not connect to mysql because ".mysql_error());
// select the database or table?
mysql_select_db("$table")
or die ("Could not select database because ".mysql_error());
// check if the users is taken
$check = "select id from $table where Users = '".$_POST['users']."';";
$qry = mysql_query($check) or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Sorry, there the username $users is already taken.<br>";
echo "<a href=register.html>Try again</a>";
exit;
} else {
// insert the data
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."',
'".$_POST['password']."')")
or die("Could not insert data because ".mysql_error());
// print a success message
echo "Your user account has been created!<br>";
echo "Now you can <a href=main_login.html>log in</a>";
}
?>