nunu nunu - 1 year ago 35
MySQL Question

confused in echo mysql result inside echo

after sign in and redirect to next page, i check the user with

$_SESSION
.
Then if username valid, i want to show dropdown list which the list is get from database. I am confuse how to
echo
.

<?php
session_start(); //Start the session
if(!isset($_SESSION['pic']))
{
header('Location:index.php?p=signin');
}
else {
echo '<div class="form-group">
<label for="symcat" class="control-label">Symptom Category</label>
<select id="symcat" name="symcat" class="selectlist form-control">
<option value=""></option>
$sql='SELECT category FROM sym_category';
if ($sql) {
$res=mysqli_query($dbc,$sql) or die(_ERROR26.': '.mysqli_connect_error());
}
while ($dat = mysqli_fetch_array($res, MYSQLI_NUM)) {
echo '\t<option value="'.$dat[0].'">'.$dat[0].'</option>\n';
}
mysqli_free_result($res);
</select>
</div> <!-- /form-group -->';
}
?>

Answer Source

As Akintunde & SheperOfFire said the nice and tidy way is like :

<?php
session_start(); //Start the session
if(!isset($_SESSION['pic']))
{
   header('Location:index.php?p=signin');
}
else {
   header('Location:index.php?p=forminputcar');
   }
?>

Because, inside of forminputcar has php tag and echo also. Or you can also put above script at the top of forminputcar page. So, if session match we stay on current page.

<?php
session_start();

if(isset($_SESSION['pic']))
{
   header('charset=UTF-8');
}
else {
   header('Location:index.php?p=signin');
   }
?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download