4

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!

Reena Parekh
  • 933
  • 1
  • 8
  • 24
  • 1
    If your just starting, why are you using old methods? The mysql function has been killed for a while now. When learning new things, like PHP, learn from newer guides and tutorials. You should be using mysqli or PDO. – Wade May 27 '15 at 08:31
  • This is your full code??? – Saty May 27 '15 at 08:33
  • well, its not like ive started now, i studied long ago and just retook it, but i consider my lvl as starter, and no, this code is just the results code, there are other 3 files involved. – Walter P Steiner May 27 '15 at 23:43

3 Answers3

1
<?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>"; 
..............
?>
abh
  • 1,189
  • 2
  • 14
  • 30
0

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
Saty
  • 22,443
  • 7
  • 33
  • 51
0

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);
?>
Jamie Harding
  • 383
  • 3
  • 22
  • thanks for answering! and for taking the time to converting the code to the new system wich i had no idea it changed, this script uses at least 4 files, and as i can see all are using the old stuff, i will study what you have left to me and i will try to convert my other files onto this new scheme. thanks a lot! – Walter P Steiner May 27 '15 at 23:48