Jump to content

northerncomfort

Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

northerncomfort's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here is the complete code. It's changed a bit in the past few hours, but the idea remains the same. But the changes in organization helped me a bit, as now at least I'm not getting a white screen. And the $_POST array is coming through just fine, that's a handy bit of code though, thanks! There aren't any errors when I remove the @ in front of the mysql_select_db. And, I use Bluefish, which gives me some colorized syntax help, but it's not quite as handy as my favorite, BBEdit Lite. The register page is in two parts, register.php (the form) and registerme.php (where the registration goodness comes into play). Here is the inital register form, register.php [code]<?php include "header.php"; ?> <div id="main"><div id="content"><div id="text"><div id="register"> <h1>sign up</h1> <form name="register" action="registerme.php" method="post"> <table border="0" cellspacing="5"> <tr> <td width="100" align="right"><b>*</b> username:</td> <td width="10"></td> <td><input type="text" name="username"><td width="15"></td></td><td><i>your identity; 16 characters max</td></i> </tr><tr> <td width="100" align="right"><b>*</b> email:</td> <td width="10"></td> <td><input type="text" name="email"><td width="15"></td></td><td><i>must be a valid email address</td></i> </tr><tr> <td width="100" align="right"><b>*</b> password:</td> <td width="10"></td> <td><input type="password" name="pass1"><td width="15"></td></td><td><i>minimum of four characters</td></i> </tr><tr> <td width="100" align="right"><b>*</b> confirm pass:</td> <td width="10"></td> <td><input type="password" name="pass2"><td width="15"></td></td><td><i>just making sure...</i></td></i> </tr><tr><td width="100"></td><td width="10"></td><td></td></tr> <tr><td width="100"></td><td width="10"></td><td><i>optional info</i></td></tr> <tr><td width="100"></td><td width="10"></td><td></td></tr> <tr> <td width="100" align="right">real name:</td><td width="10"></td><td><input type="text" name="name"></td> </tr><tr> <td width="100" align="right">location:</td> <td width="10"></td> <td><input type="text" name="location"></td> </tr><tr> <td width="100" align="right">aim/msn/icq:</td> <td width="10"></td> <td><input type="text" name="im"></td> </tr><tr> <td width="100" align="right">homepage url:</td> <td width="10"></td> <td><input type="text" name="url"></td> </tr> <tr> <td width="100" align="right">political bias:</td> <td width="10"></td> <td><select width="150" name="bias"> <option value="none">neutral</option> <option value="liberal3">extremely liberal</option> <option value="liberal2">moderately liberal</option> <option value="liberal1">slightly liberal</option> <option value="conservative1">slightly conservative</option> <option value="conservative2">moderately conservative</option> <option value="conservative3">extremely conservative</option> </select></td> </tr> <tr> <td width="100" align="right">political party:</td> <td width="10"></td> <td><select width="150" name="party"> <option value="none">no party for me</option> <option value="communist">communist</option> <option value="democrat">democrat</option> <option value="green">green</option> <option value="independent">independent</option> <option value="libertarian">libertarian</option> <option value="reform">reform</option> <option value="republican">republican</option> <option value="socialist">socialist</option> </select></td> </tr> <tr> <td width="100" align="right">age:</td> <td width="10"></td> <td><select width="150" name="age"> <option value="none">not telling!</option> <option value="under15">under 15</option> <option value="1518">15 - 18</option> <option value="1922">19 - 22</option> <option value="2327">23 - 27</option> <option value="2833">28 - 33</option> <option value="3440">34 - 40</option> <option value="4150">41 - 50</option> <option value="over50">over 50</option> </select></td> </tr> <tr> <td width="100" align="right">mailing list:</td> <td width="10"></td> <td><select width="150" name="list"> <option value="no">no emails, please!</option> <option value="yes">yes, why thank you</option> </select></td> </tr> <tr> <td width="100"></td><td width=10"></td><td width="150" align="right"><input type="submit" name="submit" value="sign up"</td></tr> </table></form></div></div></div></div> <?php include "sidebar.php"; include "footer.php"; ?>[/code] and the register processing page, registerme.php [code]<?php function fixvar() { $month = date(m); $day = date(d); $year = date(Y); $name = strip_tags($_POST['name']); $location = strip_tags($_POST['location']); $aim = strip_tags($_POST['aim']); $name = $_POST['name']; $location = $_POST['location']; $aim = $_POST['im']; $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; $url = $_POST['url']; $bias = $_POST['bias']; $party = $_POST['party']; $list = $_POST['list']; } function dbconnect() { include "database.php"; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "MAAAARRRRRGGGGEEE! Cannot connect to database."); } function inbusiness() { $username = $_POST['username']; if (strlen($username) >= 3) { continuebusiness();   }   if (strlen($username) < 3) {   echo 'sorry, that username is shorter than 3 characters. please  <a href="register.php">lengthen it</a>.</p>';   echo "</div></div></div>"; include "sidebar.php"; include "footer.php";   exit;   } }  function continuebusiness() { $email = $_POST['email']; if (strlen($email) < 7) { echo 'your email appears to be invalid,  please <a href="register.php">double-check it</a>.</p>';   echo "</div></div></div>"; include "sidebar.php"; include "footer.php";   exit;   }   if (strlen($email) > 8) {   checkuserlength();   } } function checkusername() { dbconnect(); $q = "SELECT username FROM users WHERE username = '$username'"; $result = mysql_query($q); $number = mysql_numrows($result); if ($number != 0) { echo "sorry, the username ".$username." is already taken. <a href=\"register.php\">try again</a>.</p>"; echo "</div></div></div>"; include "sidebar.php"; include "footer.php"; exit; } else { submituser(); } } function checkuserlength() { if (strlen($username) > 16) {   echo 'sorry, ".$username." is longer than 16 characters, please  <a href="register.php">shorten it</a>.</p>';   echo "</div></div></div>"; include "sidebar.php"; include "footer.php";   exit; } else { checkpasswords(); } } function checkpasswords() { if ($pass1 != $pass2) { echo 'your passwords do not match,  please <a href="register.php">double-check them</a>.</p>'; echo "</div></div></div>"; include "sidebar.php"; include "footer.php"; exit; } else { checkpasslength(); } } function checkpasslength() { if (strlen($pass1) <= 4) { echo 'your password is too short,  please <a href="register.php">lengthen it</a>.</p>'; echo "</div></div></div>"; include "sidebar.php"; include "footer.php"; exit; } else { checkemail(); } } function checkemail() {   if (ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) {         echo 'your email appears to be invalid,  please <a href="register.php">double-check it</a>.</p>'; echo "</div></div></div>"; include "sidebar.php"; include "footer.php"; exit;     } else {     checkusername();     } } function submituser() { $passhash = (md5($pass1)); $x = "INSERT INTO users VALUES ('', '$month', '$day', '$year', '$username', '$email', '$passhash', '$name', '$location', '$aim', '$bias', '$party', '$age', '$list', '0')"; $result = mysql_query($x); } include "header.php"; ?> <div id="main"><div id="content"> <h1>register</h1><div id="text"><p> <?php if ($_POST['submit']) { fixvar(); inbusiness(); ?> <div id="loginscreen"> <p>registration was a success! log in now.</p> <form name="register" action="logmein.php" method="post"> <table border="0" cellspacing="5"> <tr> <td width="100" align="right"> username:</td> <td width="10"></td> <td><input type="text" name="username"></td> </tr><tr> <td width="100" align="right"> password:</td> <td width="10"></td> <td><input type="text" name="password"></td> </tr> <tr><td width="100" align="right">remember me?</td><td width="10"></td><td> <select name="remember"><option value="yes">yes, please!</option><option value="no">no thank you</option></select> </td></tr> <tr> <td width="100"></td><td width=10"></td><td width="150" align="right"><input type="submit" name="submit" value="log in"</td> </tr> </table></form> </div> <?php } else { echo "<div id=\"text\"><p>something definitely went wrong here. please try <a href=\"register.php\">registering</a> again!</p></div>"; echo "</div></div></div>"; include "sidebar.php"; } echo "</div></div></div>"; include "sidebar.php"; include "footer.php"; ?>[/code]
  2. I fixed those two things- the detect submit was something I was going to add in a bit later, but it can't hurt to put it in now. I also swapped the $var and the $_POST['var'], that one always gets me for some reason! I also fixed a few typos (a $ in front of an if, sheesh) Still no luck, but perhaps there's another glaringly obvious thing I'm goofing up? [code] <?php include "database.php"; include "header.php"; ?> <div id="main"><div id="content"><div id="text"> <h1>register</h1><p> <?php if (isset($$_POST['submit'])) { $month = date(m); $day = date(d); $year = date(Y); $name = strip_tags($_POST['name']); $location = strip_tags($_POST['location']); $aim = strip_tags($_POST['aim']); $email = $_POST['email']; $name = $_POST['name']; $location = $_POST['location']; $username = $_POST['username']; $username = trim($username); $aim = $_POST['im']; $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; $url = $_POST['url']; $bias = $_POST['bias']; $party = $_POST['party']; $list = $_POST['list']; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "MAAAARRRRRGGGGEEE! Cannot connect to database."); $q = "SELECT username FROM users WHERE username = '$username'"; $result = mysql_query($q); $number = mysql_numrows($result); if ($number != 0) { echo "sorry, the username ".$username." is already taken. <a href=\"register.php\">try again</a>.</p>"; exit; } if (strlen($username) > 16) {   echo 'Sorry, ".$username." is longer than 16 characters, please  <a href=\"register.php\">shorten it</a>.';   exit; } if ($pass1 != $pass2) { echo 'your passwords do not match,  please <a href=\"register.php\">double check them</a>.'; exit; } if (strlen($pass1) < 4){ echo 'your password is too short,  please <a href=\"register.php\">lengthen it</a>.'; exit; } if (!preg_match("/.*@.*..*/", $email) | preg_match("/(<|>)/", $email)) { die('your email address appears to be invalid, please <a href=\"register.php\">double check it</a>.'); } else { $passhash = md5($pass1); $q = "INSERT INTO users VALUES ('', '$month', '$day', '$year', '$username', '$email', '$passhash', '$name', '$location', '$aim', '$bias', '$party', '$age', '$list', '0')"; result = mysql_query($q); ?> <div id="loginscreen"> <p>registration was a success! log in now.</p> <form name="register" action="logmein.php" method="post"> <table border="0" cellspacing="5"> <tr> <td width="100" align="right"> username:</td> <td width="10"></td> <td><input type="text" name="username"></td> </tr><tr> <td width="100" align="right"> password:</td> <td width="10"></td> <td><input type="text" name="password"></td> </tr> <tr><td width="100" align="right">remember me?</td><td width="10"></td><td> <select name="remember"><option value="yes">yes, please!</option><option value="no">no thank you</option></select> </td></tr> <tr> <td width="100"></td><td width=10"></td><td width="150" align="right"><input type="submit" name="submit" value="log in"</td> </tr> </table></form> </div> </div></div></div> <?php } include "sidebar.php"; include "footer.php"; } else { exit; } ?> [/code]
  3. No errors, just a blank screen. Which is somewhat peculiar, since I've got error messages turned on in php.ini. I'm pretty confused myself.
  4. I'm putting up the frameworks for a register script, but it just won't work! I've fiddled and fiddled, but to no avail. The code's pretty straightforward in what it's doing, which makes me even more confused as to what's wrong! Any help would be much appreciated! <?php include "database.php"; include "header.php"; ?> <div id="main"><div id="content"><div id="text"> <h1>register</h1><p> <?php $month = date(m); $day = date(d); $year = date(Y); $name = strip_tags($_POST['name']); $location = strip_tags($_POST['location']); $aim = strip_tags($_POST['aim']); $_POST['email'] = $email; $_POST['name'] = $name; $_POST['location'] = $location; $_POST['username'] = $username; $username = trim($username); $_POST['im'] = $aim; $_POST['pass1'] = $pass1; $_POST['pass2'] = $pass2; $_POST['url'] = $url; $_POST['bias'] = $bias; $_POST['party'] = $party; $_POST['list'] = $list; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "MAAAARRRRRGGGGEEE! Cannot connect to database."); $q = "SELECT username FROM users WHERE username = '$username'"; $result = mysql_query($q); $number = mysql_numrows($result); $if ($number != 0) { echo "sorry, the username ".$username." is already taken. <a href=\"register.php\">try again</a>.</p>"; exit; } if (strlen($username) > 16) {   echo 'Sorry, ".$username." is longer than 16 characters, please  <a href=\"register.php\">shorten it</a>.';   exit; } if ($pass1 != $pass2) { echo 'your passwords do not match,  please <a href=\"register.php\">double check them</a>.'; exit; } if (strlen($pass1) < 4){ echo 'your password is too short,  please <a href=\"register.php\">lengthen it</a>.'; exit; } if (!preg_match("/.*@.*..*/", $email) | preg_match("/(<|>)/", $email)) { die('your email address appears to be invalid, please <a href=\"register.php\">double check it</a>.'); } else { $passhash = md5($pass1); $q = "INSERT INTO users VALUES ('', '$month', '$day', '$year', '$username', '$email', '$passhash', '$name', '$location', '$aim', '$bias', '$party', '$age', '$list', '0')"; result = mysql_query($q); ?> <div id="loginscreen"> <p>registration was a success! log in now.</p> <form name="register" action="logmein.php" method="post"> <table border="0" cellspacing="5"> <tr> <td width="100" align="right"> username:</td> <td width="10"></td> <td><input type="text" name="username"></td> </tr><tr> <td width="100" align="right"> password:</td> <td width="10"></td> <td><input type="text" name="password"></td> </tr> <tr><td width="100" align="right">remember me?</td><td width="10"></td><td> <select name="remember"><option value="yes">yes, please!</option><option value="no">no thank you</option></select> </td></tr> <tr> <td width="100"></td><td width=10"></td><td width="150" align="right"><input type="submit" name="submit" value="log in"</td> </tr> </table></form> </div> </div></div></div> <?php include "sidebar.php"; include "footer.php"; } ?>
  5. I've encountered a bit of a problem with my contacts database. I'm building a contacts database for my office, which is working pretty nicely so far. The actual contacts part is working perfectly, and is based in mySQL. However, I've also added a "My Contacts" as this was a big request in the office. It uses a simple login, takes the name, creates a table in the database called $username_contacts, etc. Adding a contact to the mycontacts table has been working nicely so far, but I'm having a problem with listing the "My Contacts" part that hopefully I can find some help here with. Basically, each contact in the main contacts table has an id number. The $username_contacts table keeps track of who you have in your contacts list by the id number. Here is the code in question. It first checks to make sure you're logged in, then puts your username as $name and grabs the correct table. Then it sees how many contacts you have in my contacts (this is where the script starts to flounder), and for each contact you have in my contacts, it grabs the proper contact info from the main contacts table. However, that isn't working so nicely at the moment, and hopefully somebody here with a beady eye will be able to spot the problem. Also, is there any way to keep each contact email address in a different variable so I could have an option to display a table of the email addresses so that the folks in the office could quickly email all of "my contacts" at once? [code]<?php if($logged_in){ echo "My Contacts"; include "database.php"; $name = $_SESSION['username']; mysql_connect($connect,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $sql2 = "SELECT * FROM ".$name."_contacts"; $result2 = mysql_query($sql2); $num=mysql_numrows($result2); $i = 1; while ($i <= $num){ $toget = mysql_result($result2,$i,"contact_id"); $sql = "select * from contacts where id='".$toget."'"; $result = mysql_query($sql); $first=mysql_result($result,$i,"firstname"); $last=mysql_result($result,$i,"lastname"); $company=mysql_result($result,$i,"company"); $address=mysql_result($result,$i,"address"); $city=mysql_result($result,$i,"city"); $state=mysql_result($result,$i,"state"); $zip=mysql_result($result,$i,"zip"); $fax=mysql_result($result,$i,"fax"); $workphone1=mysql_result($result,$i,"workphone1"); $workphone2=mysql_result($result,$i,"workphone2"); $homephone=mysql_result($result,$i,"homephone"); $cellphone=mysql_result($result,$i,"cellphone"); $email=mysql_result($result,$i,"email"); $id=mysql_result($result,$i,"id"); echo "All the usual contact table stuff goes here, it works fine but is bulky so I editted it out for your sake..."; $i++; } } else{    echo "You are not logged in. You need to be logged in to use My Contacts.<br /><a href=\"index.php\">Log In</a>"; } ?>[/code]
×
×
  • 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.