Jump to content

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.