Jump to content

doomdude

Members
  • Posts

    44
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

doomdude's Achievements

Member

Member (2/5)

0

Reputation

  1. Which basically means that $result_verify_user contains NULL. Should I not be getting the: if (!$result_verify_user) { echo ' Database Error Occured '; Output Database Error Occurred if the query is not working? I really have no clue what is going wrong, been frustrating me for 2 weeks.
  2. Hi Thanks for the reply! How is it failing? It should be checking if username exists, if yes then error if no then continue?
  3. Anyone able to help me on this? I'm still suck
  4. Bump. Anyone able to help me on this?
  5. In fact removing that gives this error: The last error was with my original code.
  6. Hey thanks for you reply. I removed that bracked and now get this error while using the same username / email address:
  7. I'm using an open source registration and login validation system. I've got it working well, apart from I've discovered when adding check if username is taken, it has broken the script and allows duplicate usernames and email addresses: <?php include ('database_connection.php'); if (isset($_POST['formsubmitted'])) { $error = array();//Declare An Array to store any error message if (empty($_POST['name'])) {//if no name has been supplied $error[] = 'Please Enter a name ';//add to array "error" } else { $name = $_POST['name'];//else assign it a variable } if (empty($_POST['e-mail'])) { $error[] = 'Please Enter your Email '; } else { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) { //regular expression for email validation $Email = $_POST['e-mail']; } else { $error[] = 'Your EMail Address is invalid '; } } if (empty($_POST['Password'])) { $error[] = 'Please Enter Your Password '; } else { $Password = $_POST['Password']; } if (empty($error)) //send to Database if there's no error ' { // If everything's OK... // Make sure the email address is available: $query_verify_email = "SELECT * FROM members WHERE Email ='$Email'"; $result_verify_email = mysqli_query($dbc, $query_verify_email); if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false) echo ' Database Error Occured '; } if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email . // Make sure the user is available: $query_verify_user = "SELECT * FROM members WHERE Username ='$name'"; $result_verify_user = mysqli_query($dbc, $query_verify_user); if (!$result_verify_user) { echo ' Database Error Occured '; } } if (mysqli_num_rows($result_verify_user) == 0) { // IF no previous user is using this user . // Create a unique activation code: $activation = md5(uniqid(rand(), true)); $query_insert_user = "INSERT INTO `members` ( `Username`, `Email`, `Password`, `Activation`, `res1`, `res2`, `ounit1`, `dunit1`) VALUES ( '$name', '$Email', '$Password', '$activation', '50000', '50000', '100', '100')"; $result_insert_user = mysqli_query($dbc, $query_insert_user); if (!$result_insert_user) { echo 'Query Failed '; } if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull. // Send the email: $message = " To activate your account, please click on this link:\n\n"; $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation"; mail($Email, 'Registration Confirmation', $message, 'From: Admin@TheGameCo.Com'); // Flush the buffered output. // Finish the page: echo '<div class="success">Thank you for registering! A confirmation email has been sent to '.$Email.' Please click on the Activation Link to Activate your account </div>'; } else { // If it did not run OK. echo '<div class="errormsgbox">You could not be registered due to a system error. We apologize for any inconvenience.</div>'; } } else { // The email address is not available. echo '<div class="errormsgbox" >That email address or username has already been registered. </div>'; } } else {//If the "error" array contains error msg , display them echo '<div class="errormsgbox"> <ol>'; foreach ($error as $key => $values) { echo ' <li>'.$values.'</li>'; } echo '</ol></div>'; } mysqli_close($dbc);//Close the DB Connection } // End of the main Submit conditional. ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Game Name - Home</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="container"> <div id="header"> <?php include("includes/header.php"); ?> </div> <div id="nav"> <?php include("includes/nav.php"); ?> </div> <div id="content"> <form action="index.php" method="post" class="registration_form"> <fieldset> <legend>Registration Form</legend> <p>Create A new Account<br />Already a member? <a href="login.php">Log in</a></p> <div class="elements"> <label for="name">Username:</label> <input type="text" id="name" name="name" size="25" /> </div> <div class="elements"> <label for="e-mail">E-mail:</label> <input type="text" id="e-mail" name="e-mail" size="25" /> </div> <div class="elements"> <label for="Password">Password:</label> <input type="password" id="Password" name="Password" size="25" /> </div> <div class="submit"> <input type="hidden" name="formsubmitted" value="TRUE" /> <input type="submit" value="Register" /> </div> </fieldset> </form> </div> <div id="footer"> <?php include("includes/footer.php"); ?> </div> </div> </body> </html> To add user verification I simply duplicated the email verification: // Make sure the user is available: $query_verify_user = "SELECT * FROM members WHERE Username ='$name'"; $result_verify_user = mysqli_query($dbc, $query_verify_user); if (!$result_verify_user) { echo ' Database Error Occured '; } } if (mysqli_num_rows($result_verify_user) == 0) { // IF no previous user is using this user . Can anyone see where I've gone wrong?
  8. Hey thanks for the reply. I've changed the form now. Where you say my while should be a if, I'm not sure I understand why, I originally created the while to be able to pull the data for these: echo '<b>Resources</b><br />'; echo 'Wood: ' . $row['res1'] . ' <br />'; echo 'Iron: ' . $row['res2'] . ' <br />'; echo 'Credits: ' . $row['credits'] . ' <br />'; However, I've change the while to an if and it has indeed worked. Any chance you could explain why the while didn't work in the context but the if does? Thanks for your help!
  9. Hey guys, I'm just trying to add a form button to my site that updates a user's data in the mysql database. However I'm struggling trying to find a way to define which field to edit, can someone tell me if I'm along the correct lines: Page with submit button: <?php $result = mysql_query("SELECT * FROM members WHERE Username='$_SESSION[username]'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo '<b>Resources</b><br />'; echo 'Wood: ' . $row['res1'] . ' <br />'; echo 'Iron: ' . $row['res2'] . ' <br />'; echo 'Credits: ' . $row['credits'] . ' <br />'; } echo 'Offence Power: '; echo $offencepower; echo '<br />'; echo 'Defence Power: '; echo $defencepower; echo '<br />'; echo 'Total Power: '; echo $totalpower; ?> <br /><br /> <form action="update.php" method="post"> <input type="hidden" name="Memberid" value="' . $row['Memberid'] . '"> <input type="submit" name="submit" value="submit"> </form> Update.php: <?php include ('config.php'); ?> <?php $Memberid = mysql_real_escape_string($_POST['Memberid']); if (isset($_POST['Memberid'])) { $query=("UPDATE members SET totalpower = '10' WHERE Memberid='$Memberid'"); mysql_query($query); echo $query; /* header('Location: ' . $_SERVER['HTTP_REFERER']);*/ } ?> When echoing the query I'm getting: Thanks
  10. Thanks! I'm thinking i'll create a query that works out the users power then inserts it into there database. e.g. Have a "Update Power" link that works out the power then add's it into "totalpower" I'll then just be able to use the SORT query on the top scores page I believe.
  11. The variable $totalpower, is worked out from the field's ounit1 ounit2 .... ounit12 * the power of each, + the dunit1 dunit2... dunit12 + baselevel * 3000 Here: <?php //power calculations $result = mysql_query("SELECT * FROM members WHERE Username='$_SESSION[username]'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $power1 = $row['ounit1'] * 50; $power2 = $row['ounit2'] * 70; $power3 = $row['ounit3'] * 110; $power4 = $row['ounit4'] * 200; $power5 = $row['ounit5'] * 150; $power6 = $row['ounit6'] * 300; $power7 = $row['ounit7'] * 500; $power8 = $row['ounit8'] * 450; $power9 = $row['ounit9'] * 650; $power10 = $row['ounit10'] * 350; $power11 = $row['ounit11'] * 600; $power12 = $row['ounit12'] * 1000; $dpower1 = $row['dunit1'] * 50; $dpower2 = $row['dunit2'] * 70; $dpower3 = $row['dunit3'] * 110; $dpower4 = $row['dunit4'] * 200; $dpower5 = $row['dunit5'] * 150; $dpower6 = $row['dunit6'] * 300; $dpower7 = $row['dunit7'] * 500; $dpower8 = $row['dunit8'] * 450; $dpower9 = $row['dunit9'] * 650; $dpower10 = $row['dunit10'] * 350; $dpower11 = $row['dunit11'] * 600; $dpower12 = $row['dunit12'] * 1000; $dbase = $row['baselevel'] * 3000; } $offencepower = $power1+$power2+$power3+$power4+$power5+$power6+$power7+$power8+$power9+$power10+$power11+$power12; $defencepower = $dpower1+$dpower2+$dpower3+$dpower4+$dpower5+$dpower6+$dpower7+$dpower8+$dpower9+$dpower10+$dpower11+$dpower12+$dbase; $totalpower = (($offencepower+$defencepower)/ 100 * 30) + $offencepower+$defencepower; ?>
  12. Hi thanks for the help, using: <?php $query = "SELECT `Username` FROM members ORDER BY {$totalpower}"; $result = mysql_query($query); $output = ''; $rank = 0; while($row = mysql_fetch_assoc($result)) { $no++; $output .= "<tr>\n"; $output .= "<td>{$rank }</td>"; $output .= "<td>{$row['Username']}</td>\n"; $output .= "</tr>\n"; } ?> <table border='1' cellpadding='10'> <tr> <th>Rank</th> <th>Username</th> </tr> <?php echo $output; ?> </table>"; I'm given the error: Will this be because the $totalpower is called from the session? As the other place I use $totalpower is to just display the power of the user in the side bar? Will I need to call it some other way?
  13. Is it possible to sort a table of mysql data, by using a variable? I'm trying this: <?php $result = mysql_query("SELECT * FROM members ORDER BY '$totalpower'"); echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>Rank</th> <th>Username</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo '<td> </td>'; echo '<td>' . $row['Username'] . '</td>'; echo "</tr>"; } echo "</table>"; ?> It display's a list of username's but not in the correct power order. $totalpower is defined: <?php //power calculations $result = mysql_query("SELECT * FROM members WHERE Username='$_SESSION[username]'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $power1 = $row['ounit1'] * 50; $power2 = $row['ounit2'] * 70; $power3 = $row['ounit3'] * 110; $power4 = $row['ounit4'] * 200; $power5 = $row['ounit5'] * 150; $power6 = $row['ounit6'] * 300; $power7 = $row['ounit7'] * 500; $power8 = $row['ounit8'] * 450; $power9 = $row['ounit9'] * 650; $power10 = $row['ounit10'] * 350; $power11 = $row['ounit11'] * 600; $power12 = $row['ounit12'] * 1000; $dpower1 = $row['dunit1'] * 50; $dpower2 = $row['dunit2'] * 70; $dpower3 = $row['dunit3'] * 110; $dpower4 = $row['dunit4'] * 200; $dpower5 = $row['dunit5'] * 150; $dpower6 = $row['dunit6'] * 300; $dpower7 = $row['dunit7'] * 500; $dpower8 = $row['dunit8'] * 450; $dpower9 = $row['dunit9'] * 650; $dpower10 = $row['dunit10'] * 350; $dpower11 = $row['dunit11'] * 600; $dpower12 = $row['dunit12'] * 1000; $dbase = $row['baselevel'] * 3000; } $offencepower = $power1+$power2+$power3+$power4+$power5+$power6+$power7+$power8+$power9+$power10+$power11+$power12; $defencepower = $dpower1+$dpower2+$dpower3+$dpower4+$dpower5+$dpower6+$dpower7+$dpower8+$dpower9+$dpower10+$dpower11+$dpower12+$dbase; $totalpower = (($offencepower+$defencepower)/ 100 * 30) + $offencepower+$defencepower; ?> Also how do I add auto numbers in the left column e.g 1. 2. 3. 4. Thanks in advance.
  14. Wow, there's still a lot for me to learn in php lol. That pretty much went over my head. I think your saying there is a way to call all of the units opower from the ounits table, and then multiply them by the number of ounits in the members table, which I'd then be able to add up all of the power totals to equal the offence power? Could you possibly point me at an example of calling multiple rows into variables? Thanks for your help.
  15. I've got echo username on my site on the same page: You are logged in as <?php echo $_SESSION['Username'] ; ?> Which works fine: Doing: SELECT * FROM ounits WHERE ounit='1' Returns: Doing: SELECT * FROM members WHERE Username='devildog' Returns: All seem to work. Just not through php lol. I've got a feeling I've wrote the query wrong some how.
×
×
  • 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.