php sql variable (revised)
Alright, I asked this in my previous thread but it was garbled etc, so I thought I would ask here. Ok, here's what I need. I have a SQL table with 3 fields, username, password and id. I have manually set the id for me (the only person registered) to 1. What I need to do is to be able to retrieve the value of that column, and add 1 for the next person that registers so it tracks who registered in what order. Can anyone help me out?
Yea…I know that but it doesn't work that way. First I realized you have to use LAST(id) and not max, that could cause errors. But it's much more than that, the code should look something like this:
$result = mysql_query("SELECT LAST(id) FROM users");
while($row = mysql_fetch_array($result))
{
mysql_select_db("slpctrl_users", $con);
mysql_query("INSERT INTO users (id)VALUES ('$result')");
mysql_close($con);
}
Or somethin, but between adding the other information (username and password) I can't get it to work. :@
Ok, here's my code.
<html>
<body>
<?php
$username = addslashes($_POST['username']);
$password = addslashes($_POST['password']);
$con = mysql_connect("localhost:phpmyadmin","censor","censor");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$userid = ("SELECT LAST(id) FROM users");
if ($username == "" || $password == "")
{
die('<b><center>Please specify username or password</b></center><br><br>');
}
while($row = mysql_fetch_array($userid))
{
mysql_select_db("slpctrl_users", $con);
mysql_query("INSERT INTO users (username, password, id)VALUES ('$username', '$password', '$userid')");
mysql_close($con);
}
echo('<center><br><br><br><b><a href="memberlist.php">View Registered Members</a></center>');
?>
</body>
</html>
Now, without the: while($row = mysql_fetch_array($userid)) { } and without id and $userid in the query, it works fine but not with it. And I for the life of me can't figure out what is right >_<
check out: http://www.w3schools.com/php/func_mysql_fetch_array.asp i think your calling the function with the wrong parameters