Jump to content

Recommended Posts

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> ";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/244596-search-database-php/
Share on other sites

<?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>

Link to comment
https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256316
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/244596-search-database-php/#findComment-1256355
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.