Jump to content

[SOLVED] php registration help


Jiraiya

Recommended Posts

im using radio boxes and its only displaying the first 3 "village" results and im not sure why here is the code

 

 

if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO users (username, password, bloodline, village)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['bloodline']."', '".$_POST['village']."',)";

$add_member = mysql_query($insert);

?>


<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>





<?php
}
else
{
?>

<center>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><td>
Please choose an ability:<br />
Shariangan:<input type="checkbox" value="Shariangan" name="blood[]"><br />
Byuakugan:<input type="checkbox" value="Byuakugan" name="blood[]"><br />
8 Inner Gates:<input type="checkbox" value="8 Inner Gates" name="blood[]">
<center><H2>Pick a Village to start in</H2><br>
<center> Hidden Village of Konoha:<input type="checkbox" value="Konoha" name="village[]"><br />
Hidden Village of Mist:<input type="checkbox" value="Mist" name="village[]"<br />
Hidden Village of Sand:<input type="checkbox" value="Sand" name="village[]<br />
Hidden Village of Rock:<input type="checkbox" value="Rock" name="village[]<br />
Hidden Village of Cloud:<input type="checkbox" value="Cloud" name="village[]<br />
</td><td>

Link to comment
https://forums.phpfreaks.com/topic/134112-solved-php-registration-help/
Share on other sites

i did some fixing and now it wont send anything to my database.

 

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}

// now we insert it into the database
$insert = "INSERT INTO users (username, password, bloodline, village)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['bloodline']."', '".$_POST['village']."',)";

$add_member = mysql_query($insert);

?>


<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>





<?php
}
else
{
?>

<center>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><td>
Please choose an ability:<br />
Sharingan:<input type="checkbox" value="Sharingan" name="bloodline[]"><br />
Byuakugan:<input type="checkbox" value="Byuakugan" name="bloodline[]"><br />
8 Inner Gates:<input type="checkbox" value="8 Inner Gates" name="bloodline[]">
<center><H2>Pick a Village</H2><br>
Hidden Village Konoha:<input type="checkbox" value="Konoha" name"village[]"><br />
Hidden Village Rock:<input type="checkbox" value="Rock" name"village[]"><br />
Hidden Village Sand:<input type="checkbox" value="Sand" name"village[]"><br />
Hidden Village Mist:<input type="checkbox" value="Mist" name"village[]"><br />
Hidden Village Cloud:<input type="checkbox" value="Cloud" name"village[]"><br />
</td>

<tr><th colspan=0><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>






<?php
}
?> 

Using radio box for these would be better since I cant imagine someone with sharingan in one eye and byublabla in second eye.

 

Also if you get an array its propably because of name you give to each checkbox. "village[]" should be used for arrays, its kinda same as array_push(). Give them names like village1, village2, etc.

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.