AcidDriver Posted July 22, 2008 Share Posted July 22, 2008 Hi all, I am having a query problem with this one mySQL query through PHP. I bolded it for convenience. <?php { // Else, connect direct to the database mysql_connect("localhost", "root", "") or die(mysql_error()); //Need to setup dedicated H.O.P.E server to link to mySQL, then input user/server info. mysql_select_db("hope") or die(mysql_error()); //Search for search term once in database. $data = mysql_query("SELECT * FROM 'hope' WHERE '$_POST['field']' LIKE '$_POST['find']'"); //Display results while($result = mysql_fetch_array( $data )) { echo "<u><b>"; echo $result['fname']; echo " "; echo $result['lname']; echo "</b></u><b><br>ID Number:</b> "; echo $result['idnum']; echo "<b><br>Graduation Year:</b> "; echo $result['gradyear']; //echo "<b><br>Donor:</b> "; //echo $result['donor']; //echo "<br><b>FOH/Community Partner:</b> "; //echo $result['foh']; echo "<br><b>Organization/Firm: </b>"; echo $result['org']; //echo "<br><b>HOPE Fellow:</b> "; //echo $result['fellow']; //echo "<br><b>HOPE Senior Fellow:</b> "; //echo $result['sfellow']; //echo "<br><b>Miami Scholar: </b>"; //echo $result['scholar']; //echo "<br><b>Public Interest Loan Reduction Recipient:</b> "; //echo $result['lreduce']; echo "<br><b><br>Home Address:</b>"; echo $result['address']; echo "<br>"; echo $result['city'] .", " .$result['state'] ." " .$result['zip']; echo "<br><b><br>Work Address:</b> <br>"; echo $result['waddress']; echo "<br>"; echo $result['wcity'] .", " .$result['wstate'] ." " .$result['wzip']; echo "<br><b>Work Phone:</b>"; echo $result['wphone']; echo "<br><b>Fax number: </b>"; echo $result['fax']; echo "<br><b>Cell Phone: </b>"; echo $result['cphone']; echo "<br><b>Email:</b>"; echo $result['email']; //echo "<br><b><br>Interests:</b> "; //echo $result['Interests']; //echo "<br><b>Project Leader: </b>"; //echo $result['project']; //echo "<br><b>HOPE Liason:</b> "; //echo $result['liason']; //echo "<br><b>Center for Ethics and Public Service Liason:</b> "; //echo $result['pliason']; echo "<br><br><b>Community Service Hours:</b>"; echo $result['comtotalhours']; echo "<br><dd><b>Project Name/Agency: </b></dd>"; echo $result['comagency']; echo "<br><dd><b>Date of Project: </dd></b>"; echo $result['comdate']; echo "<br><dd><b>Community Service Project Hours: </b></dd>"; echo $result['comhours']; echo "<br><br><b>Advocacy Service Hours: </b>"; echo $result['adtotalhours']; echo "<br><dd><b>Project Name/Agency: </b></dd>"; echo $result['adagency']; echo "<br><dd><b>Date of Project: </dd></b>"; echo $result['addate']; echo "<br><dd><b>Hours Volunteered: </b></dd>"; echo $result['adhours']; echo "<br><dd><b>Supervising Attorney: </b></dd>"; echo $result['adattorney']; echo "<br><dd><b>Attorney Contact: </b></dd>"; echo $result['adattorneycon']; //echo "<br><b><br>Languages: </b>"; //echo $result['languages']; echo "<br><br><br><br><br>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $matchnum=mysql_num_rows($data); if ($matchnum == 0) { echo "There were no results for you mySQL query.<br><br>"; } //Echo back what the user searched for: echo "<b>Searched For: </b> " .$find; echo "<b>Number of Results: </b> " .$matchnum; echo "<br>"; echo '<a href="http://127.0.0.1/HOPE%20Database/index.htm">Search Again</a>'; } ?> I am running PHP 5.2 I have not tried anything, becuase enything that I do try, seems to turn up more errors. I am trying to have this script search for a field that is passed from the HTML Page. <html> <head> <title>Welcome to the HOPE Database</title> <link rel="stylesheet" href="text/main.css" type="text/css" /> </head> <body> <h1>H.O.P.E Volunteer Database Search</h1> <font class="title">Please enter your database query below.</font> <form name="search" method="post" action="search.php"> Search: <input type="text" value="$find" name="find" /> Category: <Select NAME="field"> <Option value="fname">First Name</option><!--Searches according to the volunteers last name --> <Option value="lname">Last Name</option><!--Searches according to the volunteers first name --> <Option value="idnum">ID Number</option><!--Searches according to the volunteers ID Number --> <option value="gradyear">Graduation Year</option> </Select><br> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search Database" class="note"/> </form> <br> <br> <a href="volunteer.htm">Input a new volunteer</a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/116051-solved-php-query-error/ Share on other sites More sharing options...
revraz Posted July 22, 2008 Share Posted July 22, 2008 And you don't post any of the errors you get... so we can only guess. One thing, you dont put single quotes around the Table Name 'Hope', you need backticks `Hope` Next, you'll want to put { } around your POST arrays. Without more info from you, it's hard to tell what errors you get and where. Link to comment https://forums.phpfreaks.com/topic/116051-solved-php-query-error/#findComment-596732 Share on other sites More sharing options...
AcidDriver Posted July 22, 2008 Author Share Posted July 22, 2008 ....... and i think that is a complete lack of attention... sorry everyone Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in H:\Documents\My Web Sites\HOPE Search Database\search.php on line 10 Link to comment https://forums.phpfreaks.com/topic/116051-solved-php-query-error/#findComment-596735 Share on other sites More sharing options...
AcidDriver Posted July 22, 2008 Author Share Posted July 22, 2008 I am trying out this new query, because my previous one just acted like a wildcard, showing me every entry. Link to comment https://forums.phpfreaks.com/topic/116051-solved-php-query-error/#findComment-596737 Share on other sites More sharing options...
AcidDriver Posted July 22, 2008 Author Share Posted July 22, 2008 Oh wow, you two fixes worked!!! There are new errors here though. The first, and most important, is that no results will show up, even if the data is correct. For instance, if I search Damian in First Name, stored as fname in the HTML form, as well as in the mySQL table, it gives this. There were no results for you mySQL query. Notice: Undefined variable: find in H:\Documents\My Web Sites\HOPE Search Database\search.php on line 94 Searched For: Number of Results: 0 Link to comment https://forums.phpfreaks.com/topic/116051-solved-php-query-error/#findComment-596743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.