Jump to content

Recommended Posts

G'day again

 

I'm trying to implement a script on my own website to start gearing up towards going from flatfile to mysql.

So far, i've got various scripts working in the test stage, but this one in particular I can't seem to get my head around.

 

What i'm trying to do, is have a script that the user can search the database (with a selection to choose from several different fields to search for), and then instead of just displaying the results, display the results so each record is editable, but all in the one screen without having to manually edit each item.

 

this is my current code which is just set to view results, but am having no luck what so ever in just getting anything to display :(

 

<form name="search" method="post" action="">
Seach for: <input type="text" name="find" /> in 
<Select NAME="field">
<Option VALUE="busno">Bus</option>
<Option VALUE="depot">Depot</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>

<? 
//This is only displayed if they have submitted the form 
if ($searching =="yes") 
{ 
echo "<h2>Results</h2><p>"; 

//If they did not enter a search term we give them an error 
if ($find == "") 
{ 
echo "<p>You forgot to enter a search term"; 
exit; 
} 

echo "
<table border='1' cellspacing='1' cellpadding='0' style='border-collapse: collapse' bordercolor='#C0C0C0'>
<tr>
<td>Bus</td>
<td>Depot</td>
</tr>"; 

// Otherwise we connect to our Database 
mysql_connect("localhost", "username", "password") or die(mysql_error()); 
mysql_select_db("databasename") or die(mysql_error()); 

// We preform a bit of filtering 
$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find); 

//Now we search for our search term, in the field the user specified 
$data = mysql_query("SELECT * FROM busfleet WHERE upper($field) LIKE'%$find%' ORDER BY busno ASC"); 

$rows = mysql_num_rows($data);
echo "Total records found: ". $rows . " for <i>". $field ."</i> matching <b>". $find ."</b><p>";

//And we display the results 
while($result = mysql_fetch_array( $data )) 
{ 

echo "<tr><td>";
echo $result['busno']; 
echo "</td><td>"; 
echo $result['depot']; 
echo "</td><td>";
} 
echo "</table>";
//This counts the number or results - and if there wasn't any it gives them a little message explaining that 
$anymatches=mysql_num_rows($data); 
if ($anymatches == 0) 
{ 
echo "Sorry, but we can not find an entry to match your query<br><br>"; 
} 
} 
?>

 

So any help, suggestions or code much appreciated...

Link to comment
https://forums.phpfreaks.com/topic/143442-search-with-update/
Share on other sites

try changing

$data = mysql_query("SELECT * FROM busfleet WHERE upper($field) LIKE'%$find%' ORDER BY busno ASC"); 

to

$data = mysql_query("SELECT * FROM busfleet WHERE upper($field) LIKE'%$find%' ORDER BY busno ASC") or die(mysql_error()); 

 

any errors ?

Link to comment
https://forums.phpfreaks.com/topic/143442-search-with-update/#findComment-752430
Share on other sites

try changing

$data = mysql_query("SELECT * FROM busfleet WHERE upper($field) LIKE'%$find%' ORDER BY busno ASC"); 

to

$data = mysql_query("SELECT * FROM busfleet WHERE upper($field) LIKE'%$find%' ORDER BY busno ASC") or die(mysql_error()); 

 

any errors ?

Sorry, no error messages :(
Link to comment
https://forums.phpfreaks.com/topic/143442-search-with-update/#findComment-752491
Share on other sites

When you say your getting nothing displayed are you getting a blank page or no results ?

As I was sending a reply, I then realised that my webhost has this STUPID thing about having a php.ini file in each directory (why, not sure), but added that, now get results, so hopefully for the next stage if at all possible please, instead of just displaying the results, how can i get it to display the results in editable input boxes so I can edit numerous records at once?
Link to comment
https://forums.phpfreaks.com/topic/143442-search-with-update/#findComment-752502
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.