Jump to content

Smee

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Everything posted by Smee

  1. Wow as easy as that... Thanks
  2. Hi, I was wondering if anyone could help me. I am working on a registration script and have it working correctly but all i have is text input fields and would like to have a drop down menu for 'team supported'. <p class="team_supported"><label> Team Supported: i.e Manchester United. </label> <input type="text" name="team_supported" maxlength="40" value="<?php if (isset($_POST['team_supported'])) echo $_POST['team_supported']; ?>" /> This is the code i am using at the moment. Thanks for any help.
  3. Thanks for your relpy, I have tried implementing something along those lines but to no avail! I am getting the error: an error occured in the script '/home/footba33/public_html/attending.php' on 47: Undefined variable: result Lince 47 code is: if (mysql_num_rows($result) == 0) { $query = "UPDATE users attending VALUES '$at'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error()); } else { The rest of the script is below and thanks for any help! <?php // Tell php we're using sessions. // This script allows us to search our database require_once ('./includes/config.inc.php'); $page_title = 'Search'; include_once ('./includes/header.html'); ?> <div id="search"> <h1> Attending Next Match </h1> <form action="attending.php" method="post" /> <p class="attending"><label> Attending Yes/No: </label> <input type="text" name="attending" maxlength="3" value="<?php if (isset($_POST['attending'])) echo $_POST['attending']; ?>" /> <p class="submit"> <input type="submit" name="submit" value="Register" /> </form> </div> <div id="searchconfirmation"> <?php if (isset($_POST['submit'])) { require_once ('../mysql_connect.php'); $error = false; if (preg_match ('/^[[:alpha:]\.\'\-]{2,30}$/i', stripslashes(trim($_POST['attending'])))) { $at = mysql_real_escape_string($_POST['attending']); }else { $error = true; echo '<center><p><font color ="red"> Please enter Yes or No!</font></p></center>'; } if (mysql_num_rows($result) == 0) { $query = "UPDATE users attending VALUES '$at'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error()); } else { if (mysql_affected_rows() == 1) { echo '<center><p>Your Status has been set!</p></center>'; }else { echo '<center><p><font color="red"> Please try again.</font></p></center>'; } mysql_close(); } } ?> </div> <?php // Footer include ('./includes/footer.html'); ?>
  4. Hi, Was wondering how i would go about changing the answer of lets say an attending column in a database. Basically i want to use yes/no radio buttons in a form to allow users to say if they will attend. If they click yes then 'yes' will be stored in attending column, where as if they click no .. 'no' will be stored in attending column. Hope this makes sense Thanks for any help
  5. Ah yeah so it does! Nice one thanks its sorted!
  6. Hi All, Can anyone tell me why i might be getting this error: an error occured in the script '/home/footba33/public_html/index.php' on 94: Undefined index: team_name Code applying to line 94 is: <td>'.$_SESSION['search_result']['team_name'].'</td> <td><a href="'.$_SESSION['search_result']['url'].'">'.$_SESSION['search_result']['url'].'</a></td> </tr> </tbody>'); I have provided the script below and thanks for any help! <?php // This is the main page for the site // Include our error config file require_once ('./includes/config.inc.php'); // Set the page title $page_title = 'Football Trip'; include ('./includes/header.html'); // Welcome the user when they are logged in echo '<h1> Welcome to Football Trip'; if (isset($_SESSION['first_name'])) { echo ", {$_SESSION['first_name']}!"; } echo '</h1>'; ?> <form action="index.php?go" method="post" /> <p class="team_supported"><label> Team Name: </label> <input type="text" name="team_name" maxlength="40" /> <p class="submit"> <input type="submit" name="submit" value="Search" /> </form> <?php $error = null; if(isset($_POST['submit'])){ // Search form require_once ('../mysql_connect.php'); if ( preg_match ('/^[[:alnum:] ]{4,30}$/i', $_POST['team_name']) ) { $query = "SELECT * FROM teams WHERE team_name LIKE '%" . $_POST['team_name'] . "%'"; $result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); $_SESSION['search_result'] = array(); while($row = mysql_fetch_array($result)){ $_SESSION['search_result'][] = $row; } } else { $error = '<center><p><font color ="red">Team Name contains either; one or more invalid characters, or too many/too little characters.</font></p></center>'; } } if(!isset($_SESSION['search_result']) || $error != null){ // No Search or errors echo(($error != null)? $error : "Please submit a Search query"); }else{ echo(' <table width="600" height="100" border="0" /> <thead> <tr> <th scope="col">Team Name</th> <th scope="col">Fixture List URL</th> </tr> </thead>'); echo(' <tbody> <tr> <td>'.$_SESSION['search_result']['team_name'].'</td> <td><a href="'.$_SESSION['search_result']['url'].'">'.$_SESSION['search_result']['url'].'</a></td> </tr> </tbody>'); } // Include HTML Footer include ('./includes/footer.html'); ?>
  7. Another one bites the dust Well it all works! Just when you click search with no content: an error occured in the script '/home/footba33/public_html/search.php' on 143: Undefined variable: thispage which is the two at the bottom of the script. echo( '<a href="'.$_SERVER['PHP_SELF'].'?page='.((($thispage-1) <= 0)? 0 : $thispage-1).'">Previous Page</a> - <a href="'.$_SERVER['PHP_SELF'].'?page='.((($thispage+1) <= 0)? 0 : $thispage+1).'">Next Page</a>' );
  8. Your an absolute legend, i cant thank you enough! Im going to go over it tomorrow as its very late. All i will say is that it comes up with an error of: an error occured in the script '/home/footba33/public_html/search.php' on 78 Undefined variable: error if(!isset($_SESSION['search_result']) || $error != null){ // No Search or errors echo(($error != null)? $error : "Please submit a Search query"); } Thanks again!
  9. Awesome it worked a treat! made a similar mistake further down as well! Well it works but i understand that because no results show on my second page they are not being passed over. Do i need to pass them through a URL or something? Sorry new to this Thanks again!
  10. Thanks for the reply! I found a good tutorial in the PHP Freaks tut section and followed in but cant see why im getting the error: Parse error: syntax error, unexpected T_IF in search.php on line 72 IF statement on line 72 is: if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } The rest of the code now looks like this.. Any suggestions? Thanks <?php // This script allows us to search our database require_once ('./includes/config.inc.php'); $page_title = 'Search'; include_once ('./includes/header.html'); ?> <div id="search"> <h1> Search </h1> <form action="search.php?go" method="post" /> <p class="post_code"><label> Post Code: </label> <input type="text" name="post_code" maxlength="40" /> <p class="team_supported"><label> Team Supported: </label> <input type="text" name="team_supported" maxlength="40" /> <p class="submit"> <input type="submit" name="submit" value="Search" /> </form> </div> <div id="searchconfirmation"> <?php $error = false; if (isset($_POST['submit'])) { if(isset($_GET['go'])){ require_once ('../mysql_connect.php'); $error = false; if (preg_match ('/^[[:alnum:]]{4,20}$/i', stripslashes(trim($_POST['post_code'])))) { $pc = $_POST['post_code']; } else { echo '<center><p><font color ="red">Please enter the first 4 letters of your Post Code!</font></p></center>'; $error = true; } $ts = $_POST['team_supported']; if (!$error) { $query = "SELECT COUNT(*) FROM users WHERE post_code LIKE '%" . $pc . "%' AND team_supported LIKE '%" . $ts . "%'"; $result = mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); $r = mysql_fetch_row($result); $numrows = $r[0]; $rowsperpage = 5; $totalpages = ceil($numrows / $rowsperpage) if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; $query = "SELECT SELECT first_name, last_name, email, post_code, team_supported FROM users LIMIT $offset, $rowsperpage"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); ?> <table width="600" height="100" border="0" /> <thead> <tr> <th scope="col">First Name</th> <th scope="col">Last Name</th> <th scope="col">E Mail</th> <th scope="col">Post Code</th> <th scope="col">Team Supported</th> <th scope="col">Attending</th> </tr> </thead> <tfoot> <tr> <th scope="row">Total</th> <td colspan="4">85 designs</td> </tr> </tfoot> <?php //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $fn = $row['first_name']; $ln = $row['last_name']; $em = $row['email']; $pc = $row['post_code']; $ts = $row['team_supported']; ?> <tbody> <tr> <td><?php echo "$fn"; ?></td> <td><?php echo "$ln"; ?></td> <td><?php echo "<a href=mailto:" . $em . ">" . $em . ""; ?></td> <td><?php echo "$pc"; ?></td> <td><?php echo "$ts"; ?></td> <td></td> </tr> </tbody> <?php $range = 3; if ($currentpage > 1) { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } } } else { echo '<center><p><font color="red">Please enter a search query</font></p></center>'; } } } ?> </div> <?php include ('./includes/footer.html'); ?>
  11. Hi, I have a working search that i need a tutorial or some help where the PHP shows a next page link if more results are given than a certain amount specified. If anyone can give me some advice or decent tutorial i'd be very grateful. Thanks <?php // This script allows us to search our database require_once ('./includes/config.inc.php'); $page_title = 'Search'; include_once ('./includes/header.html'); ?> <div id="search"> <h1> Search </h1> <form action="search.php?go" method="post" /> <p class="post_code"><label> Post Code: </label> <input type="text" name="post_code" maxlength="40" /> <p class="team_supported"><label> Team Supported: </label> <input type="text" name="team_supported" maxlength="40" /> <p class="submit"> <input type="submit" name="submit" value="Search" /> </form> </div> <div id="searchconfirmation"> <?php $error = false; if (isset($_POST['submit'])) { if(isset($_GET['go'])){ require_once ('../mysql_connect.php'); $error = false; if (preg_match ('/^[[:alnum:]]{4,20}$/i', stripslashes(trim($_POST['post_code'])))) { $pc = $_POST['post_code']; } else { echo '<center><p><font color ="red">Please enter the first 4 letters of your Post Code!</font></p></center>'; $error = true; } $ts = $_POST['team_supported']; if (!$error) { //-query the database table $query = "SELECT first_name, last_name, email, post_code, team_supported FROM users WHERE post_code LIKE '%" . $pc . "%' AND team_supported LIKE '%" . $ts . "%'"; //-run the query against the mysql query function $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); ?> <table width="600" height="100" border="0" /> <thead> <tr> <th scope="col">First Name</th> <th scope="col">Last Name</th> <th scope="col">E Mail</th> <th scope="col">Post Code</th> <th scope="col">Team Supported</th> <th scope="col">Attending</th> </tr> </thead> <tfoot> <tr> <th scope="row">Total</th> <td colspan="4">85 designs</td> </tr> </tfoot> <?php //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $fn = $row['first_name']; $ln = $row['last_name']; $em = $row['email']; $pc = $row['post_code']; $ts = $row['team_supported']; ?> <tbody> <tr> <td><?php echo "$fn"; ?></td> <td><?php echo "$ln"; ?></td> <td><?php echo "<a href=mailto:" . $em . ">" . $em . ""; ?></td> <td><?php echo "$pc"; ?></td> <td><?php echo "$ts"; ?></td> <td></td> </tr> </tbody> <?php } } else { echo '<center><p><font color="red">Please enter a search query</font></p></center>'; } } } ?> </div> <?php include ('./includes/footer.html'); ?>
  12. Thanks PFMaBiSmAd, I have played around but seem to only get a duplicate of my /include/hdear.html after the form and one record showing with two table headers... (very strange?!). I dont suppose you could change my code to show what you mean? Thanks alot
  13. have a working search script as show below and wondering why my headers keep repeating? <?php // This script allows us to search our database require_once ('./includes/config.inc.php'); $page_title = 'Search'; include ('./includes/header.html'); $error = false; if (isset($_POST['submit'])) { if(isset($_GET['go'])){ require_once ('../mysql_connect.php'); $error = false; if (preg_match ('/^[[:alnum:]]{4,20}$/i', stripslashes(trim($_POST['post_code'])))) { $pc = $_POST['post_code']; } else { echo '<p><font color ="red" size="+1"> Please enter the first 4 letters of your Post Code!</font></p>'; $error = true; } $ts = $_POST['team_supported']; if (!$error) { //-query the database table $query = "SELECT first_name, last_name, email, post_code, team_supported FROM users WHERE post_code LIKE '%" . $pc . "%' AND team_supported LIKE '%" . $ts . "%'"; //-run the query against the mysql query function $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $fn = $row['first_name']; $ln = $row['last_name']; $em = $row['email']; $pc = $row['post_code']; $ts = $row['team_supported']; ?> <table width="600" height="100" border="0" /> <tr> <th scope="col">First Name</th> <th scope="col">Last Name</th> <th scope="col">E Mail</th> <th scope="col">Post Code</th> <th scope="col">Team Supported</th> </tr> <tr> <td><?php echo "<p>" .$fn . "</p>"; ?></td> <td><?php echo "<p>" .$ln . "</p>"; ?></td> <td><?php echo "<p>" .$em . "</p>"; ?></td> <td><?php echo "<p>" .$pc . "</p>"; ?></td> <td><?php echo "<p>" .$ts . "</p>"; ?></td> </tr> </table> <?php } } else{ echo "<p>Please enter a search query</p>"; } } } ?> <h1> Search </h1> <form action="search.php?go" method="post" /> <p class="post_code"><label> Post Code: </label> <input type="text" name="post_code" maxlength="40" "/> <p class="post_code"><label> Team Supported: </label> <input type="text" name="team_supported" maxlength="40" /> <p class="submit"> <input type="submit" name="submit" value="Search" /> </form> <?php include ('./includes/footer.html'); ?>
  14. Thanks for the reply.. Ok i have makes several adjustments and have no errors in the script but now when you click 'search' it doesnt show any results when it should do. Here is the revised script: <?php // This script allows us to search our database require_once ('./includes/config.inc.php'); $page_title = 'Search'; include ('./includes/header.html'); if (isset($_POST['submit'])) { require_once ('../mysql_connect.php'); if (empty($_POST['post_code'])) { // Validate Email Address echo '<p><font color="red" size="+1">Please enter your post code.</font></p>'; if (empty($_POST['team_supported'])) { // Validate Email Address echo '<p><font color="red" size="+1">Please enter the team you support.</font></p>'; } } else { $query ="SELECT * FROM users WHERE post_code='". escape_data($_POST['post_code']) . "' AND team_supported='". escape_data($_POST['team_supported']) . "'"; $result = mysql_query ($query); if (mysql_num_rows($result) == 1) { echo "Here are the results:<br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>First Name</td> <td align=center bgcolor=#00FFFF>Last Name</td> <td align=center bgcolor=#00FFFF>E-Mail</td> <td align=center bgcolor=#00FFFF>Team Supported</td> <td align=center bgcolor=#00FFFF>Post Code</td> </tr>"; while ($r = mysql_fetch_array($result)) // Begin while $fn = $r["first_name"]; $ln = $r["last_name"]; $em = $r["email"]; $ts = $r["team_supported"]; $pc = $r["post_code"]; echo " <tr> <td>$fn</td> <td>$last_name</td> <td>$email</td> <td>$team_supported</td> <td>$post_code</td> </tr>"; } // end while } } ?> <h1> Search </h1> <form action="search.php" method="post" /> <p class="post_code"><label> Post Code: </label> <input type="text" name="post_code" maxlength="40" value="<?php if (isset($_POST['post_code'])) echo $_POST['post_code']; ?>"/> <p class="team_supported"><label> Team Supported: </label> <input type="text" name="team_supported" maxlength="40" value="<?php if (isset($_POST['team_supported'])) echo $_POST['team_supported']; ?>" /> <p class="submit"> <input type="submit" name="submit" value="Search" /> </form> <?php include ('./includes/footer.html'); ?>
  15. Hi, Im having trouble with a simple search form. As you can tell by this im new and any changes would be more than welcome. All i want to do is be able to search the database by post code and team supported. This would return results in the form of, first name, last name, email, post code and team supported. Thanks in advance! <?php // This script allows us to search our database require_once ('./includes/config.inc.php'); $page_title = 'Search'; include ('./includes/header.html'); if ($post_code) // perform search only if a string was entered. if ($team_supported) { include_once ('..mysql_connect.php'); $query = "SELECT * from users WHERE post_code='$post_code' AND team_supported='$team_supported'"; $result = mysql_db_query("post_code", "team_supported", $query); if ($result) { echo "Here are the results:<br><br>"; echo "<table width=90% align=center border=1><tr> <td align=center bgcolor=#00FFFF>First Name</td> <td align=center bgcolor=#00FFFF>Last Name</td> <td align=center bgcolor=#00FFFF>E-Mail</td> <td align=center bgcolor=#00FFFF>Team Supported</td> <td align=center bgcolor=#00FFFF>Post Code</td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $fn = $r["first_name"]; $ln = $r["last_name"]; $em = $r["email"]; $ts = $r["team_supported"]; $pc = $r["post_code"]; echo " <tr> <td>$fn</td> <td>$last_name</td> <td>$email</td> <td>$team_supported</td> <td>$post_code</td> </tr>"; } // end while echo "</table>"; } else { echo "problems...."; } } else { echo "Search string is empty. <br> Go back and type a string to search"; } ?> <h1> Search </h1> <form action="search.php" method="post" /> <p class="post_code"><label> Post Code: </label> <input type="text" name='post_code' maxlength="40" /> <p class="team_supported"><label> Post Code: </label> <input type="text" name='team_supported' maxlength="40" /> <p class="submit"> <input type="submit" name="submit" value="Reset Password" /> </form> <?php include ('./includes/footer.html'); ?>
  16. Smee

    Activate.php

    oh my.. think i have been doing this too long for one night Thanks mate!
  17. I am getting the following error: Parse error: syntax error, unexpected '{' in /home/footba33/public_html/activate.php on line 25 Line 25 is this: if ( ($x > 0) && (strlen($y) == (32)) { in the following activate.php, i have checked it several times and can't see a reason for it not to work? Any help would be good. Thanks! <?php // This page activates a user account require_once ('./includes/config.inc.php'); $page_title = 'Activate Your Account'; include ('./includes/header.html'); if (isset($_GET['x'])) { $x = (int) $_GET['x']; } else { $x = 0; } if (isset($_GET['y'])) { $y = $_GET['y']; } else { $y = 0; } // If $x and $y are not correct re-direct user. if ( ($x > 0) && (strlen($y) == (32)) { require_once ('../mysql_connect.php'); $query = "UPDATE users SET active=NULL WHERE (user_id=$x AND active='" . escape_data($y) . "') LIMIT 1"; $result = mysql_query ($query) or trigger_error("Query: $query\n <br />MySQL Error: " . mysql_error()); // Print a customized message if (mysql_affected_rows() == 1) { echo "<h1>Your account has now been activated. You can now log in.</h1>"; } else { echo '<p><font color="red" size="+1">Your account could not be activated. Please re-check the link or contact the system administrator.</font></p>'; } mysql_close(); } else { // Redirect $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for trailing slash if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop of the slash } // Add the page $url .= '/index.php'; ob_end_clean(); // Delete the buffer header("Location: $url"); exit(); // Quit the script } include ('./includes/footer.html'); ?>
  18. Smee

    Register.php

    I made the adjustments you suggested and it works fine. was a problem with the regex and when i got rid of the one for supported team it was ok. Thanks for your help mate
  19. Smee

    Register.php

    the two being returned are: echo '<p><font color ="red" size="+1"> Please enter the first 4 letters of your Post Code!</font></p>'; and echo '<p><font color ="red" size="+1"> Please enter the full name of the team you support! i.e Manchester United (you do not need to add FC etc</font></p>'; Thanks
  20. Smee

    Register.php

    Doh my bad, thought i had it all copied! Anyway the form is below Thanks in advance! <h2> Register for Football Trip</h2> <form action="register.php" method="post"> <p class="first_name"><label> First Name: </label> <input type="text" name="first_name" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /> <p class="last_name"><label> Last Name: </label> <input type="text" name="last_name" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /> <p class="email"><label> E-Mail Address: </label> <input type="text" name="email" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> <p class="password1"><label> Password: </label> <input type="password" name="password1" maxlength="20" /> <small> Use only letters and numbers. Must be between 4 and 20 Characters long. </small> <p class="password2"><label> Confirm Password: </label> <input type="password" name="password2" maxlength="20" /> <p class="post_code"><label> Post Code: (Enter Only The First Four Letters) </label> <input type="text" name="post_code" maxlength="7" value="<?php if (isset($_POST['post_code'])) echo $_POST['post_code']; ?>" /> <p class="team_supported"><label> Team Supported: i.e Manchester United (you do not need to add FC etc). </label> <input type="text" name="team_supported" maxlength="40" value="<?php if (isset($_POST['team_supported'])) echo $_POST['team_supported']; ?>" /> <p class="submit"> <input type="submit" name="submit" value="Register" /> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('./includes/footer.html'); ?>
  21. Hi, Having some problems with a registration script. Everything works fine apart from the Post Code and Team Supported input. Always returns the error as if you had forgot to put info in the form even when you have. What am i doing wrong? Thanks <?php # register.php // This is the registration script for the site require_once ('./includes/config.inc.php'); // Set the page title and header $page_title = 'Register for Football Trip'; include ('./includes/header.html'); if (isset($_POST['submitted'])) { require_once ('../mysql_connect.php'); $error = false; if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['first_name'])))) { $fn = mysql_real_escape_string($_POST['first_name']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter your first name!</font></p>'; } if (eregi ('^[[:alpha:]\.\'\-]{2,30}$', stripslashes(trim($_POST['last_name'])))) { $ln = mysql_real_escape_string($_POST['last_name']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter your last name!</font></p>'; } if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) { $e = mysql_real_escape_string($_POST['email']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter a correct e-mail address</font></p>'; } if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) { if ($_POST['password1'] == $_POST['password2']) { $p = mysql_real_escape_string($_POST['password1']); }else { $error = true; echo '<p><font color ="red" size="+1"> Your password did not match the confirmed password!</font></p>'; } }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter a valid password!</font></p>'; } if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['post_code'])))) { $pc = mysql_real_escape_string($_POST['post_code']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter the first 4 letters of your Post Code!</font></p>'; } if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['team_supported'])))) { $ts = mysql_real_escape_string($_POST['team_supported']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter the full name of the team you support! i.e Manchester United (you do not need to add FC etc</font></p>'; } if (!$error) { $query ="SELECT user_id FROM users WHERE email='$e'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); if (mysql_num_rows($result) == 0) { $a = md5(uniqid(rand(), true)); $query = "INSERT INTO users (email, pass, first_name, last_name, post_code, team_supported, active, registration_date) VALUES ('$e', '$p', '$fn', '$ln', '$pc', '$ts', '$a', NOW() )"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error()); if (mysql_affected_rows() == 1) { $body = "Thank you for registering with Football Trip. Please use the link below to activate your account:\n\n"; $body .= "http://www.footballtrip.net/activate.php?x=" . mysql_insert_id() . "&y=$a"; mail($_POST['email'],'Registration Comfirmation',$body); echo '<h2> Thank you for registering! A confirmation E-Mail has been sent to your address. Please click on the link in order to activate your account</h2>'; }else { echo '<p><font color="red" size="+1"> You could not be registered due to a system error. We apologize for any inconvenience. </font></p>'; } }else { echo '<p><font color="red" size="+1"> That E-Mail address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>'; } } else { echo '<p><font color="red" size="+1"> Please try again.</font></p>'; } mysql_close(); } ?>
  22. Smee

    Mail Script

    Thanks for the help, To make it a bit clearer when ever an error with the form is returned (Invalid First Name) it does not show the bottom two divs of my web site. The only way i can seem to resolve this is by deleting the die:() from this section. function died($error) { echo "<h1><p>There were error(s) found with the form your submitted.</p></h1>"; echo "<h1><p>These errors appear below.<br /><br /></p></h1>"; echo $error."<p></p>"; die(); } But if i do this then it shows my confirmation html text that is just above the bottom two divs of my website. <h1> <p> Thank you for contacting redrush. </p> </h1> <?php } ?> Thanks again this is driving me insane
  23. Hi all, As you will tell by this pretty simple example of php and the question i'm about to ask, im new to all this so any help would be good! Bascically i have used a pre-written script from a book i have and currently trying to get the layout of the echo errors in a location under the form submit box for each of the first name, last name etc Currently the code works and gives error replys but when trying i either stop it from working or the errors still display at the bottom of the page. Another problem is that if there are any errors made then the script does not show my Div's (footer) at the bottom of the page. I know its a problem with placement of PHP. If anyone can give me some tips i'd be very grateful. <!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>Red Rush Designs</title> <link href="CSS/main.css" rel="stylesheet" type="text/css" /> <link type="text/css" media="screen" rel="stylesheet" href="CSS/colorbox.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="colorbox/jquery.colorbox.js"></script> <script type="text/javascript"> $(document).ready(function(){ //Examples of how to assign the ColorBox event to elements $("a[rel='example1']").colorbox(); $("a[rel='example2']").colorbox({transition:"fade"}); $("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"}); $("a[rel='example4']").colorbox({slideshow:true}); $(".example5").colorbox(); $(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344}); $(".example7").colorbox({width:"80%", height:"80%", iframe:true}); $(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"}); $(".example9").colorbox({ onOpen:function(){ alert('onOpen: colorbox is about to open'); }, onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); }, onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }, onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); }, onClosed:function(){ alert('onClosed: colorbox has completely closed'); } }); //Example of preserving a JavaScript event for inline calls. $("#click").click(function(){ $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here."); return false; }); }); </script> </head> <body> <div id="holder"> <div id="logo"> <object width="970" height="90"> <param name="movie1" value="loadertest2.swf" wmode="transparent"> <embed src="images/loadertest2.swf" width="900" height="90" wmode="transparent"> </embed> </object> </div> <div id="navigation"> <table id="navigation" width="970" height="53" border="0" cellpadding="0" cellspacing="0"> <td> <img src="images/one.png" border="0" width="42" height="53" /></img></td> <td> <a href="index.html"><img src="images/home.png" border="0" width="59" height="53" onmouseover="this.src='images/homeon.png'" onmouseout="this.src='images/home.png'" alt="Red Rush Home" title="Red Rush Home"></a></td> <td> <img src="images/three.png" border="0" width="43" height="53" ></td> <td> <a href="aboutme.html"><img src="images/aboutme.png" border="0" width="123" height="53" onmouseover="this.src='images/aboutmeon.png'" onmouseout="this.src='images/aboutme.png'" alt="About Christopher Rushton" title="About Christopher Rushton"></a></td> <td> <img src="images/five.png" border="0" width="38" height="53" ></td> <td> <a href="designportfolio.html"><img src="images/designportfolio.png" border="0" width="240" height="53" onmouseover="this.src='images/designportfolioon.png'" onmouseout="this.src='images/designportfolio.png'" alt="Design Portfolio" title="Design Portfolio"></a></td> <td> <img src="images/seven.png" border="0" width="53" height="53" ></td> <td> <a href="contact.html"><img src="images/contact.png" border="0" width="105" height="53" onmouseover="this.src='images/contacton.png'" onmouseout="this.src='images/contact.png'" alt="Contact Red Rush" title="Contact Red Rush"></a></td> <td> <img src="images/nine.png" border="0" width="267" height="53"></td> <td rowspan="9"> </table> </div> <div id="content"> <div id="myphoto"> <img src="images/myphoto.png" border="0" usemap="#Christopher Rushton" /> <map name="Christopher Rushton" id="Christopher Rushton"> <area shape="rect" coords="17,154,91,170" href="http://www.facebook.com/people/Chris-Rushton/507874930?ref=search" target="_blank" /> </map> </div> <h1> Contact redrush <br /> <p> <?php if(isset($_POST['email'])) { $email_to = "[email protected]"; $email_subject = "redrush - Contact Form"; function died($error) { echo "<p>There were error(s) found with the form your submitted.</p>"; echo "<p>These errors appear below.<br /><br /></p>"; echo $error."<p></p>"; die(); } if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_from = $_POST['email']; $telephone = $_POST['telephone']; $comments = $_POST['comments']; $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; ?> <form name="contact" method="post" action="send_form_email.php"> <table width="500px"> </tr> <tr> <td valign="top"> <label for="first_name">First Name <font color="#FF0000">*</font></label> </td> <td valign="top"> <p class="submit"><input type="text" name="first_name" maxlength="50" size="30"> </td> </tr> <? $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= '<p>The First Name you entered does not appear to be valid.<br /></p>'; } ?> </p> <tr> <td valign="top"> <label for="last_name">Last Name <font color="#FF0000">*</font></label> </td> <td valign="top"> <p class="submit"><input type="text" name="last_name" maxlength="50" size="30"> </td> </tr> <p> <? if(!eregi($string_exp,$last_name)) { $error_message .= '<p>The Last Name you entered does not appear to be valid.<br /></p>'; } ?> </p> <tr> <td valign="top"> <label for="email">Email Address <font color="#FF0000">*</font></label> </td> <td valign="top"> <p class="submit"><input type="text" name="email" maxlength="80" size="30"> </td> </tr> <p> <? if(!eregi($email_exp,$email_from)) { $error_message .= '<p>The Email Address you entered does not appear to be valid.<br /></p>'; } ?> </p> <tr> <td valign="top"> <label for="telephone">Telephone Number <font color="#FF0000">*</font></label> </td> <td valign="top"> <p class="submit"><input type="text" name="telephone" maxlength="30" size="30"> </td> </tr> <p> <? $string_exp = "^[0-9 .-]+$"; if(!eregi($string_exp,$telephone)) { $error_message .= '<p>The Telphone Number you entered does not appear to be valid.<br /></p>'; } ?> </p> <tr> <td valign="top"> <label for="comments">Comments <font color="#FF0000">*</font></label> </td> <td valign="top"> <textarea name="comments" id="styled" maxlength="250" cols="10" rows="6"></textarea> </td> </tr> <p> <? if(strlen($comments) < 2) { $error_message .= '<p>The Comments you entered do not appear to be valid.<br /></p>'; } ?> </p> <tr> <td colspan="2" style="text-align:center"> <input type="image" name="submit" id="submit" src="images/submit.png"> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#submit').hover( function(){ $(this).attr({ src : 'images/submiton.png'}); }, function(){ $(this).attr({ src : 'images/submit.png'}); } ); }); </script> </td> </tr> </table> </form> <? if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <br /> <br /> <p> Thank you for contacting redrush. </p> </h1> <? } ?> </div> <div id="bottomblacklines"> </div> </div> <div id="footer"> </div> </body> </html>
  24. Great didn't notice it! Thanks mate appreciate it
  25. brilliant thanks, i changed a few things as it reported some errors but it sends the values to mysql. one problem is that it seems to put last name in the first name section of the mysql database. I cant understand why though any ideas? <form action="register.php" method="post"> <fieldset> <p><b> First Name:</b> <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p><b> Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> <p><b> E-Mail Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p><b> Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p> <small> Use only letters and numbers. Must be between 4 and 20 Characters long. </small> <p><b> Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <input type="submit" name="submit" value="Register" /> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php $error = false; if (eregi ('^[[:alpha:]\.\'\-]{2,15}$', stripslashes(trim($_POST['first_name'])))) { $fn = mysql_real_escape_string($_POST['first_name']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter your first name!</font></p>'; } if (eregi ('^[[:alpha:]\.\'\-]{2,30}$', stripslashes(trim($_POST['last_name'])))) { $fn = mysql_real_escape_string($_POST['last_name']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter your last name!</font></p>'; } if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) { $e = mysql_real_escape_string($_POST['email']); }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter a correct e-mail address</font></p>'; } if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))) { if ($_POST['password1'] == $_POST['password2']) { $p = mysql_real_escape_string($_POST['password1']); }else { $error = true; echo '<p><font color ="red" size="+1"> Your password did not match the confirmed password!</font></p>'; } }else { $error = true; echo '<p><font color ="red" size="+1"> Please enter a valid password!</font></p>'; } if (!$error) { $query ="SELECT username FROM users WHERE email='$e'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error()); if (mysql_num_rows($result) == 0) { $a = md5(uniqid(rand(), true)); $query = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', '$p', '$fn', '$ln', '$a', NOW() )"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error()); if (mysql_affected_rows() == 1) { $body = "Thank you for registering with Football Trip. Please use the link below to activate your account:\n\n"; $body .= "http://www.footballtrip.net/activate.php?x=" . mysql_insert_id() . "&y=$a"; mail($_POST['email'],'Registration Comfirmation',$body); echo '<h2> Thank you for registering! A confirmation E-Mail has been sent to your address. Please click on the link in order to activate your account</h2>'; }else { echo '<p><font color="red" size="+1"> You could not be registered due to a system error. We apologize for any inconvenience. </font></p>'; } }else { echo '<p><font color="red" size="+1"> That E-Mail address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>'; } } else { echo '<p><font color="red" size="+1"> Please try again.</font></p>'; } mysql_close(); ?>
×
×
  • 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.