problem with a mysql query with data from a form

This is a discussion on problem with a mysql query with data from a form within the PHP General forums, part of the PHP Programming Forums category; ----- Original Message ----- From: "Vincent Fievet" <vincent.fievet@technocite.be> To: <php-general@lists.php.net&...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-28-2003
Binay Agarwal
 
Posts: n/a
Default Re: [PHP] problem with a mysql query with data from a form


----- Original Message -----
From: "Vincent Fievet" <vincent.fievet@technocite.be>
To: <php-general@lists.php.net>
Sent: Friday, August 29, 2003 11:55 AM
Subject: [php] problem with a mysql query with data from a form



-----Message d'origine-----
De : Vincent Fievet
Envoyé : mercredi 27 août 2003 10:44
À : 'php-general@lists.php.net'
Objet : problem with a mysql query with data from a form


hi,

i am a newbie to php and mysql, i run the easyphp kit ( php 4.2.0, Mysql
3.23.49 and phpmyadmin 2.2.6 )

i would like to use a select * from mytable where my variable like
'%$mystring%'
where $mystring come from a form

<form action="show.php" method="post" name="form1" target="_blank">
<table align="left">
<tr> '%Mike %
<td width="98"><h3>Communication Impliquant :</h3></td>
<td width="144" valign="middle"> <font color="#FFFFCC">
<select name="det" size="5" id="det">
<option value="PC" selected>PC</option>
<option value="echo">echo</option>
...
<option value="H10 Tango">H10 Tango</option>
</select>
<select name="den" size="1" id="den">
<option value=" " selected> </option>
<option value="1">1</option>
...
<option value="10">10</option>
</select>
</font></td>
<td width="153"> <input name="delibre" type="text" id="delibre"
maxlength="20"></td>
<td width="39"> <input type="submit" name="Submit" value="Ok"> </td>

so ,after choosing "PC" in the form, in show.php i do a

$sql="SELECT * FROM journal WHERE a like '% $det%' OR de like '%$det%' order
by dateheure desc";
++++++++++++++++++
should be

$sql="SELECT * FROM journal WHERE a like '$det %' OR de like '$det %' order
by dateheure desc";
No need of prefixing $det with %
(blank space after $det.)
++++++++++++++++
echo $sql;
and what i get is :

SELECT * FROM journal WHERE a like '%PC %' OR de like '%PC %' order by
dateheure desc
( note the blank space at the end of PC )
whitch doesnt get any record since the word i am looking is "PC" and not "PC
"
i used a "like" because the request should be used to find record with "PC
1" "PC" "PC 9" "PC12" ...

any ideas ?

Thanx

Vincent Fievet
Reply With Quote
  #2 (permalink)  
Old 08-29-2003
Vincent Fievet
 
Posts: n/a
Default problem with a mysql query with data from a form


-----Message d'origine-----
De : Vincent Fievet
Envoyé : mercredi 27 août 2003 10:44
À : 'php-general@lists.php.net'
Objet : problem with a mysql query with data from a form


hi,

i am a newbie to php and mysql, i run the easyphp kit ( php 4.2.0, Mysql 3.23.49 and phpmyadmin 2.2.6 )

i would like to use a select * from mytable where my variable like '%$mystring%'
where $mystring come from a form

<form action="show.php" method="post" name="form1" target="_blank">
<table align="left">
<tr> '%Mike %
<td width="98"><h3>Communication Impliquant :</h3></td>
<td width="144" valign="middle"> <font color="#FFFFCC">
<select name="det" size="5" id="det">
<option value="PC" selected>PC</option>
<option value="echo">echo</option>
...
<option value="H10 Tango">H10 Tango</option>
</select>
<select name="den" size="1" id="den">
<option value=" " selected> </option>
<option value="1">1</option>
...
<option value="10">10</option>
</select>
</font></td>
<td width="153"> <input name="delibre" type="text" id="delibre" maxlength="20"></td>
<td width="39"> <input type="submit" name="Submit" value="Ok"> </td>

so ,after choosing "PC" in the form, in show.php i do a

$sql="SELECT * FROM journal WHERE a like '% $det%' OR de like '%$det%' order by dateheure desc";
echo $sql;
and what i get is :

SELECT * FROM journal WHERE a like '%PC %' OR de like '%PC %' order by dateheure desc
( note the blank space at the end of PC )
whitch doesnt get any record since the word i am looking is "PC" and not "PC "
i used a "like" because the request should be used to find record with "PC 1" "PC" "PC 9" "PC12" ...

any ideas ?

Thanx

Vincent Fievet

Reply With Quote
  #3 (permalink)  
Old 08-29-2003
Raditha Dissanayake
 
Posts: n/a
Default Re: [PHP] problem with a mysql query with data from a form

You might also want to use addslashes() .

like '%something%' puts a big load on the database server. and it seems
you are doing mulitples of these queries. Please make sure you have the
correct indices on your tables. You might want to look at fulltext
indexing instead.

all the best


murugesan wrote:

>use
>$det=trim($det);
>then assign the $sql value.
>-murugesan
>
>----- Original Message -----
>From: "Vincent Fievet" <vincent.fievet@technocite.be>
>To: <php-general@lists.php.net>
>Sent: Friday, August 29, 2003 11:55 AM
>Subject: [php] problem with a mysql query with data from a form
>
>
>
>-----Message d'origine-----
>De : Vincent Fievet
>Envoyé : mercredi 27 août 2003 10:44
>À : 'php-general@lists.php.net'
>Objet : problem with a mysql query with data from a form
>
>
>hi,
>
>i am a newbie to php and mysql, i run the easyphp kit ( php 4.2.0, Mysql
>3.23.49 and phpmyadmin 2.2.6 )
>
>i would like to use a select * from mytable where my variable like
>'%$mystring%'
>where $mystring come from a form
>
><form action="show.php" method="post" name="form1" target="_blank">
> <table align="left">
> <tr> '%Mike %
> <td width="98"><h3>Communication Impliquant :</h3></td>
> <td width="144" valign="middle"> <font color="#FFFFCC">
> <select name="det" size="5" id="det">
> <option value="PC" selected>PC</option>
> <option value="echo">echo</option>
> ...
> <option value="H10 Tango">H10 Tango</option>
> </select>
> <select name="den" size="1" id="den">
> <option value=" " selected> </option>
> <option value="1">1</option>
> ...
> <option value="10">10</option>
> </select>
> </font></td>
> <td width="153"> <input name="delibre" type="text" id="delibre"
>maxlength="20"></td>
> <td width="39"> <input type="submit" name="Submit" value="Ok"> </td>
>
>so ,after choosing "PC" in the form, in show.php i do a
>
>$sql="SELECT * FROM journal WHERE a like '% $det%' OR de like '%$det%' order
>by dateheure desc";
>echo $sql;
>and what i get is :
>
>SELECT * FROM journal WHERE a like '%PC %' OR de like '%PC %' order by
>dateheure desc
>( note the blank space at the end of PC )
>whitch doesnt get any record since the word i am looking is "PC" and not "PC
>"
>i used a "like" because the request should be used to find record with "PC
>1" "PC" "PC 9" "PC12" ...
>
>any ideas ?
>
>Thanx
>
>Vincent Fievet
>
>
>



--
http://www.raditha.com/php/progress.php
A progress bar for PHP file uploads.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:55 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0