Inserting into a database shouldnt be a problem.....
Posted: Sat Dec 20, 2003 2:12 pm
This is the first part of my code where you insert information
The first part of my coding works but when i try to insert the user it never works.
the second part is right here<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="register.php" method="post">
<div align="center">Register<br>
</div>
<table width="276" border="1" align="center">
<tr>
<td width="116">Username</td>
<td width="144"><input type="text" name="uname"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>Repeat Password</td>
<td><input type="password" name="passver"></td>
</tr>
<tr>
<td>E-mail</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Code: Select all
<?php
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$trigger = 0;
$host = "localhost";
$username = "root";
$db = "worldconquest";
$connection = mysql_connect($host, $username) or die("Couldn't connect to MySql");
mysql_select_db($db, $connection);
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$passver = $_POST['passver'];
$email = $_POST['email'];
$result = mysql_query("SELECT * FROM users");
$row = mysql_num_rows($result);
$row2 = mysql_fetch_array($result);
$unametest = $row2["username"];
if ($uname == $unametest){
echo "Username already taken ";
$trigger = 1;
}
if ($pass == "" | $passver == ""){
echo "A password field was left blank ";
$trigger = 1;
}
if ($pass != $passver){
echo "passwords do not match ";
$trigger = 1;
}
if ($uname == ""){
echo "Username left blank ";
$trigger = 1;
}
if ($email == ""){
echo "Email left blank ";
$trigger = 1;
}
if ($trigger == 1){
include ("preregister.php");
}
else{
$sql = "INSERT INTO users(username,password,email)VALUES($uname,$pass,$email);";
$result2 = mysql_query($sql,$connection) or die("Couldn't
execute query. ");
}
?>
</body>
</html>
<?php
?>