简体   繁体   中英

using php and mysql to display a specific URL in iFrame V2

I´m new to SQL and PHP, and need assistance for below problem.

i have an SQL database, with , for example, "username, password, nationality, class", what i want to do is, a simple PHP or SQL query that will check the user's class field from database and display corresponding URL in a designated iFrame (for example, classes are J1, J2, J3, if the field already contains J3 then upon load display a corresponding URL for that, without any user input. (all will be decided in advance)

You can think of it as a student profile, once the student has successfully logged, the query will read the class field and according to what it finds, it will return a click-able URL with the correct link.

This is way too difficult for the level i am right now, hope someone can shed a bit of light on me.


this is the code after the user is successfully logged in.

<!-- NOTIFICATIONS STARTS HERE -->
<?php
require_once('connection.php');
$id=$_SESSION['SESS_MEMBER_ID'];
$result3 = mysql_query("SELECT * FROM member where mem_id='$id'");
while($row3 = mysql_fetch_array($result3))
{ 
$fname=$row3['fname'];
$country=$row3['country'];
$class=$row3['class'];
$headteacher=$row3['headteacher'];
$attendance=$row3['attendance'];
$homework=$row3['homework'];
$messageparents=$row3['messagestudent'];
}
?>
<table width="468" border="0" align="center" cellpadding="0">
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS">
<table width="468" border="0" align="center" cellpadding="0">
<tr>
<td class="FONTS"><div align="left" class="FONTS"><b>名前:</b></div>
<?php echo $fname ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>国:</b></div>
<?php echo $country ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>クラス:</b></div>
<?php echo $class ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>家庭教師の先生:</b></div>
<?php echo $headteacher ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>出席率:</b></div>
<?php echo $attendance ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>宿題率:</b></div>
<?php echo $homework ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>先生からメッセージ:</b>            
</div>
<?php echo $messagestudent ?></td>
</tr>
</table>
</div></td>
</tr>
</table>
<p align="center" class="FONTS"><a href="index.php">ログアウト</a></p>
<!-- NOTIFICATIONS ENDS HERE -->

it is already working as intended so i will not be changing it unless its completely necessary, i just need to be able to display that URL link.

thanks in advance!

<?php
if($class=='J1')
echo "<a href='www.first_url.com'>Click Here</a>";
else if($class=='J2')
echo "<a href='www.second_url.com'>Click Here</a>"; 
..............
?>

You use this line of code in your page

$id=$_SESSION['SESS_MEMBER_ID'];

Your code is not working because you forget to start session at the top of your page

start_session();// at the top of your page

You should be using PDO or MYSQLi_*, mysql_ is deprecated and is vunerable.

<?php
start_session();

require_once('connection.php');

$id=$_SESSION['SESS_MEMBER_ID'];

$mysqli = new mysqli("myhost","myuser","mypassw","mybd");

if (mysqli_connect_errno()) {

printf("Connect failed: %s\n", mysqli_connect_error());

exit();

}

$result3 = $mysqli->query("SELECT * FROM member WHERE mem_id='$id'");

while($row3 = mysqli_fetch_array($result3))
{ 
  $fname=$row3['fname'];
  $country=$row3['country'];

if($row3['class'] == "J1"){

    $class='<a href="your link here">Your link info here</a>';

} elseif($row3['class'] == "J2") {

    $class='<a href="your link here">Your link info here</a>';

} elseif($row3['class'] == "J3") {

    $class='<a href="your link here">Your link info here</a>';

}else {

    $class='<a href="your link here">Your link info here</a>';

}
$headteacher=$row3['headteacher'];
$attendance=$row3['attendance'];
$homework=$row3['homework'];
$messageparents=$row3['messagestudent'];
}
?>
<table width="468" border="0" align="center" cellpadding="0">
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS">
<table width="468" border="0" align="center" cellpadding="0">
<tr>
<td class="FONTS"><div align="left" class="FONTS"><b>名前:</b></div>
<?php echo $fname ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>国:</b></div>
<?php echo $country ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>クラス:</b></div>
<?php echo $class ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>家庭教師の先生:</b></div>
<?php echo $headteacher ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>出席率:</b></div>
<?php echo $attendance ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>宿題率:</b></div>
<?php echo $homework ?></td>
</tr>
<tr class="FONTS">
<td valign="top"><div align="left" class="FONTS"><b>先生からメッセージ:</b>            
</div>
<?php echo $messagestudent ?></td>
</tr>
</table>
</div></td>
</tr>
</table>
<p align="center" class="FONTS"><a href="index.php">ログアウト</a></p>
<?php
mysqli_close($mysqli);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM