I'm a newb at web programming. Ugh, this is making me crazy! I've been programming it all day.
I need expert's help. Please help me guys!!
I've been trying to make a Sign Up filter and insert to database code. The code first checks if the username inputted in the sign up exists in the database. If it does, it will ignore the sign up transaction and goes back to index.php. If it doesn't it will store all the inputs to the database.
After inputting, I'm trying to get the idNum (primary key, auto increment) from table 'user' of the newly inputted record and put it in visitNum (primary key for table visit but not auto increment. Table visit is very dependent to table user). But as you can see, I don't know how.
I'm using phpdev423
I have very many problems.
1. First time I sign up, the record is successfully registered in the database. After the first sign up, it won't work anymore. I input a record, it will display "Sign Up Complete" but I don't see anything in the phpmyadmin database. And when I input the same username, it will recognize the username and it will prevent me from registering the record. But when I look at the database, the record isn't there. I tried inputting a record in phpmyadmin manually. It will work and sign up will work again.
2. I already have 4 records in the database. The idNum are 101, 102, 103 and 104. I inputted my 4th record manually. When I input my fifth record from the sign up page, this thing is displayed: Error: Duplicate entry '103' for key 1. I don't understand, isn't idNum supposed to be at 105? My idNum is autoincrement, it's not supposed to be 103.
3. I don't know how to retrieve idNum without using mysql_fetch_array. How do I retrieve an idNum without using mysql_fetch_array.
So, here's my code.
<html>
<head>
</head>
<body>
<?php
$user = $_POST["USERname"];
$con = mysql_connect();
mysql_select_db("xxx", $con);
$userz = (mysql_query("SELECT (username) FROM user"));
while($row = mysql_fetch_array($userz))
if($row["username"] == $user)
{
mysql_close($con);
?>
<script type="text/javascript">
alert("Username already exist. Please choose another one");
window.location="index.php";
</script>
<?php
}
$sql="INSERT INTO user (fname, lname, age, gender, username, password, DateJoined) VALUES ('$_POST[FNname]','$_POST[LNname]','$_POST[AGEname]','$_POST[gender]','$_POST[USERname]','$_POST[PASSname]',curdate())";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
$con2 = mysql_connect();
mysql_select_db("worldsee", $con2);
$ext = mysql_query("SELECT * FROM user WHERE fname='$_POST[FNname]'");
$sequel="INSERT INTO visit (visitNum) VALUES ('$ext')";
if (!mysql_query($sequel,$con2))
{
die('Error: ' . mysql_error());
}
mysql_close($con2);
?>
<script type="text/javascript">
alert("Sign Up Complete!");
window.location="index.php";
</script>
</body>
</html>