从html页面添加图像

时间:2015-01-02 14:38:30

标签: php html mysql

我想将图片或文件添加到我的数据库中,最多可容纳5人。在html页面中,用户选择他们的文件以及想要共享和提交的人。但我陷入了文件部分。它让我犯错。

这是我的数据库代码:

Create Database webpage;
use webpage
Create table user(Firstname varchar(40) NOT NULL,Lastname Varchar(40) NOT NULL,username varchar(20) NOT NULL,password varchar(16) NOT NULL,address varchar (70),university varchar (75),approval INT,PRIMARY KEY (username));
Create Table datas(Username varchar(20),imagesnotes LONGBLOB NOT NULL,Foreign Key (Username) References user(username));
Create Table Administrator(Firstname varchar(40) NOT NULL,Lastname Varchar(40) NOT NULL,username varchar (20) UNIQUE NOT NULL,password varchar (16) NOT NULL);
Create Table userdata(username varchar(20) NOT NULL,imagesnotes LONGBLOB NOT NULL,sharedpeople varchar (100) NOT NULL);
ALTER TABLE userdata
ADD FOREIGN KEY (sharedpeople)
References user(username);

这是我的php页面,用户将选择他们的文件和想要分享的人: upload.php的

<html>
<body>
<?php
session_start();
$username =$_SESSION["uname"];
?>
<h3>Hello again, <?php echo $username; ?>. From here, you can upload your photos or texts for only 5 people. So make your decisions carefully.</h3>
<br></br>
<br></br>
<br></br>
<br></br>
<br></br>

<form action="uploaded.php" method="post" enctype="multipart/form-data">
  Select image or text to upload:
    <input type="file" name="image" value='Select folder to upload'>

  <br></br>
  <br></br>
  People You Want To Choose:
  <br>
  <?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql= mysqli_query($con, "SELECT username FROM user");

echo "Username 1";

echo'<select name="username1">';
echo'<option value="" selected="selected">Select a Username</option>';

while($row = mysqli_fetch_array($sql))

{
    echo'<option value="' . $row['username'] . '">'. $row['username'] .'</option>';
}
echo'</select></p><p>';

mysqli_close($con);
?>       

 <?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql= mysqli_query($con, "SELECT username FROM user");

echo "Username 2";

echo'<select name="username2">';
echo'<option value="" selected="selected">Select a Username</option>';

while($row = mysqli_fetch_array($sql))

{
    echo'<option value="' . $row['username'] . '">'. $row['username'] .'</option>';
}
echo'</select></p><p>';

mysqli_close($con);
?>       

 <?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql= mysqli_query($con, "SELECT username FROM user");

echo "Username 3";

echo'<select name="username3">';
echo'<option value="" selected="selected">Select a Username</option>';

while($row = mysqli_fetch_array($sql))

{
    echo'<option value="' . $row['username'] . '">'. $row['username'] .'</option>';
}
echo'</select></p><p>';

mysqli_close($con);
?>      

 <?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql= mysqli_query($con, "SELECT username FROM user");

echo "Username 4";

echo'<select name="username4">';
echo'<option value="" selected="selected">Select a Username</option>';

while($row = mysqli_fetch_array($sql))

{
    echo'<option value="' . $row['username'] . '">'. $row['username'] .'</option>';
}
echo'</select></p><p>';

mysqli_close($con);
?>       

 <?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql= mysqli_query($con, "SELECT username FROM user");

echo "Username 5";

echo'<select name="username5">';
echo'<option value="" selected="selected">Select a Username</option>';

while($row = mysqli_fetch_array($sql))

{
    echo'<option value="' . $row['username'] . '">'. $row['username'] .'</option>';
}
echo'</select></p><p>';

echo'<input type="submit" value="Submit" />';


mysqli_close($con);
?>        
</br>

</form>
</body>
</html>

这是我的php确认操作: uploaded.php

我现在没有把sql查询。首先,如果所有部分都为空,我想要这样做,它必须给我带来错误,没有文件或要分享的人。但是我一直收到这些错误:

“注意:未定义的索引:第15行的C:\ wamp \ www \ Project2 \ members \ uploaded.php中的图像” 我该怎么办?

感谢。

更新: 我的功能有问题。我想这样做,如果有什么来自sql查询进行另一个查询,如果它没有带来任何显示消息,但我什么都没得到: uploaded.php:

<?php
session_start();
$username =$_SESSION["uname"];
?>
 <?php
$con = mysqli_connect("localhost", "root", "", "webpage");
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username1 = $_POST["username1"];
$username2 = $_POST["username2"];
$username3 = $_POST["username3"];
$username4 = $_POST["username4"];
$username5 = $_POST["username5"];
$image = $_FILES["image"];

$sql = "select username from user where username = '$username1'";
$res = mysqli_query($con,$sql);
$row = mysqli_fetch_array($res,MYSQLI_NUM);

while($row==1){

$sql2 = mysqli_query($con,"insert into userdata values '$username','$image','$username1'");
if (!mysqli_query($con,$sql)) 
{
  die('Error: ' . mysqli_error($con));
}
echo "1 file added";
}if(empty($sql)){
 echo "you didn't select anybody or a file";
}
 mysqli_close($con);
?>

0 个答案:

没有答案