anton_1 Posted August 12, 2011 Share Posted August 12, 2011 Hey guys cannot get data to display after search submitted. Thanks for your time! <form method="post" action="search.php" > <input type="hidden" name="submitted" value="true" /> <label>Search Criteria: <input type="text" name="criteria" /></label> <input type="Submit" value="Search" /> </form> <?php if (isset($_POST['submitted'])) { $criteria = $_POST['criteria']; mysql_connect('localhost', 'web101-db1-1', 'mypassword'); mysql_select_db('web101-db1-1'); $query = "SELECT * FROM Tickets WHERE $criteria LIKE '%".$criteria."%' "; $result = mysql_query($query); echo "$num_rows Tickets Found!"; echo "</br>"; echo "</br>"; echo "</br>"; echo "<table>"; echo "<tr><th>Ticket ID</th><th>Date</th><th>Status</th><th>Requested By</th><th>Assigned To</th><th>Description</th></tr>"; while ($row = mysqli_fetch_array($result)) { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['DateCreated']; echo "</td><td>"; echo $row['Status']; echo "</td><td>"; echo $row['RequestedBy']; echo "</td><td>"; echo $row['AssignedTo']; echo "</td><td>"; echo $row['Description']; echo "</td><td>"; } echo "</table>"; } echo "</br>"; echo "</br>"; echo "</br>"; echo "</br>"; echo "<a href='loggedin.php'>Helpdesk</a><br> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/ Share on other sites More sharing options...
kney Posted August 12, 2011 Share Posted August 12, 2011 Why don't you do <input type="Submit" value="Search" name="search" /> </form> <?php if (isset($_POST['search'])) { ... } Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256309 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 Thanks! When I change it to search nothing appears? it needs to know when the form is submitted? Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256310 Share on other sites More sharing options...
MasterACE14 Posted August 12, 2011 Share Posted August 12, 2011 <?php mysql_connect('localhost', 'web101-db1-1', 'mypassword'); mysql_select_db('web101-db1-1'); if (isset($_POST['submitted'])) { $criteria = mysql_escape_string($_POST['criteria']); // validation for security $query = "SELECT * FROM Tickets WHERE $criteria LIKE '%".$criteria."%' "; $result = mysql_query($query); $num_rows = mysql_num_rows($result); // check how many rows there are if($num_rows > 0) { // check that something is found... echo "$num_rows Tickets Found!"; echo "<br /><br /><br />"; echo "<table>"; echo "<tr><th>Ticket ID</th><th>Date</th><th>Status</th><th>Requested By</th><th>Assigned To</th><th>Description</th></tr>"; while ($row = mysql_fetch_array($result)) // have to use mysql_fetch_array() not mysql[b]i[/b]_fetch_array() if you're connected to the database with just mysql_connect() instead of mysql[b]i[/b]_connect() { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['DateCreated']; echo "</td><td>"; echo $row['Status']; echo "</td><td>"; echo $row['RequestedBy']; echo "</td><td>"; echo $row['AssignedTo']; echo "</td><td>"; echo $row['Description']; echo "</td><td>"; } echo "</table>"; } else { echo 'No Records Found!'; // if nothing is found... } } ?> <form method="post" action=""> <!-- leave action empty for security reasons when posting to same file --> <input type="hidden" name="submitted" value="true" /> <label>Search Criteria: <input type="text" name="criteria" /></label> <input type="Submit" value="Search" /> </form> <br /><br /><br /><br /> <a href='loggedin.php'>Helpdesk</a><br> Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256316 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 hey man! thanks! can you re-post that code when I copy and paste it its all over the place. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256336 Share on other sites More sharing options...
MasterACE14 Posted August 12, 2011 Share Posted August 12, 2011 try this... <?php mysql_connect('localhost', 'web101-db1-1', 'mypassword'); mysql_select_db('web101-db1-1'); if (isset($_POST['submitted'])) { $criteria = mysql_real_escape_string($_POST['criteria']); // validation for security $query = "SELECT * FROM Tickets WHERE $criteria LIKE '%".$criteria."%' "; $result = mysql_query($query); $num_rows = mysql_num_rows($result); // check how many rows there are if($num_rows > 0) { // check that something is found... echo "$num_rows Tickets Found!"; echo "<br /><br /><br />"; echo "<table>"; echo "<tr><th>Ticket ID</th><th>Date</th><th>Status</th><th>Requested By</th><th>Assigned To</th><th>Description</th></tr>"; while ($row = mysql_fetch_array($result)) // have to use mysql_fetch_array() not mysql[b]i[/b]_fetch_array() if you're connected to the database with just mysql_connect() instead of mysql[b]i[/b]_connect() { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['DateCreated']; echo "</td><td>"; echo $row['Status']; echo "</td><td>"; echo $row['RequestedBy']; echo "</td><td>"; echo $row['AssignedTo']; echo "</td><td>"; echo $row['Description']; echo "</td><td>"; } echo "</table>"; } else { echo 'No Records Found!'; // if nothing is found... } } ?> <form method="post" action=""> <!-- leave action empty for security reasons when posting to same file --> <input type="hidden" name="submitted" value="true" /> <label>Search Criteria: <input type="text" name="criteria" /></label> <input type="Submit" value="Search" /> </form> <br /><br /><br /><br /> <a href='loggedin.php'>Helpdesk</a><br> Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256355 Share on other sites More sharing options...
anton_1 Posted August 12, 2011 Author Share Posted August 12, 2011 Still everywhere :s Thanks Quote Link to comment https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256371 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.