elliott1
New Member
- Messages
- 31
- Reaction score
- 0
- Points
- 0
the above comes up when trying to create a user using a php script the script is below where is says ther error is in:
i use this instead of having to type out each personal detail, below is the script to create user:
Thanks everyone for your help :biggrin:
<?php
$server = "localhost"; // server to connect to.
$database = "xxxxxx"; // the name of the database.
$db_user = "xxxxxx"; // mysql username to access the database with.
$db_pass = "xxxxxx; // mysql password to access the database with.
$table = "users"; // the table that this script will set up and use.
?>
i use this instead of having to type out each personal detail, below is the script to create user:
<?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>";
}
?>
Thanks everyone for your help :biggrin: