I need some help with echoing an SQL field but it keeps showing Resource #4 or does not show anything at all.
My code is
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
$myusername=$_POST['myusername'];
session_register("myusername");
$result = mysql_query("SELECT statsight from playerinfo WHERE username = 'myusername'") or die(mysql_error());
$row = mysql_fetch_array($result);
if(!session_is_registered('myusername')){
header("location:mainlogin.php");
}
echo $row['statsight'];
?>
<html>
<body>
Login Successful
<form name="form2" method="post" action="stat.php">
Stat1: <?php echo "<td>".$row['statsight']."<td>"?>
<input type="submit" value="+">
</form>
</body>
</html>
And it does not show anything. It only shows Stat1: with the + button.
The value of statsight in the database is 3 if it matters, and the myusername information comes from a form.
Got it working using
session_start();
$myusername=$_SESSION['myusername'];
you are not suing variable here.
I am no PHP expert, but this might be the proper way
Although this is not a proper way, you should be using mechanism of Prepared statements while executing queries.