我想在验证用户名和密码后将图像和文本存储在数据库中?
我有两个文件:
- 登录.html
- 插入.php
登录.html
<html>
<body>
<form action="insert.php" method="post">
username <input type="text" name="username" />
password <input type="text" name="password" />
image <input type="file" name="image" />
message <input type="text" name="message" />
<input type="Submit" /></form>
插入.php
<?php
$conn_error='could not connect.';
$mysql_host='localhost';
$mysql_user='ommzbocg_myappu';
$mysql_pass='d*BQTk2zScNb';
$mysql_db='ommzbocg_myapp';
$tbl_name='data';
$username=$_POST['username'];
$password=$_POST['password'];
$image=$_POST['image'];
$message=$_POST['message'];
if(!@mysql_connect($mysql_host, $mysql_user, $mysql_pass) ||!@mysql_select_db($mysql_db))
{ die($conn_error);
}
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
// mysql_num_row 正在统计表行 $count=mysql_num_rows($result);
// 如果结果匹配 $myusername 和 $mypassword,表行必须是 1 行 if($count==1){
$query = "INSERT INTO data VALUES('$username','$password','$image','$message')";
}else{
echo '0';
}
if($query)
{
echo "1";
}
else
{
echo"Error";
}
mysql_query($query);
mysql_close();
?>
我只能进行身份验证,但我无法存储图像和数据。