Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

New User page?


ghost's Avatar
0 0

Okay I have everything working, more or less. I need help getting my INSERT to actually INSERT what I want when I want:

<?php
srand(time());
include 'config.php';
$user = "testing"; 
?>

<center>
<form action="createuser.php" METHOD="post" name="newuser">
Username
<br/>
<input class="textbox" type="text" name="user"/>
<br/>
Password
<br/>
<input class="textbox" type="pass" name="pass"/>
<br/>
<input type='submit' value='<Create User>'>
</form>
</center>

<?php
mysql_select_db(unrealcomps_game);
$sql = 'INSERT INTO elitehacks_user (user_name, user_pass, hack_points, rank, user_ip) VALUES (\'user\', \'" . md5(pass) . "\', 150, 1, \'" . rand() % 255 . "." . rand() % 255 . "." . rand() % 255 . "." . rand() % 255 . "\')';

mysql_query($sql) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($sql) or die('Error, ');

?>

Any ideas?


ghost's Avatar
0 0

[edit]nvm

whats not working with it?


ghost's Avatar
0 0

It creates a user before it gets the variables… and the IP part doesn't work :(


ghost's Avatar
0 0

you didnt check if the variables have been set. wrap an if() statement around the sql bit that checks if the form has been posted.


ghost's Avatar
0 0

and also the second mysql_query bit should be mysql_query($query) shouldnt it? otherwise youre entering the same row twice ;)


ghost's Avatar
0 0

Oh ok thanks. How would I do an if() I tryed $_post and also the variables don't get inserted into the SQL statement correctly :(


ghost's Avatar
0 0

Code update:

<?php
srand(time());
include 'config.php';
$valid = "12345"; 
if (isset($_POST['valid']))
?>

<center>
<form action="createuser.php" METHOD="post" name="newuser">
Username
<br/>
<input class="textbox" type="text" name="user"/>
<br/>
Password
<br/>
<input class="textbox" type="pass" name="pass"/>
<br />
Validation #
<br/>
<input class="textbox" type="text" name="valid"/>
<br/>
<input type='submit' value='<Create User>'>
</form>
</center>

<?php
if ($_POST['valid'] == $valid ) {
mysql_select_db(unrealcomps_game);
$sql = 'INSERT INTO elitehacks_user (user_name, user_pass, hack_points, rank, user_ip) VALUES (\'user\', \'" . md5(pass) . "\', 150, 1, \'" . rand() % 255 . "." . rand() % 255 . "." . rand() % 255 . "." . rand() % 255 . "\')';
echo $sql;

mysql_query($sql) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, ');
} else {
echo "dang";
}
?>

ghost's Avatar
0 0

I am using isset(), can I please IM someone for help? I got most of the script working, I just need help getting the username : passwork to be what the user selects and echo Username $user already taken!


ghost's Avatar
0 0

The username already taken part is easy:

Run a Select query in PHP, looking for entries 'WHERE username = POST[user]'. Then, check for the presence of a result. For some stereotyped code / pseudocode:

if (!result)
{
   die('Username $user already chosen!');
}
else
{
// run Insert query
}```

Not sure what you mean about the other part.

Edit:  Smileys suck.  Remember, kids, disable smileys when you post code.