Jump to content

Recommended Posts

I've got a table that lists office locations by city and state. Sometimes there are several offices in one city. Right now I am using the following code to pull up the citys

 

City: <select name="city" onchange='this.form.submit()'>
				<?php

    				$sql = "SELECT city FROM thelist WHERE state = '$state' ORDER BY city";

				$rs = mysql_query($sql);

				while($row = mysql_fetch_array($rs))
				{
    				extract($row);
  					echo "<option value='$city'>$city</option>";
				}

     				?>
                    </select>

 

But if there is three offices in one city then it will echo out that same city 3 times in the drop down list. What's the best way to correct this so it only shows once?

Link to comment
https://forums.phpfreaks.com/topic/139705-solved-best-practice/
Share on other sites

db connect include then an sql statement...

 

<?php

$sql = "SELECT * FROM $tbl_name WHERE (dtype = '$dtype' OR dtypewc = '$dtype') AND (dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor') $state_where $city_where ORDER BY jpted LIMIT $start, $limit";

$result = mysql_query($sql);

?>

Link to comment
https://forums.phpfreaks.com/topic/139705-solved-best-practice/#findComment-730976
Share on other sites

db connect include then an sql statement...

 

<?php

$sql = "SELECT * FROM $tbl_name WHERE (dtype = '$dtype' OR dtypewc = '$dtype') AND (dmajorp = '$smajor' OR dmajorc1 = '$smajor' OR dmajorc2 = '$smajor' OR dmajorc3 = '$smajor') $state_where $city_where ORDER BY jpted LIMIT $start, $limit";

$result = mysql_query($sql);

?>

 

That doesn't really tell me anything.  Let me rephrase: is $state's value derived by the script, or is it supplied by the user?

Link to comment
https://forums.phpfreaks.com/topic/139705-solved-best-practice/#findComment-730997
Share on other sites

hunna03,

 

I've had to fix many a site (not built by me) that were just querying and didn't escape their sql statements. It doesn't matter what you are trying to do, if it gets injected into your sql statement it can easily be turned into an insert, update, or delete statement (I'm assuming that $state is coming from the client).

Link to comment
https://forums.phpfreaks.com/topic/139705-solved-best-practice/#findComment-731084
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.