0

I'm trying to use a drop down menu to load data from a select value. I want it passed into a php document in order to use the data that I need. What should I do? Thanks in advance.

This is my code for the select menu:

$sqlz = "SELECT * FROM content_temp1 WHERE user_uname='$uname'";
$resultz = mysql_query($sqlz);
$checkz = mysql_numrows($resultz);
$count = 0;
?>
<select name="ltemp">
<?php
while($count<$checkz){
    $selectname=mysql_result($resultz,$count,"temp1_name");
    ?>
    <option value="<?php echo "$selectname";?>"><?php echo $selectname;?></option>
    <?php
    $count++;
}
?>
</select>
<input type="submit" value="Load Template" class="ufbutton"><br></center>
            </form>

and this is my php page

$uname = $_GET['username'];
$loadtemp = $_POST['ltemp'];

header("Location:editing1.php?username=$uname&tempname=$loadtemp");
e-sushi
  • 13,786
  • 10
  • 38
  • 57
bjmonts
  • 15
  • 7

2 Answers2

0

it seems that you have use " inside " in this line :

<option value="<?php echo \"$selectname\";?>"><?php echo $selectname;?></option>

try this:

$sqlz = "SELECT * FROM content_temp1 WHERE user_uname='$uname'";
$resultz = mysql_query($sqlz);
$checkz = mysql_numrows($resultz);
$count = 0;
?>
<select name="ltemp">
<?php
while($count<$checkz){
    $selectname=mysql_result($resultz,$count,"temp1_name");
    ?>
    <option value="<?php echo \"$selectname\";?>"><?php echo $selectname;?></option>
    <?php
    $count++;
}
?>
</select>

Alternative :

 $sqlz = "SELECT * FROM content_temp1 WHERE user_uname='$uname'";
 $resultz = mysql_query($sqlz);
 ?>
<select name="ltemp">
<?php
  while ($row = mysql_fetch_array($resultz, MYSQL_ASSOC)) {
         $selectname=$row["temp1_name"];
            ?>
            <option value="<?php echo \"$selectname\";?>"><?php echo $selectname;?></option>
     <?php } ?>

 </select>
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
0

Be careful this is ripe for sql injection without validating the input;

SQL Injection with GET

Community
  • 1
  • 1
HeavyHead
  • 310
  • 3
  • 11