Hi guys,
I was wondering if anyone had any idea why im getting two errors in my code? i've been trying to do this in pdo and am not very good at it any help would be great thanks.(sorry for the messy code)
ERRORS:

Notice: Undefined index: username in C:\xampp\htdocs\test.php on line 22
line 22>>(':username' => $_POST['username'])
Notice: Undefined variable: delete in C:\xampp\htdocs\test.php on line 68
line 68>>(if($delete){)
<?php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: login.php");
die("Redirecting to login.php");
}
$query = "
SELECT
id,
username,
invoicenumber,
package,
purchasedate,
duedate,
invoiceamount
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$row = $stmt->fetch();
?>
<table width="938" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="938" border="0" cellpadding="3" cellspacing="1" bgcolor="#000000">
<tr>
<td align="left" bgcolor="#3576B4" width="26"><font color="#FFFFFF" size="2"><strong></strong></td>
<td align="left" bgcolor="#3576B4" width="95"><font color="#FFFFFF" size="2"><strong>Invoice:</strong></font></td>
<td align="left" bgcolor="#3576B4" width="102"><font color="#FFFFFF" size="2"><strong>Package:</strong></font></td>
<td align="left" bgcolor="#3576B4" width="271"><font color="#FFFFFF" size="2"><strong>Purchase Date:</strong></font></td>
<td align="left" bgcolor="#3576B4" width="79"><font color="#FFFFFF" size="2"><strong>Due Date:</strong></font></td>
<td align="left" bgcolor="#3576B4" width="79"><font color="#FFFFFF" size="2"><strong>Invoice Amount:</strong></font></td>
</tr>
<?php
while($rows=$stmt->fetch($result)){
?>
<tr>
<td align="center" bgcolor="#f8f8f8" width="26">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo htmlentities($rows['id']); ?>" style="float: left"></td>
<td bgcolor="#f8f8f8" width="95"><font size="2"><?php echo htmlentities($rows['invoicenumber'], ENT_QUOTES, 'UTF-8'); ?></font></td>
<td bgcolor="#f8f8f8" width="102"><font size="2"><?php echo htmlentities($rows['package'], ENT_QUOTES, 'UTF-8'); ?></font></td>
<td bgcolor="#f8f8f8" width="271"><font size="2"><?php echo htmlentities($rows['purchasedate'], ENT_QUOTES, 'UTF-8'); ?></font></td>
<td bgcolor="#f8f8f8" width="240"><font size="2"><?php echo htmlentities($rows['duedate'], ENT_QUOTES, 'UTF-8'); ?></font></td>
<td bgcolor="#f8f8f8" width="240"><font size="2"><?php echo htmlentities($rows['invoiceamount'], ENT_QUOTES, 'UTF-8'); ?></font></td>
</tr>
<?php
}
?>
<tr>
<td colspan="6" align="center" bgcolor="#f8f8f8">
<input name="delete" type="submit" id="delete" value="Delete" style="float: left"></td>
</tr><?php


if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$query = "
DELETE FROM
users
WHERE
id = :$del_id And
username = :username
";
$query_params = array(
':checkbox' => $_POST['checkbox'],
':delete'   => $_POST['delete'],
':username' => $_POST['username']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
   catch(PDOException $ex)
   {
   die("Failed to run query: " . $ex->getMessage());
  }
 }
}

?></table>
</form>
</td>
</tr>
</table>
</div>

    Is the user coming to this page by a form submission made via the POST method? Does this form have a field named "username"? If the answer to either of these questions is "no", then that explains why you get the first notice.

    The second notice should be self-explanatory: you used $delete before assigning anything to it.

      Write a Reply...