Reputation: 429
Hello having a bit of problem retrieving a value so i might use it. This is is where i should get my value.
<input type="text" class="typed" readonly="readonly" name="levele"
value="<?php
if($get_display->level== "Grade 2") {
echo "Grade 4"; $lbl="Grade 4";
}?>">
For a simple test i will use the value Grade 4 because i know what the outcome I'm suppose to have. This is the code that i want to retrieve the value of "levele" so it may perform a SQL statement. For example i have 5 sections that are for grade 4 so i was thinking on using this sql statement.
<select name="section_id">
<option>SECTIONS</option>
<?php
$result = mysql_query("SELECT * FROM tbl_section where level='".$_GET['levele']."'");
while($row = mysql_fetch_array($result))
{
echo '<option value='.$row['section_id'].'>' .$row['section_name']. '</option>';
}
?>
</select>
So far i am unable to retrieve "levele" so it may be used it the sql, also tried $_POST and $_request but nothing and i check if levele does have the value Grade 4 and it does also in my database. Would appreciate any help on this. Because after i have retrieve the 5 sections I will try to automatically select one section where for example if the student has a grade of 90 the section should be "A" I'm going to do it with if else. so i would appreciate any help to solve these problems.
Upvotes: 1
Views: 116
Reputation: 760
<input type="text" class="typed" readonly="readonly" name="levele" value="<?php if(
$get_display->level== "Grade 2"){ echo "Grade 4"; **$lbl="Grade 4";**}?>">
remove ** portion and run ....
<select name="section_id">
<option>SECTIONS</option>
<?php
$result = mysql_query("SELECT * FROM tbl_section where level='".$_GET['levele']."'");
while($row = mysql_fetch_array($result))
{
echo '<option value='.$row['section_id'].'>' .$row['section`enter code here`_name']. '</option>';
}
?>
</select>
Upvotes: 0
Reputation: 33542
I see three main problems here that I think you should address:
Firstly, in your code at the top:
<input type="text" class="typed" readonly="readonly" name="levele" value="<?php if(
$get_display->level== "Grade 2"){ echo "Grade 4"; $lbl="Grade 4";}?>">
Your code will only echo and set a value if $get_display->level
is equal to 2. Did you mean to add in an else statement as well in case the value is something other than Grade 2
perhaps?
<?php
if($get_display->level== "Grade 2")
{
echo "Grade 2"; $lbl="Grade 2";
}
else
{
echo "Grade 4"; $lbl="Grade 4";
}
?>
<input type="text" class="typed" readonly="readonly" name="levele" value="<?php echo $lbl; ?>">
Secondly, your form section of code seems to be missing quotes around the values:
echo '<option value='.$row['section_id'].'>' .$row['section_name']. '</option>';
I think you meant to use this:
echo '<option value="'.$row['section_id'].'">' .$row['section_name']. '</option>';
Lastly, your code is very vulnerable to injection attacks. You really should look at moving to PDO and prepared statements when dealing with form data.
Edit: This is just an afterthought, but I can't see anywhere that you set $result
to a valid connection, but I assume that this is somewhere else in your code.
Upvotes: 2