Jump to content

mdmartiny

Members
  • Posts

    188
  • Joined

  • Last visited

Everything posted by mdmartiny

  1. Hello Everyone, I have created a form for a personal project that I am working on. I have some error checking and stuff in the form but what I would like to happen is when an error has occurred for the page to reopen the form with the error message. I know that this can be done with the header function. But how do I get the form to display the error. Here is the block of code that I am working with if ($file_error > 0) { header ('Location: add_category.php'); echo "There was an error uploading file."; } else { if ($file_type != $image_array) { header ('Location: add_category.php'); echo "Invalid Image Type"; } if ($file_name == FALSE) { header ('Location: add_category.php'); echo "Please choose a image for your category"; } if ($file_size > 5000000) { header ('Location: add_category.php'); echo "File size is to large. Images must be smaller than 5MB."; } if (str_word_count($description) > 300) { header ('Location: add_category.php'); echo "<p>category description must be less than 300 words<br />You have '.str_word_count($description).' words</p>"; } This is the form code that I am working with <div id="content"> <form id="add_cat_form" name="add_cat_form" action="do_category.php" method="post" enctype="multipart/form-data"> <fieldset> <legend><p>Add Category</p></legend> <p> <label for="cat_name">Category Name:</label> <input class="input_box" type="text" name="cat_name" id="cat_name" /> </p> <p> <label for="cat_image">Category Image:</label> <input class="file" type="file" name="cat_image" id="cat_image" /> </p> <p> <label for="cat_desc">Description:</label><br /><textarea class="cat_desc" name="cat_desc" id="cat_desc"></textarea><br /> <span id="word_count">300 words Max</span> </p> <input class="submit_button" type="submit" value="Add Category" /> </fieldset> </form> </div>
  2. oh ok ..... I thought that had to be part of the function... Thank You
  3. function count_words($description){ $word_count = 0; $punctuation = array('.', ',', '!', '?', ':', ';', '(', ')'); $description = str_replace($punctuation, '', $description); $description = trim(preg_replace("/\s+/"," ",$description)); $word_array = explode(" ", $description); for($i=0; $i < count($word_array); $i++){ if (preg_match("[0-9A-Za-z]", $word_array[$i])) { $word_count++; } return $word_count; } }
  4. I made the changes to it.. Now all I am is getting the number 0 when I should be getting the number 2.
  5. I am writing a function to count the words that have been typed into a text box. I originally had it working when I first wrote it but it was counting all of the punctuation as a word so I I tried adding some code to eliminate that. Now it is not working. Could someone help me? Here is my code function count_words($description){ $word_count = 0; $description = trim(preg_replace("/\s+/"," ",$description)); $word_array = explode(" ", $description); for($i=0; $i < count($word_array); $i++){ if (preg_match("[0-9A-Za-z]", $word_array[$i])) { $word_count++; } return $word_count; } }
  6. Thanks for all of the ideas. I have been trying to get some work from local businesses and such. Just trying to start somewhere. I have sent out letters and cold calling people. So far nothing so I think I am going to expand my area of looking and see what I can come up with.
  7. I am trying to write the code to do what I want but nothing I am doing is working. Could someone please give me a hand with it. This is what I have written so far. <p> <label for="category">Category:</label><select name="category" id="category"> <option selected="selected" disabled="disabled" value="Select a Category">Select a Category......</option> <?php $select_sql = "SELECT * FROM category ORDER BY cat_id"; $cat_select = mysql_query($select_sql); while ($row = mysql_fetch_assoc($cat_select)) { echo "<option value=\"" . $row['cat_id'] . "\">" . $row['category'] . "</option>\n "; } ?> </select> </p> <script> var category = $('#category').val(); var cat_id =$('#category option:selected').data(); $('#make').change(function(){ $.post ('includes/sub_functions.php', {category:category, cat_id:cat_id}, function(data) { $('#sub_category').html(data) }); }); </script> <p> <label for='sub_category'>Sub Category:</label><select name='sub_category' id='sub_category'> <option selected="selected" value='Select a Sub Category'>Select a Sub Category......</option> </select> </p> This is the function page <?php include('connection.php'); connect(); if(isset($_POST['category'])){ $cat_id = mysql_real_escape_string($_POST['cat_id']); $sub_sql = "Select * from sub_cat, category where sub_cat.cat_id = category.$cat_id"; $sub_select = mysql_query($sub_sql); while ($row = mysql_fetch_assoc($sub_select)) { echo "<option value=\"" . $row['sub_cat_id'] . "\">" . $row['sub_cat'] . "</option>\n "; } } ?>
  8. Hello Everyone, I have a select box with my main categories in it. Depending on what is selected by the user in the selection box another selection box will pop up with sub categories. I am not sure how to get it to open the subcategory selection box. I do not want the selection box with the sub categories in it showing at first. It would be after something has been chosen in the category selection box.
  9. Where does everyone find new work? How do you market yourself?
  10. Thank you for the help.. I goggled some more and found a solution to my situation. I am just know trying to find somewhere that I can learn about Jquery,
  11. Hello Everyone, I have written some code for my version of a like button. So visitors can "like" pages in my website. What I did was use a submit button to make the like button. But just like other submit buttons when you click the page refreshes and it throws of the page view counter. What I am looking to do is use Jquery and Ajax to get the likes from the database and place them on the page without refreshing the page. Since I am a complete newbie when it come to them. I do not know where to begin or to even look. I am hoping that someone can point me in the right direction so that I may start learning how to use Ajax and Jquery. <?php function like_add() { $last = $_GET['l']; $first = $_GET['f']; $ip = $_SERVER['REMOTE_ADDR']; $like_sql = 'Select * from `counter` where first = "' . $first . '" and last = "' . $last . '"'; $like_result = mysql_query($like_sql); $like_row = mysql_fetch_assoc($like_result); $like = $like_row['likes']; echo "Likes $like"; echo '<form name="like_add_form" action="" method="POST" class="like_add"> <input type="submit" name="like_add" class="like_add_button" value="Like Me" /> </form>'; if (isset($_POST['like_add'])) { $page_id_sql = "SELECT `page_id` FROM `counter` WHERE first = '$first' AND last = '$last'"; $page_id_result = mysql_query($page_id_sql); $page_id_row = mysql_fetch_assoc($page_id_result); $page_id = $page_id_row['page_id']; $voted_sql = "Select * FROM `liked_ip` where ip ='$ip' AND page_id='$page_id'"; $voted_result = mysql_query($voted_sql); $voted_num_rows = mysql_num_rows($voted_result); if ($voted_num_rows != 0) { echo '<div class="error">You have all ready liked this signature</div>'; } else { mysql_query("INSERT into `liked_ip` (id,page_id,ip) VALUES ('','$page_id','$ip')") or die(mysql_error()); mysql_query("UPDATE counter SET `likes` = `likes` + 1 WHERE first = '$first' AND last = '$last'") or die(mysql_error()); } } } ?>
  12. The makes sense. I will have to try it when I get in front of a computer. Thanks for the help.
  13. So then I need to assign am variable to the array. Something like $page_id = mysql_fetch_assoc($result); Right?
  14. Let's see if I hot this right. From what I read from foing some searching. I run the query and it its everything in a array. Using the mysql_fetch_assoc makes it an associative one. Will that work if I only want info from one row on table
  15. So I have to use a while loop to get the resource into an integar. Or is there some other way?
  16. I am in the process of creating a like system for a personal website that I am working on. I am trying to pull information from one database and use that to place info into another database. When I do I get resource error #15. This is my code that I have so far function like_add() { $last = $_GET['l']; $first = $_GET['f']; $ip = $_SERVER['REMOTE_ADDR']; $like_sql = "Select * from `counter` where first = ' $first ' and last = '$last '"; $like_result = mysql_query($like_sql); $likes = '<p class="like_button"> Likes '; while ($like_row = mysql_fetch_assoc($like_result)) { $like = $like_row['likes']; $likes .= " $like"; } $likes .= '</p>'; echo "$likes"; echo '<form name="like_add_form" action="" method="POST" class="like_add"> <input type="submit" name="like_add" class="like_add_button" value="Like Me" /> </form>'; if (isset($_POST['like_add'])) { $page_id = "SELECT `page_id` FROM `counter` WHERE first = '$first' AND last = '$last'"; $page_id_result = mysql_query($page_id); echo $page_id_result; <----- Here I am trying to pull information from a field in my database to use as a variable and to place in the second database $voted = mysql_query("Select * FROM `liked_ip` where ip ='$ip' AND page_id='$page_id_result'"); <----- Here I want to use the information from the first table to place in the second one if (mysql_num_rows($voted) != 0) { echo "You have all ready liked this post"; } else { mysql_query("INSERT into `liked_ip`(id,page_id,ip) VALUES ('$page_id_result','$ip')"); } if (mysql_num_rows($voted) == 0) { mysql_query("UPDATE counter SET `likes` = `likes` + 1 where first = '$first' AND last = '$last'"); } } } I know that I have to be doing something so simple that I am just not seeing it this late at night. I may even be completely wrong in all of this. If someone could please help me out I would appreciate it very much.
  17. With a Union don't the tables need to be the same? Or am I reading it wrong about them?
  18. I created a search function for a website that I am working on. Right now it is only searching one table. I would like to make it so it searches two tables. I am trying to do this the simplest way possible. So as not to clutter up my code anymore than I have two. The way that I have been trying to get it to do it is Select * from ttmautos, inperson_autos Where inperson_autos.l_name = 'something' or ttmautos.l_name = 'something' When I use this code I get repeated rows from the table. When I was searching online to see if I could figure out what the problem was and most things I read always used AND. The information does not need to be in both tables. When they are using the search feature of the site. The information could be in either table or in could pull from both tables. I have read about Joins. I am not sure if I am to new to MySql to understand them. I have also read about unions and what I understand is that both tables have to have the same number of columns and same type of field data. Both of my tables do not have the same number of columns. I would appreciate any help on this issue.
  19. It worked.. Once I changed this Everything worked fine. Thanks Paul Ryan
  20. This is what I get when I do that SELECT * FROM `ttmautos` WHERE `l_name` LIKE '%%' Array ( [0] => )
  21. I think I may of found where the problem is in the code but not sure of what I am doing wrong. When I echo out the $results query. $where = ""; $keywords = preg_split('/[\s+]/', $keywords); $total = count($keywords ); foreach($keywords as $key=>$keyword) { $where .= "`l_name` LIKE '%$keyword%'"; if($key != ($total - 1)){ $where .= "OR"; } } $results = "SELECT * FROM `ttmautos` WHERE $where"; echo $results; This is what I am getting SELECT * FROM `ttmautos` WHERE `l_name` LIKE '%%'
  22. I am trying to write a script that will allow me visitors to my site to search my database for items. I followed a tutorial that I had found and tweaked it to fit my needs. I am not getting any results it keeps telling that there was no search results found. Even though I have the items that I have been testing on in my database. I have two files the main search.php file and the search_func.php file Here is the search.php file <form method='post' action='search.php'> <fieldset> <input type='text' name='search' id='search' value='type name here'/> <input type='submit' name='search_submit' id='search_submit' value='search'/> </fieldset> </form> <?php include('includes/search_func.php'); if(isset($_POST['search'])) { $keywords = mysql_real_escape_string(htmlentities(trim($_POST['search']))); $errors = array (); if (empty($keywords )){ $errors[] = 'Please enter a search term'; } else if (strlen($keywords ) < 3 ) { $errors[] = 'Search term must be more then three characters long'; } else if (search_results($keywords == false)) { $errors[] = 'Your search for ' .$keywords . ' showed no results'; } if (empty($errors)) { $results = search_results($keywords ); $results_num = count($results); $suffix = ($results_num != 1) ? 's' : ''; echo 'Your search for <strong>'. $keywords .'</strong> returned <strong>' .$results_num.'</strong> result'.$suffix.''; foreach($results as $result) { echo $result['first']; } } else { foreach($errors as $error){ echo $error; } } } ?> Here is the search_func.php file <?php include('includes/config.php'); connect(); function search_results($keywords ) { $returned = array(); $where = ""; $keywords = preg_split('/[\s+]/', $keywords ); $total = count($keywords ); foreach($keywords as $key=>$keyword) { $where .= "`l_name` LIKE '%$keyword%'"; if($key != ($total - 1)){ $where .= "OR"; } } $results = "SELECT `l_name`,`f_name`,`image`,`item_return` FROM `ttmautos` WHERE $where"; $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results): 0 ; if ($results_num === 0) { return false; } else { while($results_row = mysql_fetch_assoc($results)) { $returned_results[] = array( 'last' => $results_row['l_name'], 'first' => $results_row['f_name'], 'image' => $results_row['image'], 'item' => $results_row['item_return'] ); } return $returned_results; } } ?> If anyone could give me an idea of what I am doing wrong I would appreciate it.
  23. Thank you for the help
  24. How do I make it so that I do not get the undefined index messages for each of the fields. I tried making it an if statement but that did not work. I do not want there to be anything in the field unless it is set.
  25. I am writing an email form for my site with some simple validation. I have the error messages working just fine. They do what they are supposed to do. However, when the form is brought back up to have the errors fixed. It puts a "1" in the field box. I looked at the code and I do not see where the "1" is coming from. I am also in the process of trying to figure out how to send email through my mail account using smtp. I want to see if it is going to send me the information that I ask for or the "1". Currently all of my work is being done on my localhost server Here is the code that I am using <?php $email_form = "<form action='' target='' id='contactform' method='post'>\n"; $email_form .="<p class='form_header'>Contact us</p>\n"; $email_form .= "<fieldset>\n"; $email_form .= "<P>\n"; $email_form .= "<label for='name'><em>*</em> Your Name:</label>\n"; $email_form .= "<input type='text' name='name' id='name' value=".(isset($_POST['name']))." />\n"; $email_form .= "</p>\n"; $email_form .= "<p>\n"; $email_form .= "<label for='email'><em>*</em> E-mail:</label>\n"; $email_form .= "<input type='text' name='email' id='email' value=".(isset($_POST['email']))." />\n"; $email_form .= "</p>\n"; $email_form .= "<p>\n"; $email_form .= "<label for='subject'>Subject:</label>\n"; $email_form .= "<input type='text' name='subject' id='subject' value=".(isset($_POST['subject']))." />\n"; $email_form .= "</p>\n"; $email_form .= "<p>\n"; $email_form .= "<label for='message'><em>*</em> Message:</label>\n"; $email_form .= "<textarea name='message' id='message'>".(isset($_POST['message']))."</textarea>\n"; $email_form .= "</p>\n"; $email_form .= "<input type='submit' id='submit' value='Submit!' name='submitted' /><br />\n"; $email_form .= "<p class='required'>Fields marked with an asterik(*) are required</p>\n"; $email_form .= "</fieldset>\n"; if (!isset($_POST['submitted'])) { echo "$email_form"; } else { $name = (isset($_POST['name'])); $email = (isset($_POST['email'])); $to = "your@email.co.uk"; $subject = (isset($_POST['subject'])); $body = (isset($_POST['message'])); if ($subject == "") { $subject = "Email from website"; } else { $subject == $subject; } if ($_POST['name'] != "") { $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if ($_POST['name'] == "") { $errors .= 'Please enter a valid name.<br/><br/>'; } } else { $errors .= 'Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "$email is <strong>NOT</strong> a valid email address.<br/>"; } } else { $errors .= 'Please enter your email address.<br/>'; } if ($_POST['message'] != "") { $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING); if ($_POST['message'] == "") { $errors .= 'Please enter a message to send.<br/>'; } } else { $errors .= 'Please enter a message to send.<br/>'; } if (empty($errors)) { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: " . $email . "\r\n"; $success = mail($to, $subject, $body, $headers); } if ($success) { echo "<p>The following email has been sent</p>\n"; echo "<p>Name: $name</p>\n"; echo "<p>E-mail: $email</p>"; echo "<p>Subject: $subject</p>\n"; echo "<p><em>*</em> Message: $body</p>\n"; echo "<p>While you are waiting for a response from one of our staff members. Feel free to look at some of the following sections</p>\n"; echo "<a href='../waiting.php'>In The Mail</a>"; echo "Thank you for visiting Michael48060.</p>\n"; } else echo "$email_form"; } if (!empty($errors)) { echo "<div class='error_div'> <span class='errors'>" . $errors . "</span> </div>"; } ?>
×
×
  • 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.