$ _FILE申请$ _poST

时间:2018-04-29 04:02:08

标签: php sql file post phpmyadmin

我是PHP的初学者,刚开始学习它。我正在尝试制作注册页面和登录页面。我选择usernamepassword后,我的登录页面正常工作,它也可以检测到错误的密码,但我通过注册页面上传的个人资料图片没有出现在欢迎页面上。添加配置文件后,登录页面根本不再有效。我希望你们能理解我的问题并帮助我找到解决方案。先感谢您。我附上下面的代码:

REGISTER FORM PHP

<?php
session_start();
$_SESSION['message'] = '';
$mysqli=new MySQLi('127.0.0.1','root','','accounts');

if($_SERVER["REQUEST_METHOD"] == "POST") {
    if ($_POST['password']== $_POST['confirmpassword']) {

        $username = $mysqli->real_escape_string($_POST['username']);
        $email = $mysqli->real_escape_string($_POST['email']);
        $password = md5($_POST['password']);
        $profile_path = $mysqli->real_escape_string('images/'.$_FILES['profile']['name']);


        if (preg_match("!image!", $_FILES['profile']['type'])) {

            if (copy($_FILES['profile']['tmp_name'],$profile_path)){
                $_SESSION['username'] =$username;
                $_SESSION['profile'] =$profile_path;


                $sql ="INSERT INTO users(username,email,password,profile)"
                ."VALUES ('$username','$email','$password','$profile_path')";       

                if($mysqli->query($sql)=== true) {
                          $_SESSION['message'] =  'Registration successful!
                          Added $username to the database!';
                     header("location:RegisterLogin.php");
                      }
                      else {
                          $_SESSION['message'] = "User could not be added to the database!";
            }
        }
        else{
            $_SESSION['message'] = "file failed!";

        }
        }
        else {
            $_SESSION['message'] = "Please only upload GIF,JPG, or PNG images!";
    }
    }
    else{
        $_SESSION['message'] = "two password do not match!";
    }
    }

?> 
lOGIN fORM

    <?php 
    session_start();
    $_SESSION['message']=''; 
    $mysqli=new MySQLi('127.0.0.1','root','','accounts');



    if(isset($_POST['login'])) {
        $username = $mysqli->real_escape_string($_POST['username']);
            $password = md5($_POST['password']);
            $profile_path = $mysqli->real_escape_string(isset($_FILES['profile']));
             $sql="SELECT * FROM users WHERE username='$username' AND password='$password' AND profile = 'profile_path'";
          $result = mysqli_query($mysqli,$sql);

            if(mysqli_affected_rows($mysqli) == 1){
                  $_SESSION['username'] = $username;
                  $_SESSION['profile'] = $profile_path;
                  $_SESSION['message'] =  "Registration successful!";
        header("location:Welcome.php");
        }
        else{
            $_SESSION['message'] = "Login Failed!"; 
        }
    }



    ?>

欢迎使用PHP

<link rel="stylesheet" href="Form2.css" />
<?php session_start(); ?>
<div class="body content">
<div class="welcome">
<div class="alert alert-success"><?= $_SESSION['message']?></div>
Welcome To Your Profile <span class="user"><img src='<?=$_SESSION['profile']?>'</span>

2 个答案:

答案 0 :(得分:0)

您正在login.php中错误地设置会话值。在下面的代码中,使用mysqli_fetch_array()来检索$ _SESSION变量的正确值。

<强>的login.php

试试这个:

_SECTION_BEGIN("T+4 day ");
Title = " ..:: duy ::.. - Filter of Stock " + " " + FullName() + " " + Date( ) ;
// 4-Day-Range Switch
prev=AMA2(C,1,0);
d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
a=Cross(Close,d);
b=Cross(d,Close);
state=IIf(BarsSince(a)<BarsSince(b),1,0);
s=state>Ref(state,-1);
ss=state<Ref(state,-1);
sss=state==Ref(state,-1);
col=IIf(state == 1 ,51,IIf(state ==0,4,1));
Plot(C,"",Col,128);

Buy=s;
Sell=ss;


PlotShapes( shapeUpArrow * s ,6,0,L);
PlotShapes( shapeDownArrow *ss ,4,0,H);


dist = 0.8*ATR(10);
dist1 = 2*ATR(10);
for( i = 0; i < BarCount; i++ )
{
    if( Buy )
    {
        PlotText( "\nBuy:" + L[ i ] + "\nT= " + (L*1.005) + "\nSL= " + (L*0.9975), i, L[ i ]-dist, colorGreen, colorWhite );
    }
    if( Sell )
    {
        PlotText( "Sell:" + H[ i ] + "\nT= " + (H*0.995) + "\nSL= " + (H*1.0025), i, H[ i ]+dist1, colorRed, colorWhite );
    }
}

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

if ( LastValue(Buy)==1)
{
    quantity=2;
    orderId=placeOrderFuture("MCX", "FUTCOM", ChartSymbol, "BUY", "INTRADAY", "MARKET", quantity, 0, defaultTriggerPrice(), "19-APR-2018", defaultStrategyId(), defaultComments());
    //orderId = placeOrderUsingParams(tradeType, AT_ORDER_TYPE, AT_QUANTITY, buyPrice, defaultTriggerPrice(), 1);
}

if ( LastValue(Sell) == 1 )
{
    quantity=2;
    orderId=placeOrderFuture("MCX", "FUTCOM", ChartSymbol, "SELL", "INTRADAY", "MARKET", quantity, 0, defaultTriggerPrice(), "19-APR-2018", defaultStrategyId(), defaultComments());
    //orderId = placeOrderUsingParams("SELL", AT_ORDER_TYPE, AT_QUANTITY, sellPrice, defaultTriggerPrice(), 1);
}

Welcome.php

<?php session_start(); $_SESSION['message']=''; $mysqli=new MySQLi('127.0.0.1','root','','accounts'); if(isset($_POST['login'])) { $username = $mysqli->real_escape_string($_POST['username']); $password = md5($_POST['password']); $sql="SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1;"; $result = mysqli_query($mysqli,$sql); if(mysqli_num_rows($result)>0){ $row = mysqli_fetch_array($result); $_SESSION['username'] = $row['username']; $_SESSION['profile'] = $row['profile']; $_SESSION['message'] = "Registration successful!"; header("location:Welcome.php");exit(); } else{ $_SESSION['message'] = "Login Failed!"; } } ?> 移至文档的最顶层。在调用session_start()之前,您无法输出任何内容(HTML内容或回声),否则会话将失败,除非使用输出缓冲。

答案 1 :(得分:0)

更新您的代码,如下所示

注册表格

[10, 11]
[13, 22]
[Finished in 0.3s]

登录表格

<?php
    session_start();
    $_SESSION['message'] = '';
    $mysqli= new mysqli('127.0.0.1','root','','accounts');

    if(isset($_POST) && array_filter($_POST)){
        if ($_POST['password'] == $_POST['confirmpassword']) {
            $username = $mysqli->real_escape_string($_POST['username']);
            $email = $mysqli->real_escape_string($_POST['email']);
            $password = md5($_POST['password']);
            $profile_path = $mysqli->real_escape_string('images/'.$_FILES['profile']['name']);
            if(!empty($username) && !empty($email) && !empty($password) && !empty($_FILES['profile']['name']){
                if (preg_match("!image!", $_FILES['profile']['type'])) {
                    if (move_uploaded_file($_FILES['profile']['tmp_name'],$profile_path)){
                        $_SESSION['username'] = $username;
                        $_SESSION['profile'] = $profile_path;
                        $sql ="INSERT INTO users(username,email,password,profile) VALUES ('$username','$email','$password','$profile_path')";
                        if($mysqli->query($sql) == true) {
                            $_SESSION['message'] =  "Registration successful! Added $username to the database!";
                            header("Location: RegisterLogin.php");
                        }
                        else { $_SESSION['message'] = "User could not be added to the database!"; }
                    } else {$_SESSION['message'] = "file failed!";}
                } else { $_SESSION['message'] = "Please only upload GIF,JPG, or PNG images!"; }
            }else{ $_SESSION['message'] = "values are missing"; }        
        } else{ $_SESSION['message'] = "two password do not match!"; }
    }
?>

欢迎使用PHP

<?php
    session_start();
    $_SESSION['message']=''; 
    $mysqli= new mysqli('127.0.0.1','root','','accounts'););

    if(isset($_POST['login'])){
        $username = $mysqli->real_escape_string($_POST['username']);
        $password = md5($_POST['password']);
        $sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
        $result = $mysqli->query($sql);
        if($result->num_rows > 0){
            $row = $result->fetch_assoc();
            $_SESSION['username'] = $username;
            $_SESSION['profile'] = 'images/'.$row['profile'];
            $_SESSION['message'] =  "Login successful!";
            header("Location: Welcome.php");
        }else{ $_SESSION['message'] = "Login Failed!";}
    }
?>