从编辑配置文件将图像上载到数据库以替换旧的

时间:2014-12-11 08:18:34

标签: php

这是我的项目,这是我的问题,我无法制作更新profil图片的代码 我希望用户可以上传他们的图片为他们描绘图片并替换我们在注册时自动设置的旧图片。 任何人都可以帮我修改我的代码吗? 如果你找到“浏览”字样

<?php
include 'session.php';

if (!empty($_POST["action"])){
include 'connection.php';
if($_POST['tfname']!='' && $_POST['tpass1']!='' && $_POST['tpass2']!='' && $_POST['tpass1']==$_POST['tpass2']){
$sql="update user_login set email='".$_POST['temail']."', first_name='".$_POST['tfname']."', last_name='".$_POST['tlname']."', password='".$_POST['tpass1']."' where email='".$_POST['temail']."'";
$result=mysql_query($sql)or die(mysql_error());
header("location: general.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration</title>

<link rel="stylesheet" type="text/css" href="all.css">
<body  background="image/background.jpg">
<?php include('header2.php'); ?>
<table border="1" bgcolor="#FBFBEF" width="100%">
    <tr>
<td align="left" width="90%"><b><a href="mainforum2.php" ><img src="image/homeicon.png" widht="40" height="40"></a>-&gt;<a href="general.php">General Discussion</a>-&gt; Edit Profile</b></td>
    </tr>
</table>
    <?php 
    include 'connection.php';
    $sql="select * from user_login where email='".$_SESSION['user_forum']."'";
    $result=mysql_query($sql);
    $row=mysql_fetch_array($result);
    ?>

<table border="1" width="80%" height="500" align="center" bgcolor="#FBFBEF" ><form id="form1" name="form1" method="post" action="">
        <tr>
            <td widht="20" align="center" valign="top" id="loginform"><strong><font size="10"> Register Form</font></strong>
                <table border="1" width="60%" height="150"  align="center"   >
                    <tr>
                    <td valign="top" colspan="3"><strong>Account Information</strong></td>
                    </tr>
                    <tr>
                    <td colspan="3" align="center"><img src="<?php echo $row['image'];?>"/></td>
                    </tr>
                    <tr>
                    <td colspan="3" align="center"><font color="green">Browse</font></td>
                    </tr>
                    <tr>
                    <td valign="top" width="50%">Email</td><td>:</td><td><input name="temail" type="text" id="temail" maxlength="50" size="29" readonly="true" value="<?php echo $row['email'];?>" /></td>
                    </tr>
                    <tr>
                    <td valign="top">Password</td><td>:</td><td><input name="tpass1" type="password" id="tpass1" size="29" value="<?php echo $row['password'];?>" /></td>
                    </tr>
                    <tr>
                    <td valign="top">Retype Password</td><td>:</td><td><input name="tpass2" type="password" id="tpass2" size="29" value="<?php echo $row['password'];?>" />
            <input name="action" type="hidden" id="action" value="edit" /></td>
                    </tr>
                    <tr>
                    <td valign="top" colspan="3"><strong>Personal Information</strong></td>
                    </tr>
                    <tr>
                    <td valign="top">First Name</td><td>:</td><td><input name="tfname" type="text" id="tfname"size="29" value="<?php echo $row['first_name'];?>" /></td>
                    </tr>
                    <tr>
                    <td valign="top">Last Name</td><td>:</td><td><input name="tlname" type="text" id="tlname"  size="29" value="<?php echo $row['last_name'];?>" /></td>
                    </tr>

                    <tr>
                    <td align="right" valign="top">Before Country</td><td>:</td><td><input type="text" name="country" readonly="true" size="29" value="<?php echo $row["country"];?>"/></td>
                    </tr>


                    <tr>
                    <td valign="top">Country</td><td>:</td>
                        <td width="65%" >
                        <select name="tcountry" id="tcountry">
                    <option value="">Country</option>
                    <option value="Afganistan">Afghanistan</option>
                    <option value="Albania">Albania</option>
                    <option value="Algeria">Algeria</option>
                    <option value="American Samoa">American Samoa</option>
                    <option value="Andorra">Andorra</option>
                    <option value="Angola">Angola</option>
                    <option value="Anguilla">Anguilla</option>
                </select>
                        </td>
                    </tr>

                    <tr>
                        <td colspan="3" align="center"><input type="submit" name="Submit" value="Save" /></td>

                    </tr>
                </table>    
            </td>
        </tr>

    </form>
    </table>
</font>
</body>
<?php include('footer.php'); ?>
</head>
</html>

这是我的最后一个代码

1 个答案:

答案 0 :(得分:0)

您好尝试添加enctype =&#34; multipart / form-data&#34;如下图所示并检查。

<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data" >