Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
照片上传PHP未定义索引。将照片插入sql数据库_Php_Html_Sql_Image Uploading - Fatal编程技术网

照片上传PHP未定义索引。将照片插入sql数据库

照片上传PHP未定义索引。将照片插入sql数据库,php,html,sql,image-uploading,Php,Html,Sql,Image Uploading,我现在正在使用一个登记表,允许上传个人资料图片的照片。尝试提交时,除了图片索引给出的错误外,所有内容都能成功完成 我坚信这与在表单中运行php有关,因为图片在提交之前没有上传到变量,但我无法通过它 注意:未定义索引:第54行/var/www/registeraccount.php中的照片 注意:未定义索引:第57行/var/www/registeraccount.php中的照片 <?php error_reporting(E_ALL); ini_set('display_errors',"

我现在正在使用一个登记表,允许上传个人资料图片的照片。尝试提交时,除了图片索引给出的错误外,所有内容都能成功完成

我坚信这与在表单中运行php有关,因为图片在提交之前没有上传到变量,但我无法通过它

注意:未定义索引:第54行/var/www/registeraccount.php中的照片

注意:未定义索引:第57行/var/www/registeraccount.php中的照片

<?php
error_reporting(E_ALL);
ini_set('display_errors',"On");
include ('database_connection.php');
$target = "/var/www/profile";

if (isset($_POST['formsubmitted'])) {
    $error = array();//Declare An Array to store any error message  
    if (empty($_POST['name'])) {//if no name has been supplied 
        $error[] = 'Please Enter a name ';//add to array "error"
    } else {
        $name = $_POST['name'];//else assign it a variable
    }

    if (empty($_POST['e-mail'])) {
        $error[] = 'Please Enter your Email ';
    } else {


        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {
           //regular expression for email validation
            $Email = $_POST['e-mail'];
        } else {
             $error[] = 'Your EMail Address is invalid  ';
        }


    }


    if (empty($_POST['Password'])) {
        $error[] = 'Please Enter Your Password ';
    } else {
        $Password = $_POST['Password'];
    }


    if (empty($error)) //send to Database if there's no error '

    { // If everything's OK...

        // Make sure the email address is available:
        $query_verify_email = "SELECT * FROM account  WHERE email ='$Email'";
        $result_verify_email = mysqli_query($dbc, $query_verify_email);
        if (!$result_verify_email) {//if the Query Failed ,similar to if($result_verify_email==false)
            echo ' Database Error Occured ';
        }

        if (mysqli_num_rows($result_verify_email) == 0) { // IF no previous user is using this email .


            // Create a unique  activation code:
            $activation = md5(uniqid(rand(), true));
            $target = $target . basename($_FILES['photo']['name']);

//This gets all the other information from the form
            $pic=($_FILES['photo']['name']);



            $query_insert_user = "INSERT INTO `account` ( `username`, `passwords`, `email`, `picture`) VALUES ( '$name', '$Password', '$Email ' , '$pic')";


            $result_insert_user = mysqli_query($dbc, $query_insert_user);
            if (!$result_insert_user) {
                echo 'Query Failed ';
            }

            if (mysqli_affected_rows($dbc) == 1) { //If the Insert Query was successfull.


                // Send the email:
                $message = " To activate your account, please click on this link:\n\n";
                $message .= WEBSITE_URL . '/activate.php?email=' . urlencode($Email) . "&key=$activation";
                mail($Email, 'Registration Confirmation', $message, 'From: systemadminstrator@theanimator.com');

                // Flush the buffered output.


                // Finish the page:
                echo '<div class="success">Thank you for
registering! A confirmation email
has been sent to '.$Email.' Please click on the Activation Link to Activate your account </div>';


            } else { // If it did not run OK.
                echo '<div class="errormsgbox">You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
            }

        } else { // The email address is not available.
            echo '<div class="errormsgbox" >That email
address has already been registered.
</div>';
        }

    } else {//If the "error" array contains error msg , display them



echo '<div class="errormsgbox"> <ol>';
        foreach ($error as $key => $values) {

            echo '  <li>'.$values.'</li>';



        }
        echo '</ol></div>';

    }

    mysqli_close($dbc);//Close the DB Connection

} // End of the main Submit conditional.



?><!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=utf-8" />
<title>Registration Form</title>





<style type="text/css">
//CSS Once again removed because it has nothing to do with the issue.
</style>

</head>
<body>


<form action="registeraccount.php" method="post" class="registration_form" enctype="multipart/form-data">
  <fieldset>
    <legend>Registration Form </legend>

    <h2 style="text-align:center">Create an account!</h2>
    <p style="text-align:center"> <span>Already a member? <a href="login.php">Log in</a></span> </p>

    <div class="elements">
      <label for="name">Name :</label>
      <input type="text" id="name" name="name" size="25" />
    </div>
    <div class="elements">
      <label for="e-mail">E-mail :</label>
      <input type="text" id="e-mail" name="e-mail" size="25" />
    </div>
    <div class="elements">
      <label for="Password">Password:</label>
      <input type="password" id="Password" name="Password" size="25" />
      <p>
              Photo:
            </p>
            <input type="hidden" name="size" value="350000">
            <input type="file" name="photo"> 
            <p>
      </div>

      <br />

    <div class="submit">
     <input type="hidden" name="formsubmitted" value="TRUE" />
      <input type="submit" value="Register" />

    </div>
  </fieldset>
</form>
<button onclick="window.location='theanimator.html';">Go Back!</button>
</body>
</html>

只需添加一个条件来检查是否上传了照片

if(!isset($_FILES['photo'])) {
    $error[] = "No photo selected !";
}

据我目前所知,您将
$target
分配为
/var/www/profile
而没有结尾可能是一个问题。尝试向其中添加一个=
/var/www/profile/
。这是一个通知,当用户没有上传我正在用图像测试的照片时会发生这种情况。现在要尝试斜杠,并给弗雷德发短信。将发布结果Nope不起作用。奇怪的是,查看SQLWorkbench时,列图片不是空的,而是空的。。。还有其他建议吗?@ZachHarvey好的,随时通知我。看起来很奇怪的是
$target=$target中的双重
$target
。basename($_文件['photo']['name']).OMG!非常感谢你!工作完美。我从未确认图片是否在那里,因此全局变量从未被记录!现在明白了!非常感谢ionutvmi!!!!这确实适用于名称,但实际上并不上传照片。我知道这不是最好的做法,因为它可能会占用空间,但当试图在个人资料页面上使用照片时,除非上传否则它不会起作用。我认为你需要使用默认图像,以防用户不上传照片,并更改你的代码,如果(isset($_FILES['photo')){//上传}否则{//添加默认图像}再次感谢您ionutvmi!