/    Sign up×
Community /Pin to ProfileBookmark

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’];

[COLOR=Red]$query=”SELECT * FROM book where ” . $searchtype . ” like% ” . $searchterm . “%”;[/COLOR]
$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

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsDec 07.2006 — your query should be:"SELECT * FROM book WHERE " .$searchtype. " LIKE '%$searchterm%'"
Copy linkTweet thisAlerts:
@ctyauthorDec 07.2006 — Thank you!
×

Success!

Help @cty spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...