My site is generating a HTML-tr structure with the dataset of a SQL table. Each tr would contain a dataset with each td being a SQL table value, like this:
include_once("functions.php");
SQL_Connect();
$queryBestellung = mysql_query("SELECT * FROM Bestellung ORDER BY $sortbestellung ASC");
$num = mysql_num_rows($queryBestellung);
$resultproductname = array();
$resultbestellnummer = array();
$resulturgent = array();
$benutzername = array();
$resultbestelltesProdukt = array();
$resultbestelltesProduktPakete = array();
$resultbestelltesProduktMenge = array();
if($num)
{
for ($i = 0; ($row = mysql_fetch_assoc($queryBestellung)); ++$i)
{
$resultproductname [$i] = $row["productname"];
$resultbestellnummer [$i] = $row["bestellnummer"];
$resulturgent [$i] = $row["urgent"];
$benutzername [$i] = ( $row ['firstname']." ".$row ['lastname']);
$resultbestelltesProdukt [$i] = $row["productname"];
$resultbestelltesProduktPakete [$i] = $row["packages"];
$resultbestelltesProduktMenge [$i] = $row["quantity"];
}
}
$arrlength = count($resultbestelltesProdukt);
for ($i = 0; ($i < ($arrlength)); ++$i){
echo "<tr class='".$resulturgent [$i]."'><td>".$resultbestellnummer [$i]."</td><td>".$benutzername [$i]."</td><td>".$resultbestelltesProdukt [$i]."</td><td>".$resultbestelltesProduktPakete [$i]."</td><td>".$resultbestelltesProduktMenge [$i]."</td><td>".$resulturgent [$i]."</td>
<td>
<form action='Orders.php' method='post' >
<div class='buttonDelete'><button class='submit' name='submit' type='submit' value='X' tabindex='3'></button></div>
<input name='MOVEOrderForm' type='hidden' value='' />
<input name='OrderToMOVE' type='hidden' value='".$resultbestellnummer [$i]."' />
</form>
</td>
</tr>";
}
Now I want to add a function which allows Copying one SQL Dataset (tr) to another table (check the form). My solution looks something like this, but it doesnt work:
if (isset($_POST['MOVEOrderForm']))
{
$OrderToMOVE = $_POST["OrderToMOVE"];
include_once("functions.php");
SQL_Connect();
$query = mysql_query ("INSERT INTO anKundeVerschickt (bestellnummer, name, urgent, productname, quantity, packages) VALUES (bestellnummer, name, urgent, productname, quantity, packages) FROM bestellung WHERE bestellnummer='$OrderToMOVE' ");
mysql_close();
}
Does anyone have any suggestion?
Your query needs to be an INSERT ... SELECT query: https://dev.mysql.com/doc/refman/5.5/en/insert-select.html
$query = mysql_query ("INSERT INTO anKundeVerschickt (bestellnummer, name, urgent, productname, quantity, packages) SELECT bestellnummer, name, urgent, productname, quantity, packages FROM bestellung WHERE bestellnummer='$OrderToMOVE' ");
Stop using mysql extention it has been deprecated and there is a note to that effect in the manual (it has been there for years). Use PDO or MYSQLI instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.