Current location: Hot Scripts Forums » Programming Languages » PHP » How do i search from a form to mysql database using php


How do i search from a form to mysql database using php

Reply
  #1 (permalink)  
Old 04-21-04, 12:40 AM
QTortZ QTortZ is offline
New Member
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
How do i search from a form to mysql database using php

Hello everyone..i have this problem..i want to know how to search from a form to a database
on my form.php i have this code:

<b>Search by : </b>
<form method="post" action="test8.php">
<select name="searchList">

<option value="own"name="owner" >Owner</option>

<option value="sec"name="section">Section</option>

<option value="ipad"name="ipaddress">IP Address</option>
</select>
<input type="text" name="frm_search" size="30">
<input type="Submit" value="Search" align="MIDDLE">
</form>


and on my test8.php:

<?php
$hostname = "10.18.1.78"; // Usually localhost.
$username = "root"; // If you have no username, leave this space empty.
$usertable = "ipa"; // This is the table you made.
$dbName = "ipadd"; // This is the main database you connect to.
mysql_connect($hostname, $username) 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 ipa WHERE $searchList LIKE '%$frm_search%' limit 0, 30");
if ($row = mysql_fetch_array($query))
{
echo "<table border=1>\n";
echo "<tr><td>Owner</td><td>Section</td><td>IP Address</td></tr>\n";
do {
printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", $row["owner"], $row["section"], $row["ipaddress"]);
} while ($row = mysql_fetch_array($query));
echo "</table>\n";
}
if (!$variable1)
{
print ("$XX");
}

?>

but it has this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\apache\apache2\htdocs\TMP9qjlrwi7z2.php on line 14
No Record Found

can anyone help me?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-21-04, 06:48 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
this means that the query has somethign wrong with it !
change the query line to:
PHP Code:

$query mysql_query("SELECT * FROM ipa WHERE $searchList LIKE '%$frm_search%' limit 0, 30")or

die(
mysql_error()); 
if any error was found, shall show it ..
also don't depend on globals !
add these lines at the top of your test8.php file:
PHP Code:

$searchList $_POST['searchList'];

$frm_search trim(addslashes($_POST['frm_search'])); 
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-22-04, 10:18 PM
QTortZ QTortZ is offline
New Member
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

thanks for your reply but i still can't get it..
when i change the code above..it prompt out error like:

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 '%%'' at line 1

thanx again...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-23-04, 12:16 AM
Tim Tim is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
It is probably due to using the mysql_fetch_array function
twice. Try changing:
if ($row = mysql_fetch_array($query))
to
if ($row = !$query)

It will accomplish the same thing without the extra function call.
__________________
Tim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-23-04, 11:32 PM
QTortZ QTortZ is offline
New Member
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ermmm...still the same problem..how to solve it?


thanks..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-24-04, 01:24 AM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
it seems to me that $frm_search is empty... check if that's the right variable or w/e that holds the keyword.
__________________
New beta project: GFX-PRO.ATH.CX
Description: GFX-PRO a great new project that anyone can and setup in less then a minute. [ More info ]
Website: http://gfx-pro.ath.cx
Status: Online
http://gfx-pro.ath.cx/sig.png
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-02-04, 10:57 PM
ron_barber ron_barber is offline
New Member
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
NEVER MIND!! i could kiss you, im just learning php mysql dah dah, geez i been trying to query a search and rahh you just saved me from havign to turn the kettle on for the 5th time this morn haha, MWAHH,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 02:41 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 01:11 AM
Importing to a mysql database via php gulfan PHP 1 01-23-04 05:44 PM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 01:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.