<?php
require_once 'db_connection.php'; // Ensure this sets up a valid $mysqli connection

$email = '';
// Check if form was previously submitted and validation failed (ret=T means valid POST)
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    $sql = "SELECT * FROM partners_checkout WHERE checkout_user_id = 0 LIMIT 1";
    $result = $mysqli->query($sql);

    if ($result && $result->num_rows > 0) {
        $row = $result->fetch_object();
        $email = htmlspecialchars(stripslashes($row->checkout_email));
    }
}
?>

<form method="POST" action="checkout_validate.php">
  <table width="70%" class="tablebdr" cellspacing="0" cellpadding="0">
    <tr align="center">
      <td height="22" colspan="3" class="tdhead">PayPal Details</td>
    </tr>

    <tr align="center">
      <td colspan="3">&nbsp;</td>
    </tr>

    <tr>
      <td align="right">Email</td>
      <td>&nbsp;</td>
      <td width="66%" align="left">
        <input name="txtemail" type="email" id="txtemail" value="<?= $email ?>" size="30" required>
      </td>
    </tr>

    <tr>
      <td width="32%" align="right">&nbsp;</td>
      <td width="2%" align="right">&nbsp;</td>
      <td align="left">&nbsp;</td>
    </tr>

    <tr>
      <td height="19" colspan="3">&nbsp;</td>
    </tr>

    <tr align="center">
      <td colspan="3">
        <input type="submit" name="Submit" value="Update">
      </td>
    </tr>

    <tr>
      <td height="19" colspan="3">&nbsp;</td>
    </tr>

    <tr>
      <td class="tdhead" height="22" colspan="3">&nbsp;</td>
    </tr>
  </table>
</form>
