Editing Specific column in a row
Posted: Thu Dec 18, 2008 12:15 pm
Hey guys, just joined this forum, just started PHP a couple days ago, so please don't flame if I'm doing something stupidly wrong xD
I started making an avatar displaying page, it gets displayed on members.php
Basically, on members.php in a form, they send POST data to avatar.php that tells avatar to edit the column avatar in their row.
This is members.php:
And it seems to be working correctly.
avatars.php executes without any direct errors, but doesn't actually edit the row, and I think the problem is something wrong with this line:
In case that's not the problem, here's all of avatars.php:
I started making an avatar displaying page, it gets displayed on members.php
Basically, on members.php in a form, they send POST data to avatar.php that tells avatar to edit the column avatar in their row.
This is members.php:
Code: Select all
<?php
ob_start();
session_start();
include("config.php");
// connect to the mysql server
$link = mysql_connect($servername, $dbusername, $dbpassword)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($dbname)
or die ("Could not select database because ".mysql_error());
$match = "select * from $table where username = '$username'
and password = '$password'";
$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$Query = mysql_fetch_assoc($qry);
?>
<html>
<head>
<title>Members' Section</title>
</head>
<body>
<?php
if (!isset($_SESSION['Logged_in']))
{
echo "<center>";
echo "You are not logged in!<br><a href=login.html>log in</a>";
echo "</center>";
return false;
} else {
$userid = $_SESSION["userid"];
$username = $_SESSION["username"];
$password = $_SESSION["password"];
$wepname = $_SESSION["wepname"];
$name = $_SESSION["name"];
$level = $_SESSION["level"];
$avatar = $_SESSION['avatar'];
echo "<center>";
echo "Hello $name.";
echo "You are logged in as $username.<p> and you are level $level.<p>";
echo "Your password is $password. and the name of your weapon is $wepname.<p>";
echo "You are also id: $userid. and your avatar URL is: $avatar.";
}
?>
<form action="avatar.php" method="post">
<font face='Arial' size='5'color="#736AFF">Avatar URL:</font> <span><input type="text" name="avatar" size="150"></span><br />
<input type="submit" value="Apply">
</form>
Avatar:
<?php
echo "<img src=\"$avatar\" width=200 height=200 alt=Avatar />";
?>
<a href="logout.php">Log out</a>
</center>
</body>
</html>
avatars.php executes without any direct errors, but doesn't actually edit the row, and I think the problem is something wrong with this line:
Code: Select all
$sql = 'UPDATE `12219_gonline`.`users` SET `avatar` = $avatar WHERE `users`.`id` = $userid;';Code: Select all
<?php
ob_start();
session_start();
include("config.php");
// connect to the mysql server
$link = mysql_connect($servername, $dbusername, $dbpassword)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($dbname)
or die ("Could not select database because ".mysql_error());
$match = "select * from $table where username = '$username'
and password = '$password'";
$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$wepname = $_SESSION['wepname'];
$name = $_SESSION['name'];
$level = $_SESSION['level'];
$avatar = $_POST['avatar'];
$sql = 'UPDATE `12219_gonline`.`users` SET `avatar` = $avatar WHERE `users`.`id` = $userid;';
if ( !mysql_query($sql) ) {
echo("not successful");
} else {
echo "Your avatar has been successfully saved!<br>";
$_SESSION['avatar'] = $Query['avatar'];
echo "Now you can <a href=members.php>view it!</a>";
}
// print a success message
?>