Current location: Hot Scripts Forums » Programming Languages » PHP » Problem in php4 Vs Mysql4(Select query unsupport"%")


Problem in php4 Vs Mysql4(Select query unsupport"%")

Reply
  #1 (permalink)  
Old 12-07-06, 01:14 AM
cty cty is offline
Newbie Coder
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Problem in php4 Vs Mysql4(Select query unsupport"%")

Good day,

I currently using mysql servers and clients 4.0.14b and php 4.4.4

I have facing a coding problem,can any one give me some idea?
Hopefully you may guide me to edit it.

---------------------------------------------------------------
error message shown:

cannot execute sql becauseYou have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '% %' at line 1

-----------------------------------------------------------
<html>
<head>
</head>
<body>
<form action=result.php method=post>
Choose Search Type:<br />
<select name="searchtype">
<option value="author">Author</option>
<option value="title">Title</option>
<option value="isbn">ISBN</option>
</select>
<br />
Enter Search Term:
<br />
<input type=text name="searchterm">
<br />
<input type=submit value=Search>
</form>
</body>
</html>
------------------------------------------------------------
//result.php


<html>
<head>
<title>New Page 1</title>
</head>
<body>
<?php
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];

$query="SELECT * FROM book where " . $searchtype . " like% " . $searchterm . "%";
$connection=mysql_connect("localhost","root","") or die("cannot connect!");
mysql_select_db("kelly") or die("cannot select db!");

$result=mysql_query($query) or die("cannot execute sql because".mysql_error());


if(mysql_num_rows($result)>0)
{
echo"<table>";
echo"<td>ISBN</td>";
echo"<td>TITLE</td>";
echo"</tr>";
while($row=mysql_fetch_assoc($result))
{
echo"<tr>";
echo"<td>".$row['isbn']."</td>";
echo"<td>".$row['title']."</td>";
echo"</tr>";
}
echo"</table>";
}
else
{echo"No data found!";
}

mysql_close($connection);
?>

</body>
</html>
------------------------------------------------//(end)

From,
UTAR student
MALAYSIA
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 12-07-06, 06:40 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
try:
PHP Code:

$query="SELECT * FROM book where " $searchtype " like '% " $searchterm "%'"
you forgot to add a space between like and %. I think it's also necessary to wrap the %..% in quotes.

BTW: if you're having mysql-query problems, the first thing to do is to diplay your ready-for-execution query. That way you will find your problems easily

UnrealEd
please use [php] wrappers
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

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
MYSQL Distinct Query problem FunkyM PHP 20 02-28-07 09:33 AM
code problem throws error matt001 ASP.NET 0 10-23-05 04:30 AM
mysql query problem (very important for me...) pedroso PHP 5 07-26-05 02:09 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


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