我的PHP代码有点问题 [英] I am having alittle problem with my php code

查看:49
本文介绍了我的PHP代码有点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的唯一问题是我希望每个用户都能看到他们的照片。他们的数据显示正确,但只有一个图像显示所有用户配置文件,我的所有图像都存储在图像文件夹中上传



这里是我的 login.php在我的表格行动上



session_start();

header('Location:account.php');

?>

//连接到数据库

require('config.php');

//为此脚本设置用户名和密码变量

$ user = mysql_real_escape_string($ _ POST [username]);

$ pass = mysql_real_escape_string($ _ POST [password]);

//确保用户名和密码匹配,如果有的话,从数据库中选择所有客户端的

//数据。将数据存储到$ clientdata

$ clientdata = mysql_query(SELECT * FROM $ tbl_name WHERE username ='$ user'和password ='$ pass')

或die(mysql_error());

//将$ clientdata查询放入我们可以使用的数组中

$ data = mysql_fetch_array($ clientdata,MYSQL_ASSOC);

//如果用户名和密码匹配,我们的

// $ clientdata数组中应该有一个条目。如果没有,我们应该有0.所以,我们可以使用一个简单的

// if / else语句

if(mysql_num_rows($ clientdata)== 1){< br $>
$ _SESSION ['username'] = $ user;

$ _SESSION ['firstname'] = $ data ['firstname'];

$ _SESSION ['lastname'] = $ data ['lastname'];

$ _SESSION ['address'] = $ data ['address'];

$ _SESSION ['nationality'] = $ data ['nationality'];

$ _SESSION ['photo'] = $ data ['photo'];

?>

}其他{echo点击登录再试一次或注册一个帐户。

谢谢你;}

?>



在我的土地页面上这是显示数据和图像的脚本。











if($ rows ['photo']){

$ row = $ rows [ 'photo'];

$ imagepath =< img width'60'height ='70'src ='upload / $ row'>;



echo $ imagepath;

}

else {

echo< img width'60'height = '70'src ='upload / no_image.png' >中;

}



?>

the only problem i am having is that i want each user to see their pictures. their data are displaying correctly but is only one image that shows at all the user profile and all my image are stored in the image folder "upload"

here is my "login.php" on my form action

session_start();
header('Location: account.php');
?>
// Connect to the database
require('config.php');
// Set username and password variables for this script
$user = mysql_real_escape_string($_POST["username"]);
$pass = mysql_real_escape_string($_POST["password"]);
// Make sure the username and password match, selecting all the client's
// data from the database if it does. Store the data into $clientdata
$clientdata = mysql_query("SELECT * FROM $tbl_name WHERE username='$user' and password='$pass'")
or die (mysql_error());
// Put the $clientdata query into an array we can work with
$data = mysql_fetch_array($clientdata, MYSQL_ASSOC);
// If the username and password matched, we should have one entry in our
// $clientdata array. If not, we should have 0. So, we can use a simple
// if/else statement
if(mysql_num_rows($clientdata) == 1){
$_SESSION['username'] = $user;
$_SESSION['firstname'] = $data['firstname'];
$_SESSION['lastname'] = $data['lastname'];
$_SESSION['address'] = $data['address'];
$_SESSION['nationality'] = $data['nationality'];
$_SESSION['photo']=$data['photo'];
?>
}else{echo "Click Login to try again or Register for an account.
Thank You";}
?>

on my land page this is the script that display data and image.





if ($rows['photo']) {
$row = $rows['photo'];
$imagepath = "<img width'60' height='70' src='upload/$row' >";

echo $imagepath ;
}
else {
echo "<img width'60' height='70' src='upload/no_image.png' >" ;
}

?>

推荐答案

user = mysql_real_escape_string(
user = mysql_real_escape_string(


_POST [username]);
_POST["username"]);


pass = mysql_real_escape_string(
pass = mysql_real_escape_string(


这篇关于我的PHP代码有点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆