Page 2 of 2

Re: PHP Search Form PLEASE HELP

Posted: Sun Feb 22, 2009 8:56 am
by fionaom87
hey thanks so far to who wrote back i solved that error i had but got a new one then :banghead:


any help would be great only started learning PHP and mysql a month ago :(

Tanks
F :D
Incorrect parameter count in the call to native function 'upper'

Code: Select all

<html>
<body>
<h2>Search</h2>
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="name"> Name</option>
<Option VALUE="address">Address</option>
<Option VALUE="telephoneno">Telephoneno</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
 
 
 
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?><!-- DB connection -->
<?php
$find = strtoupper(strip_tags(trim($find)));
if(isset($_POST['search']))
{
$find= $_POST['find'];
 
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;
}
 
$data = mysql_query("SELECT * FROM customers WHERE upper($field) LIKE'%$find%'")or die(mysql_error());
 
while($result = mysql_fetch_array( $data ))
{
echo $result['name'];
echo " ";
echo $result['address'];
echo "<br>";
echo $result['telephoneno'];
echo "<br>";
echo "<br>";
}
 
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
 
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
</body>
</html>
 
 
 

Re: PHP Search Form

Posted: Mon Feb 23, 2009 3:01 am
by susrisha

Code: Select all

 
"SELECT * FROM customers WHERE upper($field) LIKE'%$find%'"
 
PHP regards upper as a function in the above statement. thus throws an error. if you want to use it

Code: Select all

 
"SELECT * FROM customers WHERE upper(".$field.") LIKE'%$find%'"
 
try it out

Re: PHP Search Form

Posted: Mon Feb 23, 2009 3:05 am
by mattpointblank
You've defined $find after you try to use it for strtoupper().

Re: PHP Search Form

Posted: Mon Feb 23, 2009 3:49 am
by fionaom87
I tried that suggestion below with the mysql statement but same error still seems to be occuring

im under a bit of pressure to get things done so anyhelp would be great.

Incorrect parameter count in the call to native function 'upper'

Code: Select all

 
<html>
<body>
<h2>Search</h2>
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="name"> Name</option>
<Option VALUE="address">Address</option>
<Option VALUE="telephoneno">Telephoneno</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
 
 
 
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?><!-- DB connection -->
<?php
$find = strtoupper(strip_tags(trim($find)));
if(isset($_POST['search']))
{
$find= $_POST['find'];
 
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;
}
 
$data = mysql_query("SELECT * FROM customers WHERE upper(".$field.") LIKE'%$find%'")or die(mysql_error());
 
while($result = mysql_fetch_array( $data ))
{
echo $result['name'];
echo " ";
echo $result['address'];
echo "<br>";
echo $result['telephoneno'];
echo "<br>";
echo "<br>";
}
 
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
 
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
</body>
</html>
 
 

Re: PHP Search Form

Posted: Mon Feb 23, 2009 4:10 am
by susrisha
You havent assigned anything to $field variable.,

Hence it goes null and invalid parameter count.
Guess this was what you were expecting

Code: Select all

 
$field= $_POST['field'];
 
Then do the query

Re: PHP Search Form

Posted: Mon Feb 23, 2009 5:41 am
by fionaom87
many tanks that solved my problem. :D :D :D