我怎样才能使我的个人资料页面在PHP中工作?

时间:2019-01-27 13:16:55

标签: php sql

因此,我对SQL和PHP相当陌生。已经创建了一个登录系统,现在尝试在我的个人资料部分中创建一个更改电子邮件框。

我尝试使用PDO以外的其他方法,但会不断出错

<?php

session_start();

require 'database.php';


if( isset($_SESSION['user_id']) ){

    $records = $conn->prepare('SELECT id,email,password,curvouch,fname FROM users WHERE id = :id');
    $records->bindParam(':id', $_SESSION['user_id']);
    $records->execute();
    $results = $records->fetch(PDO::FETCH_ASSOC);

    $user = NULL;

    if( count($results) > 0){
        $user = $results;
    }


}
?>
<?php

FORM CODE:


  <div class="form-group" action="profile.php" method="POST">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" name="email">
    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>

数据库代码:


<?php
$server = 'localhost';
$username = 'HIDDEN';
$password = 'HIDDEN';
$database = 'HIDDEN';

try{
    $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e){
    die( "Connection failed: " . $e->getMessage());
}

我收到此错误

Fatal error: Uncaught Error: Call to a member function execute() on null in /

0 个答案:

没有答案