Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. <form> <textarea name="code"> <?php echo '<html>'; echo '<body>'; echo '<p>Hello World</p>'; echo '<body>'; echo '</html>'; ?> </textarea> </form>
  2. Awesome, using an array is so much cleaner than the if version! Thanks
  3. Is there an alternative form of the if statement that I can use for validation? What I want to do is to shorten code that looks like this: if($memType!='Regular' && $memType!='Student' && $memType!='Retired') { //invalid membership type, display error } Is there any way to rewrite the if statement so that I don't need to repeat $memType? In the past, I've used a switch statement: switch($memType) { case 'Regular': case 'Student': case 'Retired': //do nothing default: //invalid membership type, display error } ...but I feel a little weird using switch for this scenario. I would also like to avoid using regular expressions since that seems like overkill.
  4. Another quick question. Did you post the entire script? If not, it would be helpful to see all the code.
  5. This might seem like a silly question, but is the e-mail that is sent to admin@nexus.com being forwarded to you twice? For example, my web host allows me to create "Forward-Only" e-mail addresses. Any e-mail sent to that address can then be forwarded to any number of addresses. Maybe the address you're forwarding to is listed twice.
  6. It looks like you forgot to pass the data of birth field to the preg_match() function. If you change this: // check to see if the date of birth is in the correct format if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', 'Date_of_Birth')) { $error['DOB_Invalid'] = 'Your date of birth is invalid. Please enter a valid date of birth.'; } To this: if(!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $_POST['Date_of_Birth'])) { $error['DOB_Invalid'] = 'Your date of birth is invalid. Please enter a valid date of birth.'; } It should work. The same thing goes for the code that tests the phone number. Also, you should update your error text to match what you're asking for: // check to see if the user supplied a date of birth if (empty($_POST['Date_of_Birth'])) { $error['Date_of_Birth'] = 'Please enter your date of birth in the format of mm/dd/yyyy.'; } The "mm/dd/yyyy" should be changed to "yyyy-mm-dd".
  7. Then you're probably going to want to store the list of friends in a variable and display it later. Try this: //INITIALIZE VARIABLE TO STORE LIST OF FRIENDS $listOfFriends = ''; //GET THE LIST OF FRIENDS $query = "SELECT * FROM friends WHERE username='$session->username'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { //FIGURE OUT IF THE CURRENT FRIEND IS ONLINE $query2 = "SELECT * FROM available_users WHERE username='$row[friendname]'"; $result2 = mysql_query($query2) or die(mysql_error()); //IF THE CURRENT FRIEND IS ONLINE, SHOW CHAT LINK if($row2 = mysql_fetch_array($result2)) { //MAKE SURE THE AVATAR VARIABLE IS BLANK $avatar = ''; //GET CURRENT FRIEND'S AVATAR $query3 = "SELECT avatar FROM users WHERE username='$row[friendname]'"; $result3 = mysql_query($query3) or die(mysql_error()); if($row3 = mysql_fetch_array($result3)) { $avatar = $row3['avatar']; } //SHOW CHAT LINK $listOfFriends .= "<a href=\"javascript:void(0)\" onClick=\"javascript:chatWith('$row2[username]')\">"; if($avatar != '') { $listOfFriends .= "<img src='$avatar'>"; } else { $listOfFriends .= "<img src='no_image.png'>"; } $listOfFriends .= "Chat With $row2[username]</a><br></br>"; } } //DISPLAY THE LIST OF FRIENDS if($listOfFriends != '') { echo "You have " . mysql_num_rows($result2) . " friend/s online<br>"; echo $listOfFriends; }
  8. The code below has been modified to address the issue of a blank avatar. //GET THE LIST OF FRIENDS $query = "SELECT * FROM friends WHERE username='$session->username'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { //FIGURE OUT IF THE CURRENT FRIEND IS ONLINE $query2 = "SELECT * FROM available_users WHERE username='$row[friendname]'"; $result2 = mysql_query($query2) or die(mysql_error()); //IF THE CURRENT FRIEND IS ONLINE, SHOW CHAT LINK if($row2 = mysql_fetch_array($result2)) { //MAKE SURE THE AVATAR VARIABLE IS BLANK $avatar = ''; //GET CURRENT FRIEND'S AVATAR $query3 = "SELECT avatar FROM users WHERE username='$row[friendname]'"; $result3 = mysql_query($query3) or die(mysql_error()); if($row3 = mysql_fetch_array($result3)) { $avatar = $row3['avatar']; } //SHOW CHAT LINK echo "<a href=\"javascript:void(0)\" onClick=\"javascript:chatWith('$row2[username]')\">"; if($avatar != '') { echo "<img src='$avatar'>"; } else { echo "<img src='no_image.png'>"; } echo "Chat With $row2[username]</a><br></br>"; } }
  9. Shouldn't there be an AS between the table name and the name shortcut? Also I think you need to designate which username you're referrring to in the WHERE clause? SELECT f.*, au.* FROM friends AS f JOIN available_users AS au ON au.username = f.friendname WHERE au.username = '{$session->username}'
  10. It sounds like you want to get the avatar for the friends that are online. If that's the case, this should work. //GET THE LIST OF FRIENDS $query = "SELECT * FROM friends WHERE username='$session->username'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { //FIGURE OUT IF THE CURRENT FRIEND IS ONLINE $query2 = "SELECT * FROM available_users WHERE username='$row[friendname]'"; $result2 = mysql_query($query2) or die(mysql_error()); //IF THE CURRENT FRIEND IS ONLINE, SHOW CHAT LINK if($row2 = mysql_fetch_array($result2)) { //MAKE SURE THE AVATAR VARIABLE IS BLANK $avatar = ''; //GET CURRENT FRIEND'S AVATAR $query3 = "SELECT avatar FROM users WHERE username='$row[friendname]'"; $result3 = mysql_query($query3) or die(mysql_error()); if($row3 = mysql_fetch_array($result3)) { $avatar = $row3['avatar']; } //SHOW CHAT LINK echo "<a href=\"javascript:void(0)\" onClick=\"javascript:chatWith('$row2[username]')\">"; if($avatar != '') { echo "<img src='$avatar'>"; } echo "Chat With $row2[username]</a><br></br>"; } } As mentioned before, using a join statement would be more efficient for the MySQL query. But I would need to go back to the books to figure out the syntax.
  11. So then the function you're using doesn't break if there are more than 2 letters...such as "Mrs."? What if there is an ellipsis "..." in the middle of the sentence?
  12. This should work, but its untested. //GET THE LIST OF FRIENDS $query = "SELECT * FROM friends WHERE username='$session->username'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { //FIGURE OUT IF THE CURRENT FRIEND IS ONLINE $query2 = "SELECT * FROM available_users WHERE username='$row[friendname]'"; $result2 = mysql_query($query2) or die(mysql_error()); //IF THE CURRENT FRIEND IS ONLINE, SHOW CHAT LINK if($row2 = mysql_fetch_array($result2)) { echo "<a href=\"javascript:void(0)\" onClick=\"javascript:chatWith('$row2[username]')\">Chat With $row2[username]</a><br></br>"; } } Also, the process could be done in fewer steps if you use the JOIN clause to get data from both tables at the same time. But I never remember exactly how to use it.
  13. Sorry, I'm still a little fuzzy on the details and unfortunatally I not familiar with jp77's login script. Maybe this scenario will help? I have an account in your online forum and my username is "cyberRobot". I have two friends whose usernames are "smiley" and "jc". So I have two records in your friends table: idfriendnameusername 1smileycyberRobot 2jccyberRobot If smiley and I are logged in, the available_users table will look like this: usernametimestamp cyberRobot... smiley... Of course the "..." will be the timestamp for when we logged in. And if we're looking at listing my friends, then $session->username would be equal to cyberRobot? Is this a correct picture of the process?
  14. In my mind there are just too many options to catch everything. But maybe someone has a somewhat decent solution?
  15. I just want to make sure I'm understanding. When someone logs into the system, their username is added to the available_users table. Are they removed from the table when they logout? For the friends table, what does friendname contain...the username of the friend? Is there another table which contains your user data? The one that tells you what username goes with what person?
  16. You could also use friends.* if you want all the fields
  17. Out of curiosity, is "Dr." the only thing you need to worry about? What about other things like: Mr. Mrs. The main navigation; which contains the About Us, Contact Us, etc. links; is on the left This is an interesting idea, but... John M. Smith Have you ever played .Hack?
  18. What do your tables look like? Could you provide the column names and a small sample of the data...of course the data doesn't need to be real.
  19. Are you referring to my comment? If so, what I meant was that the shopping cart product that I use has a default header. It then uses CSS (I think?) to replace the default header that comes with the template with our own custom header. Occasionally when I first visit the website the header shows for less than a second. Then its replaced with the custom header. After that the custom header is cached, so I won't see the default header until my cache is cleared. Note that I've never looked into the code used by the shopping cart system, so the header could be replaced using JavaScript for all I know.
  20. OK, nevermind The answer is to use redirectMatch: redirectMatch 301 ^/about_us_page/$ http://www.example.com/about/ redirectMatch 301 ^/about_us_page$ http://www.example.com/about/ This will force an exact match. Why is it that I can never find a solution until I attempt to ask someone else! I've been looking for this solution for quite some time now. O' well...another unknown that I can check off my list.
  21. Wow, those are some nice tricks. I normally use JavaScript, but I may have to dump that code. I probably wouldn't use the hidden div trick since a bunch of images would show if CSS isn't supported or is disabled. As for the CSS on the body tag, have you noticed any of the graphics temporarily showing up as the graphics load. We use a shopping cart product that flashes their default header for less than a second before our custom graphic loads. They're probably using the same technique but for a different reason.
  22. How do I set up a 301 redirects in my .htaccess file so that a folder reference get sent to a specific file. Without it trying to redirect all the files within that folder. For example, if I have a link like: http://www.example.com/about_us_page/index.html and want to redirect it to: http://www.example.com/about/ I would normally create a couple statements like this: redirect 301 /about_us_page/index.html http://www.example.com/about/ redirect 301 /about_us_page/ http://www.example.com/about/ The problem is that second statement also redirects everything within the "about_us_page" to the new "about" folder occasionally resulting in a 404 error. Is there a way to indicate that the "/about_us_page/" part only refers to the folder reference. I want it to treat the following senarios the same: http://www.example.com/about_us_page/index.html http://www.example.com/about_us_page/ http://www.example.com/about_us_page Where if someone types: http://www.example.com/about_us_page/non_existant_page.html It doesn't get redirected to: http://www.example.com/about/non_existant_page.html
  23. array_slice() is exactly what I was looking for. Thanks for everyone's help!
  24. I have a multidimensional array that looks like: $matchingResults[342] = array(id => 342, title => 'Some awesome resource', matches => 3); $matchingResults[5] = array(id => 5, title => 'A great resource', matches => 1); $matchingResults[200] = array(id => 200, title => 'Another ok resource', matches => 1); This array may contain hundreds of items and I want to only display 10 items per page. Is there a simple offset function that I can use to adjust the array pointer. I was thinking about writing a function which would use a loop to manually change the pointer with the next() function. But it seems like there should be a function already available.
  25. Actually the while loop should start like: $firstTime = true; $i=0; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { //IF FIRST TIME, OPEN A NEW ROW if($firstTime) { echo '<tr>'; $firstTime = false; }
×
×
  • 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.