![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
mattyd
-
Posts
25 -
Joined
-
Last visited
Never
Posts posted by mattyd
-
-
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
-
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>
-
I figured it out. Thanks.
Matty
-
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>
-
Remove your database credentials from your code in that post. Probably a good time to change your database password now, too.
Yes, thank-you for pointing that out - totally forgot
to do that in the post.
-
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"):
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
-
do you have any code to show us thus far?
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
-
That means the $search and $metode variables are empty or undefined. Is there anything in the tutorial that looks like this? If not, add this to the results.php file, right after //error message (not found message)
if( isset($_POST['search']) ) { $search = mysql_real_escape_string($_POST['search']); } if( isset($_POST['metode']) ) { $metode = mysql_real_escape_string($_POST['metode']); }
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'
-
Frankly, that tutorial is already teaching you some bad habits. Look this over and see my comments within the code. Let me know if you have any questions.
<?php $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"; // assign a value for the 'empty result set' message $query = "SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30"; // Query string, separated from the query execution if( !$result = mysql_query($query) ) { // check query execution success/failure echo '<br>Query string: ' . $query . '<br>Resulted in an error: ' . mysql_error() . '<br>'; // if execution fails, echo debugging info incl. error and query string } else { // if query succeeds if( mysql_num_rows($result) > 0 ) { // if result set is not empty, echo the result set 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..."); } } else { // else, if the result set is empty, echo the message for an empty result set. echo $XX; } } //end ?>
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
-
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
-
In search.php, you open the php tags, then have an html block in there without using 'echo'. If you simply remove the <?php tags around that block of html, it should fix that error. I didn't look over all of the code, so fixing that one may reveal other errors that need attention.
Thank-you for all of your help.
Matty
-
I jumped the gun. See my edit above . . .
In the file "result.php"? I am sort of confused (and not sure how to fix this).
Thanks.
~Matty
-
You're using short <? open tags. Change the tags from <? To <?php tags and see if that help.
Thank-you for your reply. I made the change as you suggested but I am still getting the same error message as before.
Matty
-
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
-
Hello. I currently have a web page that allows a user to enter text into a form then select a "Submit Query" button; upon doing this the entered text is saved to a database and displayed for the user on the same page (the page where the form and "Submit Query" button are located).
My question is as follows: I wish the results to be displayed on a new page when the "Submit Query" button is clicked, not displayed on the same page. Is this achieved through targeting? I am a bit lost at this point on how to achieve this result.
Thank-you in advance for any help.
~Matty
-
Thanks for everyone's help and input.
~Matty
-
Hello. I am interested in taking a result returned from a database and having it displayed in a certain way/style on the user's screen; For example, the user enters text into a field and hits "submit" - the data is saved in the database then displayed to the user (This part I have working just fine so far due to help I received here.)
My question is if I would like to, for example, have said text not simply dumped to the top of the screen, inline, but nicely formatted in a boxed, text area, I assume I will use HTML/CSS, and I was wondering if anyone had any good links/tutorials regarding this topic so I may look further into it (my search thus far has not turned up the correct topic or results).
Thank-you in advance for any assistance.
~Matty
-
There is no such superglobal as $_Post. It's $_POST. Variables are case-sensitive, functions aren't.
Thank-you so much for your help - that worked perfectly! Very exciting
I appreciate it.
-
I have adjusted the code now to where the noted error messages do not appear when running the code; The two text boxes appear. I am able to enter text and select the submit button without error. But, now, the problem is the overall functionality: The entered data should be added to the DB and also displayed on the screen. (I am following a tutorial for this and have done everything correctly I believe). Now I just have to figure out why it is not writing to the database and why it is not displaying (*Thank-you for your patience, I am a newbie to PHP/MYSQL)
~Matty
-
Thank-you for everyone's help. I do appreciate it.
I added the '$descrip') ) as noted above but am still receiving the error message related to an unexpected ';'
-
Upon running my code online I receive the following error:
Parse error: syntax error, unexpected ';' in /home/a4542527/public_html/create.php on line 13
indicating that the semicolon (to the right of or die(mysql_error())) in the following code is in error:
create.php
<?php include 'connection.php'; $name= $_Post['inputName']; $descrip= $_Post['inputDesc']; if(!$_Post['submit']){ echo "Please fill out the review"; header('Location: index.php'); } else{ mysql_query("INSERT INTO people (`id`,`name`,`descrip`) VALUES(NULL, '$name', '$descrip')" or die(mysql_error()); echo "Your review has been added"; header('Location: index.php'); } ?>
If I remove this semicolon and run the code, I receive this error:
Parse error: syntax error, unexpected T_ECHO in /home/a4542527/public_html/create.php on line 14
I'm not sure what I'm doing wrong.
(When this script runs it allows for two text boxes to be displayed. After text is entered and submitted, the said text will be displayed on the screen. Below are the two other associated files that I'm using.)
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']; } ?>
connection.php
<?php $dbhost = 'mysql7.000webhost.com'; $dbuser = 'a4542527_root'; $dbpass = '*******'; $db = 'a4542527_test1'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); ?>
Thank-you in advance for any help or pointer in the right direction.
~Matty
-
$result = "mysql_query($query)";
...should not be in quotes.
Thank-you for your reply and help.
-
$result = mysql_query($query) or die(mysql_error());
Thank-you so much for your help! That worked perfectly.
I really appreciate your help.
~Matty
-
I have searched for this topic here but have not found reference to it.
I am receiving the following:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a4542527/public_html/index.php on line 8
The scripting for this is basic at this point (I am building something in steps and this is just a test section: The script will call data from the table and display said data.)
The following is the code (two, separate files located on my server)- I am hoping that someone may see something that I am missing.
connection.php
<?php $dbhost = 'mysql7.000webhost.com'; $dbuser = 'a4542527_root'; $dbpass = '**********'; $db = 'a4542527_test1'; $conn = mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db($db); ?>
index.php
<?php include 'connection.php'; $query = "SELECT * FROM people"; $result = "mysql_query($query)"; while ($person = mysql_fetch_array($result)){ echo $person ['name']; echo $person ['descrip']; } ?>
Thank-you for any help, suggestions or a point in the right direction.
~Matty
Setting font type within a "textarea"
in CSS Help
Posted
Thank-you, that worked great.