2021年1月5日星期二

PHP Query Not Extracting id from database table

I have two tables in one database where one table is used for the signup system that I have created called "users" (works fine) and another table that stores information inputed by the user once they have logged into the website called "info". I want to query into the "users" table and extract the id number which is auto generated by phpMyAdmin and insert that into the "info" table. The php code I have attached below is also used to take information from a form in the website and also store it into the "info" table. Any help would be appreciated, as I am very new to php and sql. Thank you in advance!

        <?php    $name = $_SESSION['username'];  $query=mysql_query("select * from users where username='$name'");  $row=mysql_fetch_array($query);  $id=$row["id"];      if(isset($_POST['submit'])) {          $cashflow = $_POST['cashflow'];        $amount = $_POST['amount'];        $description = $_POST['description'];          try {              $SQLInsert = "INSERT INTO info (cashflow, amount, description, user_id)                     VALUES (:cashflow, :amount, :description, :id)";          $statement = $conn->prepare($SQLInsert);        $statement->execute(array(':cashflow' => $cashflow, ':amount' => $amount, ':description' => $description, ':id' => $id));          if($statement->rowCount() == 1) {                header('location: dashboard.php');        }      }      catch (PDOException $e) {        echo "Error: " . $e->getMessage();      }    }      ?>  
https://stackoverflow.com/questions/65588729/php-query-not-extracting-id-from-database-table January 06, 2021 at 08:56AM

没有评论:

发表评论