Jump to content

Registration Problems


ThomasBalaban

Recommended Posts

Hello, I am currently working on my first passion project which I am trying to create a account based system where users can register / log in / log out. I am having one small issue I can't seem to figure it out. 

 
The old version of the site can be found here http://thomasbalaban.com/pieces/afterlyfegaming/login.php (I have done many updates but this problem is happening on this one so why update it for this). The problem is when someone makes a account for some reason my code is making three accounts. Here is my code.
 
 
        //bring in the code to run a query:
include("../includes/checkDb.php");
session_start();
 
//make vars to store what the user typed
$userId = 0;
$userUsername = $_POST['createUser'];
$userPassword = $_POST['createPassword'];
 
//add one to the highest id being used
$result = run_my_query("select * from users order by userId desc limit 1");
while($row = mysql_fetch_array($result)){
$userId = $row["userId"];
}
 
$userId++;
 
echo "Account creation succesful, redirecting";
run_my_query("
INSERT INTO users VALUES (null, '$userUsername', '$userPassword', 'user', null, null, null, null)
");
header("refresh:3;url=../index.php");
 
 
 
and this is the include
       /* Connects to local host and gets the sql file open */
function run_my_query($query){
$serverHandle = mysql_connect('localhost', 'root');
if($serverHandle == false){
die("bad server connection".mysql_error());
}
 
$myDb = mysql_select_db('user_table') or die ('DB Problem - '.mysql_error());
 
$result = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result2 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result3 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
 
mysql_close($serverHandle);
 
return $result;
}
 
function run_my_query2($query){
$serverHandle = mysql_connect('localhost', 'root');
if($serverHandle == false){
die("bad server connection".mysql_error());
}
 
$myDb = mysql_select_db('user_table') or die ('DB Problem - '.mysql_error());
 
$result = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result2 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result3 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
 
mysql_close($serverHandle);
 
return $result;
}
 
 
Can you guys see my problem? I have been trying to figure it out all day. 
Thank you very much!

 

Link to comment
https://forums.phpfreaks.com/topic/278047-registration-problems/
Share on other sites

Yes, you're running the query 3 times.

 

$result = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result2 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result3 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());

Yes, you're running the query 3 times.

 

$result = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result2 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());
$result3 = mysql_query($query) or die ('Query Problem - '.$query.mysql_error());

 

 

I completely over looked that. Thank you so much!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.