Trying to delete a data

i am trying to delete a data after using it to pre-populate a form, but it is deleting before pre-populating the form.

<?php
$submit = $_POST['Add'];

//form data
$Sname = mysql_real_escape_string(htmlentities(strip_tags($_POST['Sname'])));
$Pname = mysql_real_escape_string(htmlentities(strip_tags($_POST['Pname'])));
$Pidno = mysql_real_escape_string(htmlentities(strip_tags($_POST['Pidno'])));
$Psize = mysql_real_escape_string(htmlentities(strip_tags($_POST['Psize'])));
$Pcolour = mysql_real_escape_string(htmlentities(strip_tags($_POST['Pcolour'])));
$Pquantity = $_POST['Pquantity'];
$Weblink = mysql_real_escape_string(htmlentities(strip_tags($_POST['Weblink'])));
$Price = mysql_real_escape_string(htmlentities(strip_tags($_POST['Price'])));
$comment = mysql_real_escape_string(htmlentities(strip_tags($_POST['comment'])));
$date = date("Y-m-d");


//echo " ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price','$Uname')";
if('POST' === $_SERVER['REQUEST_METHOD']) 

{
if ($Sname&&$Pname&&$Pidno&&$Weblink&&$Price)
{
if (is_numeric($Price))
{
	$repeatheck = mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}' AND Pidno ='$Pidno' AND Sname='$Sname' AND Pname='$Pname'");
	$count = mysql_num_rows($repeatheck);
if($count!=0)
{
	die ('PRODUCT ALREADY IN BASKET YOU CAN INCREASE OR DECREASE QUANTITY, <a href="youraccount.php">CLICK TO GO BACK TO YOUR LIST</a>');
}
else
//echo'$Price';
$tprice = $Price * $Pquantity;
//echo"$tprice";
$queryreg = mysql_query("
INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price','$comment','$tprice','$date','{$_SESSION['username']}','')
")or die(mysql_error());
}
else
echo 'price field requires numbers';
}
else
echo 'please fill in all required * fields ';
}
      $deletetable = mysql_query("DELETE FROM addingprod WHERE Uname = '{$_SESSION['username']}';
?>
<form action='youraccount.php' method='Post' class='ilistbar'>
	<!--<div>
	<label for='shoppinglist' class='fixedwidth'></label>
	<textarea type='text' name='shoppinglist' id='username' cols='100' rows='15'></textarea>
	</div> -->
	<div>
	<label for='Sname' class='fixedwidth'> * Shop name</label>
	<input type='text' name='Sname' id='Sname' value='
```php
&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Sname}; ?&gt;

‘/>


* Product name
<input type=‘text’ name=‘Pname’ id=‘Pname’ value=’

&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pname}; ?&gt;

‘/>



* Product id no /ad reference
<input type=‘text’ name=‘Pidno’ id=‘Pidno’ value=’

&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pidno}; ?&gt;

‘/>
(This should be unique for each product)



Product size
<input type=‘text’ name=‘Psize’ id=‘Psize’ value=’

&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Psize}; ?&gt;

‘/>



Product colour
<input type=‘text’ name=‘Pcolour’ id=‘Pcolour’ value=’

&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pcolour}; ?&gt;

‘/>



Product quantity

(You can update quantity in excess of 10 on the shopping list below)


* Web link
<input type=‘text’ name=‘Weblink’ id=‘Weblink’ value=’

&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Weblink}; ?&gt;

‘/>



* Price GBP
<input type=‘text’ name=‘Price’ id=‘Price’ value=’

&lt;?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Price}; ?&gt;

'/>
Please valid format is (.) for decimal



Extra info

Please give different colours , sizes of the same products,discount codes, and other information that you would like us to use

<div class='buttonarea'>
		<p>
		<input type='submit' name='submit' value='Add'>
		</p>
		</div>
		</p>
</form>

In your script, you’re deleting the row from the addingprod table whenever the script is run. Is this right, or should the row only be deleted if the form submission is successful and the data is saved to the repplac table?

Also, in your form html, you’re querying addingprod for the same data multiple times, which is very inefficient. You only need to run the query once at the top of the page:


<?php
$addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());
$row = mysql_fetch_array($addprodresult);
?>
<form action='youraccount.php' method='Post' class='ilistbar'>
    // ..
    <div>
        <label for='Sname' class='fixedwidth'> * Shop name</label>
        <input type='text' name='Sname' id='Sname' value='<?php echo $row['Sname']; ?>' />
    </div>
    // ..

thanks fret burner,i have been able to sort it, and will work on the querry