尝试在重新填充后删除数据(trying to delete a data after repopulating)

编程入门 行业动态 更新时间:2024-10-23 19:21:39
尝试在重新填充后删除数据(trying to delete a data after repopulating)

我试图在使用它来预先填充表单后删除数据,但在预先填充表单之前它正在删除。 虽然它重新填充,但当我尝试通过插入if($ queryreg!== false)使用它来删除数据时{$ deletetable = mysql_query(“DELETE FROM addingprod WHERE Uname ='{$ _SESSION ['username']}' “); 它根本不起作用

<?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 '; } if($queryreg !== false){ $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 $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Sname}; ?>'/> </div> <div> <label for='Pname' class='fixedwidth'> * Product name</label> <input type='text' name='Pname' id='Pname' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pname}; ?>'/> </div> <div> <label for='Pidno' class='fixedwidth'> * Product id no /ad reference</label> <input type='text' name='Pidno' id='Pidno' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pidno}; ?>'/> (This should be unique for each product) </div> <div> <label for='Psize' class='fixedwidth'>Product size</label> <input type='text' name='Psize' id='Psize' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Psize}; ?>'/> </div> <div> <label for='Pcolour' class='fixedwidth'>Product colour</label> <input type='text' name='Pcolour' id='Pcolour' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pcolour}; ?>'/> </div> <div> <label for='Pquantity' class='fixedwidth'>Product quantity</label> <select name="Pquantity" id="Pquantity"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> (You can update quantity in excess of 10 on the shopping list below) </div> <div> <label for='Weblink' class='fixedwidth'> * Web link</label> <input type='text' name='Weblink' id='Weblink' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Weblink}; ?>'/> </div> <div> <label for='Price' class='fixedwidth'> * Price GBP</label> <input type='text' name='Price' id='Price' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Price}; ?>'/> Please valid format is (.) for decimal </div> <div> <label for='comment' class='fixedwidth'> Extra info</label> <input type='text' name='comment' id='comment'/> Please give different colours , sizes of the same products,discount codes, and other information that you would like us to use </div> <div> <div class='buttonarea'> <p> <input type='submit' name='submit' value='Add'> </p> </div> </p> </form>

i am trying to delete a data after using it to pre-populate a form, but it is deleting before pre-populating the form. though it repopulates well , but when i try deleting the data after using it by inserting if($queryreg !== false){ $deletetable = mysql_query("DELETE FROM addingprod WHERE Uname = '{$_SESSION['username']}'"); } ?> it simply does not work

<?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 '; } if($queryreg !== false){ $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 $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Sname}; ?>'/> </div> <div> <label for='Pname' class='fixedwidth'> * Product name</label> <input type='text' name='Pname' id='Pname' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pname}; ?>'/> </div> <div> <label for='Pidno' class='fixedwidth'> * Product id no /ad reference</label> <input type='text' name='Pidno' id='Pidno' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pidno}; ?>'/> (This should be unique for each product) </div> <div> <label for='Psize' class='fixedwidth'>Product size</label> <input type='text' name='Psize' id='Psize' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Psize}; ?>'/> </div> <div> <label for='Pcolour' class='fixedwidth'>Product colour</label> <input type='text' name='Pcolour' id='Pcolour' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Pcolour}; ?>'/> </div> <div> <label for='Pquantity' class='fixedwidth'>Product quantity</label> <select name="Pquantity" id="Pquantity"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> (You can update quantity in excess of 10 on the shopping list below) </div> <div> <label for='Weblink' class='fixedwidth'> * Web link</label> <input type='text' name='Weblink' id='Weblink' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Weblink}; ?>'/> </div> <div> <label for='Price' class='fixedwidth'> * Price GBP</label> <input type='text' name='Price' id='Price' value='<?php $addprodresult = mysql_query("SELECT * FROM addingprod WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());$row = mysql_fetch_array($addprodresult); echo $row{Price}; ?>'/> Please valid format is (.) for decimal </div> <div> <label for='comment' class='fixedwidth'> Extra info</label> <input type='text' name='comment' id='comment'/> Please give different colours , sizes of the same products,discount codes, and other information that you would like us to use </div> <div> <div class='buttonarea'> <p> <input type='submit' name='submit' value='Add'> </p> </div> </p> </form>

最满意答案

我可以在插入另一个表后立即使用删除查询删除数据

$queryreg = mysql_query(" INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price','$comment','$tprice','$date','{$_SESSION['username']}','') ")or die(mysql_error()); $deletetable = mysql_query("DELETE FROM addingprod WHERE Uname = '{$_SESSION['username']}'"); }

而不是后来的代码

i have been able to delete the data by immediately using the delete query after inserting in the other table

$queryreg = mysql_query(" INSERT INTO repplac VALUES ('','$Sname','$Pname','$Pidno','$Psize','$Pcolour','$Pquantity','$Weblink','$Price','$comment','$tprice','$date','{$_SESSION['username']}','') ")or die(mysql_error()); $deletetable = mysql_query("DELETE FROM addingprod WHERE Uname = '{$_SESSION['username']}'"); }

instead of later in the code

更多推荐

本文发布于:2023-04-27 16:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   delete   repopulating   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!