
barrowvian
Members-
Posts
58 -
Joined
-
Last visited
Never
Everything posted by barrowvian
-
I'm not 100% sure if this is the correct section, so if its not then I apologise. I have been looking into implementing some form of payment method onto my website so that I can accept payments. The only thing is there are hundreds if not thousands out there will all sorts of different rates, setup fees etc. Can one recommend one and any particular reason why you feel that is a good one to go for? Thanks
-
combining the form with the processing page
barrowvian replied to barrowvian's topic in PHP Coding Help
anyone else know how to insert it properly? -
combining the form with the processing page
barrowvian replied to barrowvian's topic in PHP Coding Help
iblood, that didnt work it just kept spitting out errors -
combining the form with the processing page
barrowvian replied to barrowvian's topic in PHP Coding Help
Nevermind, I changed the php self bit in the form action to the name of the page (contact.php) and now it works fine. Thank you again for that link -
combining the form with the processing page
barrowvian replied to barrowvian's topic in PHP Coding Help
Thanks for that Siric, it was a good help. That has now left me with this code; <?php include("includes/header.php"); ?> <div id="main"> <div class="container"> <div id="header"> <ul id="menu"> <li><a href="/ads/index.php">Homepage</a></li> <li><a href="/ads/search.php">Search</a></li> <li><a href="/ads/faq.php">FAQ</a></li> <li><a href="/ads/blog.php">Blog</a></li> <li><a href="/ads/contact.php" class="active">Contact</a></li> </ul> <ul id="menu2" name="menu2"> <form action="search.php" method="GET"> <input type="text" name="searchterms" size="20" /> <input type="submit" value="Search"></form> </ul> <div id="logo"></div> </div> <div id="block_featured" class="block"> <img src="images/ribbon_featured.png" class="ribbon" alt="Featured Project"/> <div class="block_inside"> <div class="text_block"> <h2>Contact Me</h2> <?php session_start(); if (isset($_POST['submit'])) { //This checks to see if the submit button is set //process query $name_field = isset($_POST['name']) ? trim($_POST['name']) : ''; $email_field = isset($_POST['email']) ? trim($_POST['email']) : ''; $message = isset($_POST['message']) ? trim($_POST['message']) : ''; $dropdown = $_POST['drop_down']; $flag="OK"; // This is the flag and we set it to OK $msg=""; // Initializing the message to hold the error messages //name validation if (!preg_match("/^[a-zA-Z\-\s]{2,40}$/", $name_field)){ $msg= $msg . "<font color=\"color\">Invalid Name!</font><br />"; $flag="NOTOK"; //setting the flag to error flag. } //email validatin if(!preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $email_field)){ $msg= $msg . "<font color=\"color\">Invalid Email!</font> <br />"; $flag="NOTOK"; //setting the flag to error flag. } //message validation if(strlen($message) < 5 ){ $msg= $msg . "<font color=\"color\">Message must be over 5 characters!</font><br />"; $flag="NOTOK"; //setting the flag to error flag. } if(strlen($message) > 250 ){ $msg= $msg . "<font color=\"color\">Message cannot be over 250 characters!</font><br />"; $flag="NOTOK"; //setting the flag to error flag. } // captcha validation if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { $msg= $msg . "<font color=\"color\">The captcha code does not match!</font><br />"; $flag="NOTOK"; } //check the flag if($flag <>"OK"){ echo "$msg <br /><hr><input type='button' value='Go Back' onClick='history.go(-1)'>"; } //send the email to location based upon result of dropdown menu if($dropdown == "General Enquiries" && $flag == "OK"){ $to = "ENTER EMAIL HERE"; $subject = "General Enquiry"; $body = "From:" . htmlspecialchars($name_field) . "\n E-Mail:" . htmlspecialchars($email_field) . "\n Message:" . htmlspecialchars($message); echo "Your email has been submitted,<strong> " . htmlspecialchars($name_field) . "</strong>. I aim to reply to all emails within 48 hours."; mail($to, $subject, $body); // this is the reply message $reply = "Thank you for your email"; $replybody = "thank you again"; mail($email_field, $reply, $replybody); }elseif($dropdown == "Sales Enquiries" && $flag == "OK"){ $to = "ENTER EMAIL HERE"; $subject = "Sales Enquiry"; $body = "From:" . htmlspecialchars($name_field) . "\n E-Mail:" . htmlspecialchars($email_field) . "\n Message:" . htmlspecialchars($message); echo "Your email has been submitted,<strong> " . htmlspecialchars($name_field) . "</strong>. I aim to reply to all emails within 48 hours."; mail($to, $subject, $body); }elseif($dropdown == "Press Enquiries" && $flag == "OK"){ $to = "ENTER EMAIL HERE"; $subject = "Press Enquiry"; $body = "From:" . htmlspecialchars($name_field) . "\n E-Mail:" . htmlspecialchars($email_field) . "\n Message:" . htmlspecialchars($message); echo "Your email has been submitted,<strong> " . htmlspecialchars($name_field) . "</strong>. I aim to reply to all emails within 48 hours."; mail($to, $subject, $body); }else { // an errror was detected } } else { // insert the form echo '<FORM name="email" action="$_SERVER[\'PHP_SELF\'];" method="post" >'; echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">'; echo '<tr> <td width="9%" align="left" valign="top">Name:</td> <td width="91%"><input type="text" name="name" size="38" /></td> </tr> <tr> <td align="left" valign="top">Email:</td> <td><input type="text" name="email" size="38" /></td> </tr> <tr> <td align="left" valign="top"></td> <td></td> </tr> <tr> <td align="left" valign="top">Subject:</td> <td><select size="1" name="drop_down"> <option>General Enquiries</option> <option>Sales Enquiries</option> <option>Press Enquiries</option> </select></td> </tr> <tr> <td align="left" valign="top">Message:</td> <td><textarea rows="5" name="message" cols="30"></textarea></td> </tr> <tr> <td> </td> <td><p>'; echo '<img src="captcha_code_file.php?rand=' . rand() . '" id=\'captchaimg\' ><br>'; echo '<label for=\'message\'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can\'t read the image? click <a href=\'javascript: refreshCaptcha();\'>here</a> to refresh</small> </p></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit" name="submit" /></td> </tr> </table> </form>'; // echo closed here echo '<script language=\'JavaScript\' type=\'text/javascript\'> function refreshCaptcha() { var img = document.images[\'captchaimg\']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script>'; } ?> </div> </div> </div> </div> </div> <?php include("includes/footer.php"); ?> But when I submit it I get this from google chrome: Oops! This link appears to be broken. And the url is http://localhost/ads/$_SERVER['PHP_SELF']; What do I need to change to get this bit working? -
The below code is what I have for my basic contact form; <form method="POST" action="mailer.php"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="9%" align="left" valign="top">Name:</td> <td width="91%"><input type="text" name="name" size="38" /></td> </tr> <tr> <td align="left" valign="top">Email:</td> <td><input type="text" name="email" size="38" /></td> </tr> <tr> <td align="left" valign="top"></td> <td></td> </tr> <tr> <td align="left" valign="top">Subject:</td> <td><select size="1" name="drop_down"> <option>General Enquiries</option> <option>Sales Enquiries</option> <option>Press Enquiries</option> </select></td> </tr> <tr> <td align="left" valign="top">Message:</td> <td><textarea rows="5" name="message" cols="30"></textarea></td> </tr> <tr> <td> </td> <td><p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p></td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit" name="submit" /></td> </tr> </table> </form> <script language='JavaScript' type='text/javascript'> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script> And the following code is what is included in mailer.php <?php session_start(); if(isset($_POST['submit'])) { $name_field = isset($_POST['name']) ? trim($_POST['name']) : ''; $email_field = isset($_POST['email']) ? trim($_POST['email']) : ''; $message = isset($_POST['message']) ? trim($_POST['message']) : ''; $dropdown = $_POST['drop_down']; $flag="OK"; // This is the flag and we set it to OK $msg=""; // Initializing the message to hold the error messages } //name validation if (!preg_match("/^[a-zA-Z\-\s]{2,40}$/", $name_field)){ $msg= $msg . "<font color=\"color\">Invalid Name!</font><br />"; $flag="NOTOK"; //setting the flag to error flag. } //email validatin if(!preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $email_field)){ $msg= $msg . "<font color=\"color\">Invalid Email!</font> <br />"; $flag="NOTOK"; //setting the flag to error flag. } //message validation if(strlen($message) < 5 ){ $msg= $msg . "<font color=\"color\">Message must be over 5 characters!</font><br />"; $flag="NOTOK"; //setting the flag to error flag. } if(strlen($message) > 250 ){ $msg= $msg . "<font color=\"color\">Message cannot be over 250 characters!</font><br />"; $flag="NOTOK"; //setting the flag to error flag. } // captcha validation if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { $msg= $msg . "<font color=\"color\">The captcha code does not match!</font><br />"; $flag="NOTOK"; } //check the flag if($flag <>"OK"){ echo "$msg <br /><hr><input type='button' value='Go Back' onClick='history.go(-1)'>"; } //send the email to location based upon result of dropdown menu if($dropdown == "General Enquiries" && $flag == "OK"){ $to = "ENTER EMAIL HERE"; $subject = "General Enquiry"; $body = "From:" . htmlspecialchars($name_field) . "\n E-Mail:" . htmlspecialchars($email_field) . "\n Message:" . htmlspecialchars($message); echo "Your email has been submitted,<strong> " . htmlspecialchars($name_field) . "</strong>. I aim to reply to all emails within 48 hours."; mail($to, $subject, $body); // this is the reply message $reply = "Thank you for your email"; $replybody = "thank you again"; mail($email_field, $reply, $replybody); }elseif($dropdown == "Sales Enquiries" && $flag == "OK"){ $to = "ENTER EMAIL HERE"; $subject = "Sales Enquiry"; $body = "From:" . htmlspecialchars($name_field) . "\n E-Mail:" . htmlspecialchars($email_field) . "\n Message:" . htmlspecialchars($message); echo "Your email has been submitted,<strong> " . htmlspecialchars($name_field) . "</strong>. I aim to reply to all emails within 48 hours."; mail($to, $subject, $body); }elseif($dropdown == "Press Enquiries" && $flag == "OK"){ $to = "ENTER EMAIL HERE"; $subject = "Press Enquiry"; $body = "From:" . htmlspecialchars($name_field) . "\n E-Mail:" . htmlspecialchars($email_field) . "\n Message:" . htmlspecialchars($message); echo "Your email has been submitted,<strong> " . htmlspecialchars($name_field) . "</strong>. I aim to reply to all emails within 48 hours."; mail($to, $subject, $body); }else { // an errror was detected } ?> Is there a way that I can have it all on one page rather than 2? And also to include the error message for each field opposite? How would I go about achieving this? Thanks
-
Solved it it was actually quite easy when going through it section by section. I simply implemented a flag variable and checked if it was ok or not like so; <?php include("includes/header.php"); ?> <div id="main"> <div class="container"> <div id="header"> <ul id="menu"> <li><a href="/ads/index.php">Homepage</a></li> <li><a href="/ads/search.php" class="active">Search</a></li> <li><a href="/ads/faq.php">FAQ</a></li> <li><a href="/ads/blog.php">Blog</a></li> <li><a href="/ads/contact.php">Contact</a></li> </ul> <ul id="menu2" name="menu2"> <form action="search.php" method="GET"> <input type="text" name="searchterms" size="20" /> <input type="submit" value="Search"></form> </ul> <div id="logo"></div> </div> <div id="block_featured" class="block"> <img src="images/ribbon_featured.png" class="ribbon" alt="Featured Project"/> <div class="block_inside"> <div class="text_block"> <form action="search.php" method="GET"> <b>Enter Search Term:</b> <input type="text" name="searchterms" size="30"> <input type="submit" value="Search"> </form><br /> <?php $flag = "OK"; // creates an array for the errros to be stored. if (isset($_GET['searchterms'])) { $searchTerms = trim($_GET['searchterms']); // trims the white space from searchterms $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { echo "Search terms must be longer than 3 characters."; $flag = "NOTOK"; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } if (strlen($searchTerms) > 50) { echo "Search terms must be shorter than 50 characters."; $flag = "NOTOK"; } // If there are no errors, lets get the search going. if ($flag =="OK"){ //sql fulltext statement against words/phrase user enters $sql = "SELECT *, MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') AS score FROM adverts WHERE MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0, 500"; $result = mysql_query($sql); //display an error if the query returns no results if (mysql_num_rows($result) < 1 && strlen($searchTerms) > 3 && strlen($searchTerms) < 50) { echo "No results found for <strong>{$searchTerms}</strong>."; $flag = "NOTOK"; } if ($flag =="OK"){ $row = mysql_fetch_assoc($result); $max_score = 0; $data = array(); echo "Your search: <strong>{$searchTerms}</strong> returned; <br /><br />"; echo '<table width="100%" table border="0" style="border-width: 1px; border-color:#000000; border-style: solid;" cellspacing="0" cellpadding="2">'; echo '<tr>'; echo "<td width=\"15%\" style=\"background-color: #00C\" style=\"color:white\">" . "<font color=\"white\"><strong>Relevance</font></strong>" . " " . "</td>" . "<td width=\"20%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Logo</font></strong>" . " " . "</td>" . "<td width=\"35%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Company</font></strong>" . " " . "</td>" . "<td width=\"30%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Link</font></strong>" . " " . "</td>"; echo '</tr>'; do { // results are already based upon relevance. this turns relevance into a % if($row['score'] > $max_score){ $max_score = $row['score']; } //we can assume on the first run this wil be the max score. echo '<tr>'; echo "<td style=\"background-color: #e1e1e1\">" . @number_format(($row['score']/$max_score)*100,0)."%" . " " . "</td>" . "<td style=\"background-color: #e1e1e1\">" . $row['image_link'] . " " . "</td>" . "<td style=\"background-color: #e1e1e1\">" . $row['company_name'] . " " . "</td>" . "<td style=\"background-color: #e1e1e1\">" . $row['company_link'] . "<br />" . "</td>"; echo '</tr>'; }while($row = mysql_fetch_assoc($result)); } } } echo '</table>'; ?> </div> </div> </div> </div> </div> <?php include("includes/footer.php"); ?>
-
I tried switch to exit(); but no luck. Then realised about testing with echoes etc and found that this problem is only occurring when the exit(); has been applied. If I remove them then the footer appears but Im now left with the basic outline of the empty table upon each error so just need to sort out where to stop the code now.
-
could someone take a quick look at this please; i know the codes a bit messy at the moment <?php include("includes/header.php"); ?> <div id="main"> <div class="container"> <div id="header"> <ul id="menu"> <li><a href="/ads/index.php">Homepage</a></li> <li><a href="/ads/search.php" class="active">Search</a></li> <li><a href="/ads/faq.php">FAQ</a></li> <li><a href="/ads/blog.php">Blog</a></li> <li><a href="/ads/contact.php">Contact</a></li> </ul> <ul id="menu2" name="menu2"> <form action="search.php" method="GET"> <input type="text" name="searchterms" size="20" /> <input type="submit" value="Search"></form> </ul> <div id="logo"></div> </div> <div id="block_featured" class="block"> <img src="images/ribbon_featured.png" class="ribbon" alt="Featured Project"/> <div class="block_inside"> <div class="text_block"> <form action="search.php" method="GET"> <b>Enter Search Term:</b> <input type="text" name="searchterms" size="30"> <input type="submit" value="Search"> </form><br /> <?php $error = array(); // creates an array for the errros to be stored. $results = array(); if (isset($_GET['searchterms'])) { $searchTerms = trim($_GET['searchterms']); // trims the white space from searchterms $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { echo "Search terms must be longer than 3 characters."; exit; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } if (strlen($searchTerms) > 50) { echo "Search terms must be shorter than 50 characters."; exit; } // If there are no errors, lets get the search going. if (count($error) < 1) { //sql fulltext statement against words/phrase user enters $sql = "SELECT *, MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') AS score FROM adverts WHERE MATCH(company_name, search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0, 500"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $max_score = 0; $data = array(); //display an error if the query returns no results if (mysql_num_rows($result) < 1 && strlen($searchTerms) > 3 && strlen($searchTerms) < 50) { echo "No results found for <strong>{$searchTerms}</strong>."; exit; } echo "Your search: <strong>{$searchTerms}</strong> returned; <br /><br />"; echo '<table width="100%" table border="0" style="border-width: 1px; border-color:#000000; border-style: solid;" cellspacing="0" cellpadding="2">'; echo '<tr>'; echo "<td width=\"15%\" style=\"background-color: #00C\" style=\"color:white\">" . "<font color=\"white\"><strong>Relevance</font></strong>" . " " . "</td>" . "<td width=\"20%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Logo</font></strong>" . " " . "</td>" . "<td width=\"35%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Company</font></strong>" . " " . "</td>" . "<td width=\"30%\" style=\"background-color: #00C\">" . "<font color=\"white\"><strong>Link</font></strong>" . " " . "</td>"; echo '</tr>'; do { // results are already based upon relevance. this turns relevance into a % if($row['score'] > $max_score){ $max_score = $row['score']; } //we can assume on the first run this wil be the max score. echo '<tr>'; echo "<td style=\"background-color: #e1e1e1\">" . @number_format(($row['score']/$max_score)*100,0)."%" . " " . "</td>" . "<td style=\"background-color: #e1e1e1\">" . $row['image_link'] . " " . "</td>" . "<td style=\"background-color: #e1e1e1\">" . $row['company_name'] . " " . "</td>" . "<td style=\"background-color: #e1e1e1\">" . $row['company_link'] . "<br />" . "</td>"; echo '</tr>'; }while($row = mysql_fetch_assoc($result)); } } echo '</table>'; ?> </div> </div> </div> </div> </div> <?php include("includes/footer.php"); ?> Basically, when the page is called up the footer appears as normal, and when there is a valid search (with results) the footer is there as normal. But is I enter whilst the field is blank, or if i enter a field over 50 characters or a keyword that doesnt exist in the database then when the page is reloaded the footer is missing :/ can anyone see a way to correct this? thanks
-
nevermind. ive got the results i was after by removing the arrays and simply using echo instead!
-
no that didnt fix the problem, i dont understand it really cause it seems the same process as the tutorial and when i followed that it worked properly :/
-
Ive messed around with it a bit and have found that I can echo the result aslong as I am not using an array.....which is probably why the errors array isnt working either. Can anyone see what the problems are with the arrays?
-
also, the error messages are not showing :/
-
Right, I've attempted to make a simple search using fulltext and based it around the simple search that you can find in the tutorial section here on phpfreaks, this is what I have; <?php $error = array(); // creates an array for the errros to be stored. $results = array(); if (isset($_GET['searchterms'])) { $searchTerms = trim($_GET['searchterms']); // trims the white space from searchterms $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } if (strlen($searchTerms) > 50) { $error[] = "Search terms must be shorter than 50 characters."; } // If there are no errors, lets get the search going. if (count($error) < 1) { $sql = mysql_query("SELECT company_name, image_link FROM adverts WHERE MATCH(company_name,search_data) AGAINST('%$_GET[searchterms]%') LIMIT 0,$_GET[results]"); if (mysql_num_rows($sql) < 1) { $error[] = "No results found for {$searchTerms}."; }else{ $results = array(); // the result array $i = 1; while ($row = mysql_fetch_array($sql)) { $results[] = "{$i}: {$row['company_name']}<br />{$row['image_link']}<br /><br />"; $i++; } } } } ?> My problem is that it is not displaying anything at all even when there is data in the table. Also, how would I go about displaying the results by relevance. I know fulltext search does this already but how do I display the actual relevance scale for the user to see? Thanks
-
editing the simple search tutorial found here on phpfreaks
barrowvian replied to barrowvian's topic in PHP Coding Help
anyone? -
Hi, Ive been playing around with the simple search tutorial that is provided here on php freaks but have a question or two about how to change it. So far I have it edited for my own requirements; <?php // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT * FROM adverts WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['cname'])?"`company_name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['desc'])?"`search_data` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`search_data` LIKE '%{$searchTermDB}%'"; // use the search data as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `company_name`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['company_name']}<br />{$row['search_data']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <style type="text/css"> #error { color: red; } </style> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Search For: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> Search In:<br /> Company Name: <input type="checkbox" name="cname" value="on" <?php echo isset($_GET['cname'])?"checked":''; ?> /> | Description: <input type="checkbox" name="desc" value="on" <?php echo isset($_GET['desc'])?"checked":''; ?> /><br /> Match All Selected Fields? <input type="checkbox" name="matchall" value="on" <?php echo isset($_GET['matchall'])?"checked":''; ?><br /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> However, Im wanting to adjust it so that if a user searches using multiple keywords then it can identify that there is more than one. So far, if a user searches clothes and clothing then it will give me the results, as both of these keywords are located within the same row of data. But if the user searched for example clothes and mcdonalds then it just gives an errror message rather than finding all of the rows with clothes and mcdonalds in them. Also, is there any way to order the results by relevance? thanks
-
Excellent! Thank you the182guy. Took your other advice on board and editing to make sure the data is valid
-
Hi, ive been toying around with a simple validation form and have 2 out of 3 parts working. The only thing that isnt working is the date of birth part. Ive basically got a form that loops if invalid data is inserted and Im wanting the values of 'day', 'month' and 'year' to be recognised as errors and to continue if the values are anything else. Code is a little messy at the moment but Id appreciate it if someone could help me out, thanks <?php include("includes/header.php"); ?> <?php // USER ENTERED VARIABLES $firstname = isset($_POST['firstname']) ? trim($_POST['firstname']) : ''; $surname = isset($_POST['surname']) ? trim($_POST['surname']) : ''; $day = isset($_POST['day']); $month = isset($_POST['month']); $year = isset($_POST['year']); // USER ENTERED VALIDATION if (!preg_match("/^[a-zA-Z\-]{2,25}$/", $firstname)) $errorFirstname = true; if (!preg_match("/^[a-zA-Z\-]{2,25}$/", $surname)) $errorSurname = true; if ($day == 'day') $errorDob1 = true; if ($month == 'month') $errorDob2 = true; if ($year == 'year') $errorDob3 = true; // FORM FUNCTION function showForm($errorFirstname=false,$errorSurname=false, $errorDob1=false, $errorDob2=false, $errorDob3=false){ if ($errorFirstname) $errorTextFirstname = "Invalid Entry (A-Z only)"; if ($errorSurname) $errorTextSurname = "Invalid Entry (A-Z only)"; if ($errorDob1) $errorTextDob1 = "Invalid Day Entry"; if ($errorDob2) $errorTextDob2 = "Invalid Month Entry"; if ($errorDob3) $errorTextDob3 = "Invalid Year Entry"; echo '<form action="createaccount.php" method="POST"><table>'; echo '<table width="650" border="0" cellspacing="0" cellpadding="0">'; // FIRSTNAME echo '<tr> <td width="200"> First Name: </td> <td width="200"> <input name="firstname" type="text" id="firstname" size="38"></td> <td width="250" align="center"> '; if ($errorFirstname) echo "$errorTextFirstname"; echo '</td>'; echo '</tr>'; // SURNAME echo '<tr> <td width="100"> Surname: </td> <td width="200"> <input name="surname" type="text" id="surname" size="38"></td> <td width="250" align="center"> '; if ($errorSurname) echo "$errorTextSurname"; echo '</td>'; echo '</tr>'; // DATE OF BIRTH echo '<tr> <td width="100">Date of Birth: </td> <td width="200">'; // DAY echo '<select name="day" id="day">'; echo '<option value="day">Day</option>'; include("includes/day.php"); echo '</select>'; // MONTH echo '<select name="month" id="month">'; echo '<option value="month">Month</option>'; include("includes/month.php"); echo '</select>'; //YEAR echo '<select name="year" id="year">'; echo '<option value="year">Year</option>'; include("includes/year.php"); echo '</select>'; echo '<td width="250" align="center">'; if ($errorDob1) echo "$errorTextDob1"; if ($errorDob2) echo "$errorTextDob2";if ($errorDob3) echo "$errorTextDob3";echo '</td>'; echo '</tr>'; // SUBMIT AND END OF FORM echo '<tr><td><input type="submit" name="SubmitForm" value="Send"></td></tr>'; echo '<form>'; } if (!isset($_POST['SubmitForm'])) { showForm(); } else { //Init error variables $errorFirstname = false; $errorSurname = false; $errorDob1 = false; $errorDob2 = false; $errorDob3 = false; $firstname = isset($_POST['firstname']) ? trim($_POST['firstname']) : ''; $surname = isset($_POST['surname']) ? trim($_POST['surname']) : ''; $day = isset($_POST['day']); $month = isset($_POST['month']); $year = isset($_POST['year']); if (!preg_match("/^[a-zA-Z\-]{2,25}$/", $firstname)) $errorFirstname = true; if (!preg_match("/^[a-zA-Z\-]{2,25}$/", $surname)) $errorSurname = true; if ($day == 'day') $errorDob1 = true; if ($month == 'month') $errorDob2 = true; if ($year == 'year') $errorDob3 = true; // Display the form again as there was an error if ($errorFirstname || $errorSurname || $errorDob1 || $errorDob2 || $errorDob3) { showForm($errorFirstname,$errorSurname, $errorDob1, $errorDob2, $errorDob3); echo $_POST['day'] . $_POST['month'] . $_POST['year']; } else { $dob = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day']; echo 'Submission was success!'; } } ?>
-
displaying an image using php within the img src
barrowvian replied to barrowvian's topic in PHP Coding Help
Just deleted this message.........cause I found the mistake. My bad ha. Problem fixed though. -
displaying an image using php within the img src
barrowvian replied to barrowvian's topic in PHP Coding Help
ok Ive just given that a go but still nothing, it just displays the border of the image with the alt "photo gallery" inside. Ive checked the source and the dir is fine but still its not outputting the image properly :-\ -
I am wanting to dynamically display an image. So far I have got; <img style="border: 1px black solid" alt="Photo gallery" src="<?php $image_path . "profile.jpg"; ?>" id="tempGallery" width="160" height="160"> with $image_path being the directory which is called from a cookie. I could not include profile.jpg within the cookie as I use that for other parts of the site. All Im wanting to do is display the profile image, but I do need the $image_path in there also. Thanks
-
Dynamic image upload with incremental filenames
barrowvian replied to barrowvian's topic in PHP Coding Help
^^ -
Dynamic image upload with incremental filenames
barrowvian replied to barrowvian's topic in PHP Coding Help
thanks, i check that link out and gave it a try but to be honest i prefer the original way of doing it as i can upload multiple files at the same time already. all im really wanting to do is be able to shrink the amount of code i use on upload.php and have it automatically rename the files based on how many are uploaded. For example, if 5 files are uploaded then they will be named file1, file2, file3, file4, file5. i think it would be done with an increment feature but not sure what the best way of implementing it would be? -
Basically, I have 3 files at the moment; the form, upload.php and a includes file. The form; <form action="./upload.php" method="post" enctype="multipart/form-data"> <p> <label for="file">Select file 1:</label> <input type="file" name="profileimg" id="file"> <br /> <label for="file">Select file 2:</label> <input type="file" name="userfile2" id="file"> <br /> <label for="file">Select file 3:</label> <input type="file" name="userfile3" id="file"> <br /> <button>Upload File</button> <p> </form> upload.php <?php include("includes/header.php"); ?> <?php // Configuration of profile image $filename = $_FILES['profileimg']['name']; // Get the name of the file (including file extension). if ($filename == $_FILES['profileimg']['name']){ $img = "profileimg"; $imgname = "profile"; include("includes/test2.php"); } ?> <?php // Configuration of profile image $filename = $_FILES['userfile2']['name']; // Get the name of the file (including file extension). if ($filename == $_FILES['userfile2']['name']){ $img = "userfile2"; $imgname = "userfile2"; include("includes/test2.php"); } ?> <?php // Configuration of profile image $filename = $_FILES['userfile3']['name']; // Get the name of the file (including file extension). if ($filename == $_FILES['userfile3']['name']){ $img = "userfile3"; $imgname = "userfile3"; include("includes/test2.php"); } ?> <?php include("includes/footer.php"); ?> and the includes file; <?php $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation. $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB). $upload_path = $_COOKIE['tmp']; // upload files to. called from cookie tmp from newuser.php $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. $pathinfo = pathinfo($_FILES["$img"]['name']); //gets the information about the file path??? // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES["$img"]['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Upload the file to your specified path and renames this file to 'profile' and keeps the same extension. if(move_uploaded_file($_FILES["$img"]['tmp_name'],$upload_path . "$imgname." . $pathinfo['extension'])) echo 'Upload Successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a><br />'; else echo 'There was an error during the file upload. Please try again.'; ?> At the moment it all works fine. I can upload all 3 files to a temporary directory that I created earlier and all are renamed so that I can display them with ease later on. Im after tidying it up a bit now to be honest, ideally on the upload.php page. What Im wanting to do is combine this part; <?php // Configuration of profile image $filename = $_FILES['userfile2']['name']; // Get the name of the file (including file extension). if ($filename == $_FILES['userfile2']['name']){ $img = "userfile2"; $imgname = "userfile2"; include("includes/test2.php"); } ?> <?php // Configuration of profile image $filename = $_FILES['userfile3']['name']; // Get the name of the file (including file extension). if ($filename == $_FILES['userfile3']['name']){ $img = "userfile3"; $imgname = "userfile3"; include("includes/test2.php"); } ?> <?php include("includes/footer.php"); ?> so that there is only one block of code. Is it possible to increment the file names so that theyre simply stored as 1 and 2? If so, how would I go about implementing this? This way it would allow me to extend the form to upload more images without having to add any additional code to upload.php Thanks
-
ah right, i didnt realise that move_uploaded_file() could be used to rename the file too. i implemented your advice and it worked perfectly and has made displaying the images so much easier, thank you