473,473 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

a listbox populated with query strings when selected particular query to be executed

27 New Member
hi all,

somebody help me out on this

i have a listbox where i have the values as starts with and ends with and next to that is a textbox where we give the input whether the fieldname should start with a particular letter or end with a particular letter

say for example the field name lastname is to be executed

so what we do is select a value from listbox say startswith and in the textbox we give as letter p and that should execute a mysql query that the lastname should start with letter p and display all the lastnames which all starts with letter p

hope could be understood

thanks in advance
Apr 24 '09 #1
13 1764
Dormilich
8,658 Recognized Expert Moderator Expert
this sounds like a hell of validation to do… anyways you might want to look here on string comparison in MySQL.
Apr 24 '09 #2
Ciary
247 Recognized Expert New Member
i think you better write 3 SQL Queries looking like this:
Expand|Select|Wrap|Line Numbers
  1. if($_POST['validateType'] == 'start'){
  2.    $query = "SELECT * FROM yourtable WHERE lastname LIKE " . $_POST['myval'] . "%";
  3. } if($_POST['validateType'] == 'end'){
  4.    $query = "SELECT * FROM yourtable WHERE lastname LIKE %" . $_POST['myval'];
  5. } else {
  6.    $query = "SELECT * FROM yourtable WHERE lastname LIKE %" . $_POST['myval'] . "%";
  7. }
  8.  
i'm not sure if this is what you need but it generates a recordset depending on what you selected
Apr 24 '09 #3
ahilar12
27 New Member
hi dormi,

could u clarify me what these variables represent in this following code

1.validateType
2.start
3.myval


Expand|Select|Wrap|Line Numbers
  1.       if($_POST['validateType'] == 'start')
  2.           {
  3.     $query = "SELECT * FROM yourtable WHERE lastname LIKE " . $_POST['myval'] . "%";
  4.  } if($_POST['validateType'] == 'end'){
  5.     $query = "SELECT * FROM yourtable WHERE lastname LIKE %" . $_POST['myval'];
  6.  } else {
  7.     $query = "SELECT * FROM yourtable WHERE lastname LIKE %" . $_POST['myval'] . "%";
  8.  }
  9.  
  10.  
Apr 27 '09 #4
Dormilich
8,658 Recognized Expert Moderator Expert
@ahilar12
  1. where to have the search sting ("start": at the beginning, "end": at the end, anywhere in the text)
  2. see above
  3. the search term
Apr 27 '09 #5
ahilar12
27 New Member
hi ciary
check out this code and tell me whats wrong

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <script language="javascript">
  5. function ShowHideForm(o){
  6.     if(o.checked == true)
  7.         document.getElementById("formId").style.display="block";
  8.     else
  9.         document.getElementById("formId").style.display="none";
  10. }
  11. </script>
  12. <body>
  13.  
  14. <?php
  15. include 'menu.php';
  16. ?>
  17.  
  18. <form name="createreport" action="insertreport.php" method="POST">
  19. <input type="checkbox" name="test" onclick="ShowHideForm(this)"> First Name
  20. <br>
  21. <br>
  22. <div id="formId" style="display:none">
  23. <table border="1">
  24.   <tbody>
  25.     <tr>
  26.       <td>FirstName</td>
  27.       <td><input type="text" name="myval"/>   </td>
  28.       <td><select name="validatetype">
  29.       <option name="start">start</option>
  30.       <option name="end">end</option>
  31.  
  32.  
  33. </select>
  34. </td>
  35.  
  36. <td><input type="submit" value="submit"/></td>
  37.  
  38.     </tr>
  39.   </tbody>
  40. </table>
  41.  
  42. </div>
  43. </form>
  44.  
  45. </body>
  46. </html>
  47.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4.        include 'connect.php';
  5.  
  6.        $ins=mysql_query("insert into createreport(validatetype,myval)values('$_POST[validatetype]','$_POST[myval]')");
  7.  
  8. if($ins)
  9. {
  10.   echo "inserted";
  11. }
  12.  
  13. if(!$ins)
  14. {
  15.     echo "mysql_error()";
  16. }
  17.  
  18.  
  19.       if($_POST['validatetype'] == 'start')
  20.   {
  21.     $query = mysql_query("SELECT * FROM createreport WHERE lastname LIKE " . $_POST['myval'] . "%");
  22.     echo $query;
  23.  } 
  24.  else if($_POST['validatetype'] == 'end')
  25. {
  26.     $query = mysql_query("SELECT * FROM createreport WHERE lastname LIKE %" . $_POST['myval']);
  27.     echo $query;
  28.  } else 
  29. {
  30.     $query = mysql_query("SELECT * FROM createreport WHERE lastname LIKE %" . $_POST['myval'] . "%");
  31.     echo $query;
  32.  }
  33. ?>
  34.  
Apr 27 '09 #6
Dormilich
8,658 Recognized Expert Moderator Expert
@ahilar12
there's no input validation (see SQL Injection). and some indices are not quoted.

what is the code not doing / doing, what it should do / not do?

are there any error messages?
Apr 27 '09 #7
Ciary
247 Recognized Expert New Member
what does it say as error? or what do you see?

ps. try codeblocks, makes it easier to read
Apr 27 '09 #8
ahilar12
27 New Member
hi ciary,

what is code blocks?

i m a beginner to php.
Apr 27 '09 #9
Dormilich
8,658 Recognized Expert Moderator Expert
codeblocks belong to the forum to make source code easier to read.

Expand|Select|Wrap|Line Numbers
  1. // this is a code block
Apr 27 '09 #10
Ciary
247 Recognized Expert New Member
it's not php. it's when you post code on the forum. on top of your editor when replying, you see a symbol like this: #. it will add codeblocks. then put your code between them.
Apr 27 '09 #11
Markus
6,050 Recognized Expert Expert
[code] code goes here [/code].

[PHP] and [HTML] used to do the same thing, but no more. Please use the above.

Moderator.
Apr 27 '09 #12
ahilar12
27 New Member
oh ok

understood

thanks
Apr 27 '09 #13
Ciary
247 Recognized Expert New Member
np :)

now, you said something about an error in the code. what does it do? is that what you want it to do? are there any errors?
Apr 27 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
7
by: Douglas Buchanan | last post by:
I cannot access certain column values of a list box using code. I have a list box 'lstPrv' populated by the query below. SELECT tblPrv.fkPrvID, lkpCat.CatNm, lkpSrv.SrvNm, lkpCat.pkCatID,...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
4
by: collie | last post by:
HI, I need to populate 2 listboxes from a db. When the page loads then the first listbox needs to be populated and based on selection from that listbox the second listbox needs to be populated...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
5
by: =?Utf-8?B?QmlnU2Ft?= | last post by:
I've a ListBox with the Selection Mode set to Multiple. I want to use the Selected values as the WHERE Parameters in a SQL Data Source. If I set the SQL Data Source to use the Selected Value of the...
9
by: ahilar12 | last post by:
1. <head> 2. <script type="text/javascript"> 3. </script> 4. </head> 5. <body> 6. <form> 7. <select name="team" id="mylist" > 8. <option></option> 9....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.