I am a college student taking a course in php and mysql progamming and my first question is about the "$variable" variables in the following code:
<?php ob_start(); ?>
<?php
session_start();
if ($_SESSION['auth'] != "true")
{ header("Location: login.php");
exit;
}
$uid = $_SESSION['user'];
$connection = mysql_connect("localhost", "username", "password");
mysql_select_db("username", $connection);
$result = mysql_query ( "SELECT * FROM users where user_id = '$uid'",
$connection);
$num = mysql_numrows($result);
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"firstname");
$f2=mysql_result($result,$i,"lastname");
?>
<html><body>
<p>
<td><center><font size = "18" face="Arial"><?php echo "Name: $f1 "; echo $f2; ?> </font></center></td>
</p>
</body></html>
<?php
$i++;
}
?>
<?php
$result1 = mysql_query ( "SELECT * FROM phone where user_id = '$uid'", $connection);
$num1 = mysql_numrows($result1);
$j=0;
while ($j < $num1) {
$f3=mysql_result($result1,$j,"type");
$f4=mysql_result($result1,$j,"number");
?>
<html><body>
<p>
<br>
<td><center><font size = "12" face="Arial"><?php echo "$f5: "; echo "($f3) "; echo "$f4 <br />"; ?> </font></center></td>
</p>
</body></html>
<?php
$j++;
}
?>
<?php
$result2 = mysql_query ( "SELECT * FROM address where user_id = '$uid'", $connection);
$num2 = mysql_numrows($result2);
$h=0;
while ($h < $num2) {
$f6=mysql_result($result2,$h,"type");
$f7=mysql_result($result2,$h,"address");
$f8=mysql_result($result2,$h,"city");
$f9=mysql_result($result2,$h,"state");
$f10=mysql_result($result2,$h,"zip");
?>
<html><body>
<p>
<br>
<td><center><font size = "12" face="Arial"><?php echo "$f10 Address: $f6, $f7, $f8 $f9"; ?></font></center></td>
</p>
</body></html>
<?php
$h++;
}
?>
<?php
include 'navbar.php';
ob_end_flush();
?>
I just don't really understand the $variables at all. Are they user-generated or are they entities in the database? And how does the code know which $result is which?
My second question is that, if this was someone else in my class's code and I wanted to modify it to make it my own and substitute my own variables, how would I go about doing that? Do the $variables need to be changed if they are not user-defined and if so, how? I apologize if these are dumb questions, but I am a beginner at this programming language. Thanks in advance for your help.
-Jeff