Jump to content

mattyd

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mattyd's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for your reply I did as you said. Currently I am not using a separate CSS file (the page is still in a rough state and I will convert to a separate page sometime soon). I added .txtarea { font-family: arial; } directly into the code and it showed up on the page-- I guess I misunderstand. Thanks for your help. Matty
  2. I am attempting to set all font-type to Arial on a simple submission page I've created. So far this has been easy and worked for the majority of the displayed and some entered text but the primary "textarea" will not display in Arial. Below is a link to the actual page as well as the PHP/CSS. Thank-you in advance for any help, Matty http://bluelinedown.netau.net/index.php <?php include 'connection.php'; $query = "SELECT * FROM people"; $result = mysql_query($query) or die(mysql_error()); while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?> </br > <img src="reviewBanner.jpg" alt=""/> </br > <form action="create.php" method="post"> <span style='font-size:14px;font-family: "Arial";color:black;position:absolute;right:1228px;'>Subject</span> <span style='font-size:14px;font-family: "Arial";color:black;position:absolute;right:1073px;'><input type="text" name="inputName" value=""/></span> </br > <span style='font-size:14px;font-family: "Arial";color:black;position:absolute;right:1230px;top:185;'>Review</span> <span style='font-size:14px;font-family: "Arial";color:black;position:absolute;right:785px;top:185;'><textarea cols="50" rows="4" name="inputDesc" value=""/></textarea></span> </br > <span style='font-size:14px;font-family: "Arial";color:black;position:absolute;right:1160px;top:280;'><input type= "submit" name= "submit" value="Submit"/></span> *Note: The offending area on the web page is beside the "Review" label. The line of code dealing with this is: <span style='font-size:14px;font-family: "Arial";color:black;position:absolute;right:785px;top:185;'><textarea cols="50" rows="4" name="inputDesc" value=""/></textarea></span>
  3. Hi. I have just one question (I have searched for an answer for this but have not been able to locate one): How do you go about changing the text on a "Submit Query" button to display simply "Submit"? Below is the current code for the page that displays said button. Thank-you in advance for any help or direction. <?php include 'connection.php'; $query = "SELECT * FROM people"; $result = mysql_query($query) or die(mysql_error()); while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?> <H1>Add Your Review:</H1> <form action="create.php" method="post"> Subject <input type="text" name="inputName" value=""/> </br > Review <textarea cols="50" rows="4" name="inputDesc" value=""/></textarea> </br > <input type= "submit" name= "submit"/> </form> <html> <head></head> <body> <p>The current second is <span style='font-size:16px;font-weight:bold;color:red;position:absolute;right:25px;'><?php echo time(); ?></span> on this computer.</p> </body> </html>
  4. Yes, thank-you for pointing that out - totally forgot to do that in the post.
  5. Hello. I have been following a great tutorial that I found here regarding searching a database: Tutorial: http://www.phpfreaks.com/tutorial/simple-sql-search I was very happy to find and implement this as I have been looking to understand this for some time now. When I used this and ran it from my server (doing a search of the database), I bookmarked the page; my question relates to the next step: When I return to the page via the bookmark the actual search has been saved and is displayed, not just the search form. I do not understand this. This is the search page as noted (search term is "kim"): http://bluelinedown.netau.net/new_test.php?search=Kim&body=on&title=on&desc=on&matchall=on&submit=Search! I need it to be so that each time a user goes to this search page, no prior search is displayed and it is, of course, available for a new search. Is this issue related to sessions? And if so, how? Below is the actual code I am using for this search function/page: <?php /***************************** * Simple SQL Search Tutorial by Frost * of Slunked.com ******************************/ $dbHost = 'mysql7.000webhost.com'; // localhost will be used in most cases // set these to your mysql database username and password. $dbUser = '********'; $dbPass = '*******'; $dbDatabase = 'a4542527_test1'; // the database you put the table into. $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // 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 id, name, descrip FROM people WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['id'])?"`id` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['name'])?"`name` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['descrip'])?"`descrip` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `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['id']}<br />{$row['name']}<br />{$row['descrip']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?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 /> Body: <input type="checkbox" name="body" value="on" <?php echo isset($_GET['body'])?"checked":''; ?> /> | Title: <input type="checkbox" name="title" value="on" <?php echo isset($_GET['title'])?"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):""; ?> </body> </html> Thank-you in advance for any help or explanation as to what to do next. ~Matty
  6. Yes. So far I am using the following two files: index.php <?php include 'connection.php'; $query = "SELECT * FROM people"; $result = mysql_query($query) or die(mysql_error()); while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?> <H1>Add a Review:</H1> <form action="create.php" method="post"> <input type="text" name="inputName" value=""/> </br > <textarea cols="50" rows="4" name="inputDesc" value=""/></textarea> </br > <input type= "submit" name= "submit"/> </form> <html> <head></head> <body> <p>The current second is <span style='font-size:16px;font-weight:bold;color:red;position:absolute;right:25px;'><?php echo time(); ?></span> on this computer.</p> </body> </html> connection.php <?php $dbhost = 'mysql7.000webhost.com'; $dbuser = 'a4542527_root'; $dbpass = '*******'; $db = 'a4542527_test1'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); ?> The basic function works fine. I am just trying to figure out how to have the text data returned/displayed to a new page after it is submitted. Thanks, Matty
  7. I did as you suggested and am getting a different error now: Query string: SELECT * FROM people WHERE row_name2 LIKE '%kate%' LIMIT 0, 30 Resulted in an error: Unknown column 'row_name2' in 'where clause'
  8. Hi. I looked this over and replaced my file with this code. I received the following result when running a search query: Query string: SELECT * FROM people WHERE LIKE '%%' LIMIT 0, 30 Resulted in an error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%%' LIMIT 0, 30' at line 1 I am not really sure what that means or how to address the issue. Page: http://bluelinedown.netau.net/search.php Thanks. ~Matty
  9. That error has been resolved. Now I am able to enter search data and perform a search. When attempting to do this, though, I receive the error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a4542527/public_html/result.php on line 15 Note: I am using this code from a tutorial and did not write it myself so I am a bit stuck with some of it. I am attempting to connect to a pre-existing DB and search for data that already resides there. Here is the actual page: http://bluelinedown.netau.net/search.php Thanks, ~Matty
  10. In the file "result.php"? I am sort of confused (and not sure how to fix this). Thanks. ~Matty
  11. Thank-you for your reply. I made the change as you suggested but I am still getting the same error message as before. Matty
  12. I am seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // This is the main database you connect to. MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty
×
×
  • 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.