Jump to content

Unholy Prayer

Members
  • Posts

    166
  • Joined

  • Last visited

    Never

Everything posted by Unholy Prayer

  1. Just the errors that I had the script display if the user left a field blank or chose a username that was already taken.
  2. Eh, I have another problem now. I tested the error messages to make sure they worked and left some fields blank. The error messages displayed, but the data was still inserted into the database. How do I make it so that if an error message is displayed, the data does not get inserted into the database? This is my current code: <?php //Connect to the database... this is definitely an essential. require_once('config.php'); //Get the server date... $date = date("F j, Y"); //Include the header body/functions include('templates/default/header_body.tpl'); $action = $_GET['action']; if($action == '') //What is this user's member number? $members = mysql_query("SELECT * FROM members"); $number = mysql_num_rows($members); $mem_no = $members + 1; { //If the register button was not click clicked... if(empty($_POST['register'])) { echo "</tr><tr>"; //Display the form include('templates/default/register_body.tpl'); } //If it was clicked... if(isset($_POST['register'])) { //Transform inputs into strings for mysql insertion... $username = $_POST['username']; $password = mysql_real_escape_string($_POST['password']); $password_conf = mysql_real_escape_string($_POST['password_conf']); $email = $_POST['email']; $reg_date = $_POST['reg_date']; $mem_no = $_POST['mem_no']; $perm = $_POST['perm']; //Is the user name in use? $membername = "SELECT * FROM members WHERE username='$username'"; $name_result = mysql_query($membername) or die("Error: ".mysql_error()); $name = mysql_num_rows($name_result); //If it is in use... if($name == 1){ echo "<td align='center' class='inputrow'>The username you entered is already in use. Please go back and choose another.</td></tr><tr>"; } //Check if any fields are blank and display error messages if they are. if(empty($_POST['username'])){ echo "<td align='center' class='inputrow'>You left the username field blank. Please go back and fill it out.</td></tr><tr>"; } if(empty($_POST['password'])){ echo "<td align='center' class='inputrow'>You left the password field blank. Please go back and choose a password.</td></tr><tr>"; } if(empty($_POST['password_conf'])){ echo "<td align='center' class='inputrow'>You did not confirm your password. Please make sure your password is correct by filling in the confirm password field.</td></tr><tr>"; } if(empty($_POST['email'])){ echo "<td align='center' class='inputrow'>You did not enter an email address. Please go back and tell us your email address.</td></tr><tr>"; } //Did the passwords match? if($password != $password_conf){ //If they didn't match, display an error message. echo "<td align='center' class='inputrow'>Your passwords did not match. Please go back and re-enter your passwords so they match.</td></tr><tr>"; } //If all fields are filled out, the passwords match, and the username isn't taken... else{ mysql_query("INSERT INTO `members` (`username`,`password`,`email`,`reg_date`,`mem_no`,`perm`) values('$username', '$password', '$email', '$reg_date', '$mem_no', '$perm')") or die("Error: ".mysql_error()); //Display a welcome to the forums message. echo "<td align='center' class='inputrow'>Welcome to the forums, $username! You can now <a href='login.php'>login</a> with the information you chose.</td>"; } } } //And we're done! For now, at least. ?>
  3. Wow, he was right. I have made MySQL Insertion scripts before that didn't have the ' around the table name and they worked fine. Idk why it didn't work. Thanks for the help, all.
  4. Nope, still not inserting the data.
  5. It doesn't display any errors. It just displays the message I have echoed but doesn't insert the information into the database.
  6. <?php require_once('config.php'); $date = date("F j, Y"); include('templates/default/header_body.tpl'); $action = $_GET['action']; if($action == '') //What is this user's member number? $members = mysql_query("SELECT * FROM members"); $number = mysql_num_rows($members); $mem_no = $members + 1; { if(empty($_POST['register'])) { include('templates/default/register_body.tpl'); } if(isset($_POST['register'])) { $username = $_POST['username']; $password = mysql_real_escape_string($_POST['password']); $password_conf = mysql_real_escape_string($_POST['password_conf']); $email = $_POST['email']; $reg_date = $_POST['reg_date']; $mem_no = $_POST['mem_no']; $perm = $_POST['perm']; $membername = "SELECT * FROM members WHERE username='$username'"; $name_result = mysql_query($membername) or die("Error: ".mysql_error()); $name = mysql_num_rows($name_result); if(empty($_POST['username'])){ echo "You left the username field blank. Please go back and fill it out."; } if(empty($_POST['password'])){ echo "You left the password field blank. Please go back and choose a password."; } if(empty($_POST['password_conf'])){ echo "You did not confirm your password. Please make sure your password is correct by filling in the confirm password field."; } if(empty($_POST['email'])){ echo "You did not enter an email address. Please go back and tell us your email address."; } if($password != $password_conf){ echo "Your passwords did not match. Please go back and re-enter your passwords so they match."; } if($name == 1){ echo "The username you entered is already in use. Please go back and choose another."; } else{ mysql_query("INSERT INTO members(username,password,email,reg_date,mem_no,perm) values('$username', '$password', '$email', '$reg_date', '$mem_no', '$perm')" or die(mysql_error)); echo "there are $number members."; echo "<td align='center' class='forumname'>Welcome to the forums, $username! Before you can login and start posting, you must activate your account by visiting the link in an email that was sent to the address you provided. Once you activate your account, you are free to post as you please(as long as you follow the rules)!</td>"; } } } ?> Note: I echoed the number of members there are so I wouldn't have to keep refreshing phpmyadmin.
  7. Eeerrrg... I changed it to that, but now the data isn't inserted into the database and there are no errors.
  8. It's weird... I took the space out of the username I entered in the form and now the error is saying:
  9. I found the error with that part, but now it's saying my mysql_num_rows is not a valid MySQL result resource. The error that is on the line it's saying is the code that determines if the user's username is already in use. This is the code: $membername = "SELECT * FROM members WHERE username = $username"; $name_result = mysql_query($membername); $name = mysql_num_rows($name_result);
  10. It displays this when I try to register: Array ( [username] => Unholy Prayer [password] => password [password_conf] => warrior [email] => email [reg_date] => March 12, 2007 [mem_no] => [perm] => 1 [activation_code] => [is_activated] => no [register] => Register ) I refreshed my database in PHPMyAdmin but there are still no records in the database.
  11. I am using a registration script for my website, but when the register button is pressed, the information doesn't get inserted into the database. No error messages are displayed. This is my code: <?php require_once('config.php'); $date = date("F j, Y"); include('templates/default/header_body.tpl'); function generateCode($length = 10) { $password=""; $chars = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789"; srand((double)microtime()*1000000); for ($i=0; $i<$length; $i++) { $password = $password . substr ($chars, rand() % strlen($chars), 1); } return $password; } $action = $_GET['action']; if($action == '') { if(empty($_POST['register'])) { //What is this user's member number? $members = "SELECT * FROM members"; $member_result = mysql_query($members); $member = mysql_num_rows($member_result); include('templates/default/register_body.tpl'); } if(isset($_POST['register'])) { $activation_code = generateCode(25); $mem_no = $member + 1; $username = $_POST['username']; $password = mysql_real_escape_string($_POST['password']); $password_conf = mysql_real_escape_string($_POST['password_conf']); $email = $_POST['email']; $reg_date = $_POST['reg_date']; $mem_no = $_POST['mem_no']; $perm = $_POST['perm']; $activ_code = $_POST['activ_code']; if(empty($_POST['username'])){ echo "You left the username field blank. Please go back and fill it out."; } if(empty($_POST['password'])){ echo "You left the password field blank. Please go back and choose a password."; } if(empty($_POST['password_conf'])){ echo "You did not confirm your password. Please make sure your password is correct by filling in the confirm password field."; } if(empty($_POST['email'])){ echo "You did not enter an email address. Please go back and tell us your email address."; } if($password != $password_conf){ { echo "Your passwords did not match. Please go back and re-enter your passwords so they match."; } $membername = "SELECT * FROM members where username = $username"; $name_result = mysql_query($membername); $name = mysql_num_rows($name_result); if($name == 1){ echo "The username you entered is already in use. Please go back and choose another."; } $activation_code = generateCode(25); //What is this user's member number? $members = "SELECT * FROM members"; $member_result = mysql_query($member); $member = mysql_num_rows($member_result); $mem_no = $member + 1; mysql_query("INSERT INTO members(username,password,email,reg_date,mem_no,perm) values ('$username', '$password', '$email', '$reg_date', '$mem_no', '$perm')" or die(mysql_error)); echo "Welcome to the forums, $username! Before you can login and start posting, you must activate your account by visiting the link in an email that was sent to the address you provided. Once you activate your account, you are free to post as you please(as long as you follow the rules)!"; mail($email, "New Registration, $sitename", " Thanks for registering on SITE NAME. Here are your login details: Username: ".$username." Password: ".$password." In order to login and gain full access, you must validate your account. Click here to validate: http://$domain/$path/register.php?action=activate&user=".$username."&code=".$activation_code." $email_sig "); } } if($action == 'activate') { if(isset($_GET['user']) && isset($_GET['code'])) { $username = mysql_real_escape_string($_GET['user']); if(mysql_num_rows(mysql_query("SELECT id FROM user_system WHERE username = '$username'")) == 0) { echo "That username is not in the database!"; } else { $activate_query = "SELECT is_activated FROM user_system WHERE username = '$username'"; $is_already_activated = mysql_fetch_object(mysql_query($activate_query)) or die(mysql_error()); if($is_already_activated->is_activated == 1) { echo "This user is already activated!"; } else { $code = mysql_real_escape_string($_GET['code']); $code_query = "SELECT activation_code FROM user_system WHERE username = '$username' LIMIT 1"; $check_code = mysql_fetch_object(mysql_query($code_query)) or die(mysql_error()); if($code == $check_code->activation_code) { $update = "UPDATE user_system SET is_activated = '1' WHERE username = '$username'"; mysql_query($update) or die(mysql_error()); echo "User $username has been activated! Thanks! You may now login!"; } else { echo "The activation code was wrong! Please try again!"; } } } } else { echo "No ID or user given to activate!"; } } } ?>
  12. Ah, the error is gone, but it only displays text for the previous/next links but no link.
  13. I can't figure out how to get this pagination to work. I got it from a tutorial. It says the mysql_fetch_array is not a valid MySQL Resource. This is my code: <?php $tid = $_GET["id"]; require_once('config.php'); //If the thread is viewed... if ($_GET['id']){ //update views in database mysql_query("UPDATE vbb_threads SET tviews = tviews+1 WHERE tid = $tid"); } include('templates/default/header_body.tpl'); echo "<div><a href='index.php'>Index</a> -> <a href='viewforum.php?id=$fid'>$fname</a> -> <a href='viewthread.php?id=$tid'>$threadname</a><br><br> <a href='addreply.php?tid=$tid'>Add Reply</a></div> <table align='center' width='65%' cellspacing='1' cellpadding='1' border='0'> <tr> <td align='center' colspan='2' width='100%' class='ctop'>Viewing $tname</td> </tr><tr>"; $bb_replace = array('[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]'); $bb_replacements = array ('<b>', '</b>', '<i>', '</i>', '<u>', '</u>'); $threads = mysql_query("SELECT * FROM vbb_threads where tid = $tid"); while($t=mysql_fetch_array($threads)) { $tcreator=$t["tcreator"]; $tcontent=$t["tcontent"]; $tdatetime=$t["tdatetime"]; $tsubject=$t["tsubject"]; $tcontent = str_replace($bb_replace, $bb_replacements, $tcontent); include('templates/default/viewthread_body.tpl'); } //Start pagination. $limit = 10; $query_count = "SELECT count(*) FROM vbb_replies WHERE tid = $tid"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $replies = "SELECT * FROM vbb_replies WHERE tid = $tid LIMIT $limitvalue, $limit"; $result = mysql_query($replies) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $bgcolor = "#f9f5b8"; while($r=mysql_fetch_array($replies)) { $rauthor=$r["rauthor"]; $rcontent=$r["rcontent"]; $rdatetime=$r["rdatetime"]; $rcontent = str_replace($bb_replace, $bb_replacements, $rcontent); include('templates/default/replies_body.tpl'); } echo "</table>"; if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); //End pagination. ?>
  14. I need help with my registration script. I got this code off of a tutorial on tutorialized.com and it didn't have a password confirmation input. I added another input but I can't figure out how to make it encrypted with the md5 thing. This is my code: <?php require("config.php"); require("functions.php"); $action = $_GET['action']; if($action == '') { if(empty($_POST['register'])) { echo "<form action='register.php' method='POST'> <table align='center' cellspacing='1' cellpadding='1' border='0'> <tr> <td align='center' colspan='2'>Clan Member Registration</td> </tr><tr> <td align='right'>Username: </td> <td align='left'><input type='text' name='username'></td> </tr><tr> <td align='right'>Email Address:</td> <td align='left'><input type='text' name='email'></td> </tr><tr> <td align='right'>Password: </td> <td align='left'><input type='password' name='password'></td> </tr><tr> <td align='right'>Confirm Password: </td> <td align='left'><input type='text' name='password_conf'></td> </tr><tr> <td align='center' colspan='2'><input type='submit' name='register' value='Register'></td> </form>"; } elseif(isset($_POST['register'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $password_conf = md5($_POST['password_conf']); if($password != $password_conf) { echo "Your passwords did not match. Please go back and change them."; } $email = mysql_real_escape_string($_POST['email']); $activation_code = generateCode(25); $userq = "SELECT username FROM members WHERE username = '$username' LIMIT 1"; $emailq = "SELECT email FROM members WHERE email = '$email' LIMIT 1"; //put errors into an array $errors = array(); if(empty($username)) { $errors[] = "The username field was blank! <br />"; } if(mysql_num_rows(mysql_query($userq)) > 0) { $errors[] = "The username given is already in use! Please try another one! <br />"; } if(empty($password)) { $errors[] = "The password field was blank! <br />"; } if(empty($email)) { $errors[] = "The email field was blank! <br />"; } if(mysql_num_rows(mysql_query($emailq)) > 0) { $errors[] = "The email given is already in use! Please try another one! <br />"; } if(count($errors) > 0) { foreach($errors as $err) { echo $err; } } else { $sqlq = "INSERT INTO members (username, password, email, is_activated, activation_code)"; $sqlq .= "VALUES ('$username', '$password', '$email', '0', '$activation_code')"; mysql_query($sqlq) or die(mysql_error()); echo "Thanks for registering! You will recieve an email shortly containing your validation code, and a link to activate your account!"; mail($email, "New Registration, www.death-on-demand.com", " Thanks for registering on Death On Demand's official clan website. Here are your login details: Username: ".$username." Password: ".$password." In order to login and gain full access, you must validate your account. Click here to validate: http://www.dev.mtechdev.com/deathondemand/register.php?action=activate&user=".$username."&code=".$activation_code." Thanks, Unholy Prayer, Webmaster. "); } } }
  15. I once again need help with my forum software. I am trying to make it so that everytime a user posts a reply or a new thread, it updates both the replies or threads table, and the forums table. I can't figure out what is wrong with my code. The page is functioning, but the table row is not updated. This is my code: mysql_query("UPDATE vbb_forums SET $lastpost_auth = lastpost_auth, $laspost_datetime = lastpost_datetime, $lastpost_thread = lastpost_thread WHERE fid = $fid");
  16. Ah, thank you very much for your help.
  17. This is my first time doing bbcode so I'm not really sure how to do this. I copied this from a tutorial but it doesn't work. $string = "I am so [b]cool[/b] "; $bb-replace = array('[b]','[/b]','[i]',[/i]'); $bb-replacements = array ('<b>','</b>','</i>','</i>'); $string = str_replace($bb-replace,$bb-replacements,$string); The error is a syntax error unexpected T_ARRAY. Thanks in advance.
  18. I am trying to count the number of replies that are in the forum being listed.
  19. Eh, PHP.net doesn't explain these things very well.
  20. How do I set the default timezone to Eastern Standard Time? I am displaying the time on one of my pages but it's five hours off of my time so I'm guessing it's england's time.
  21. That would only work for my count threads code which I already have working. This is my table structure: Forums Table: Threads Table(fid= forum the thread is in) Replies Table(tid=thread the reply is in)
  22. Another question about my forum software for my website. How would I make it so the integer of the "views" field of the threads table automatically increases for every time a user views that thread?
×
×
  • 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.