Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-12-07, 03:26 AM
cty cty is offline
Junior Member
 
Join Date: Dec 2006
Posts: 4
cty is on a distinguished road
Default Problem in php4 Vs Mysql4(Select query unsupport"%")

Good day to all,

can anyone tell me why my mysql do not support the "%"??What is happen?
Anyone can let me know how to edit the "query" statement (red in color)?

---------------------------------------------------------------
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
Reply With Quote
  #2 (permalink)  
Old 2006-12-12, 05:06 AM
Junior Member
 
Join Date: Dec 2006
Posts: 5
drgovind06 is on a distinguished road
Default

Hello Friend,
The Like clause needs ' (quotes ) around it to work

for e.g.

Select * from table2 where x like 'abcd%'

the code suggested earlier seems to generate

Select * from table2 where x like abcd%

Quotes missed out so .... its likely to generate some error.


regard
RG
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:42 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.