I'm have a php script that does the following: It selects all the data from a table. If the rows are greater than 0, the data must be updated, otherwise it makes a new row of data. Making the new of data works, only the update does not run. Here's my code:
$host = "localhost";
$user = "******";
$password = "*********";
$database = "elektrowinkel";
$link = mysqli_connect($host, $user, $password) or die("Er kan geen connectie gelegd worden met $host");
mysqli_select_db($link, $database) or die("databank $database niet beschikbaar");
$queryRijen = "SELECT * FROM stock_fysieke_winkels
WHERE Fysieke_winkel_ID = '". $_POST['winkel'] . "' and
Product_ID = '" . $_POST['product']. "'";
$rijen = mysqli_query($link, $queryRijen);
$resultaat = mysqli_num_rows($rijen);
if (mysqli_num_rows($rijen) > 0)
{
$query = "UPDATE stock_fysieke_winkels
Set Aantal = '" .$_POST['aantal']. "'
WHERE Fysieke_winkel_ID = '". $_POST['winkel'] . "',
Product_ID = '" . $_POST['product']. "'";
}
else
{
$query = "INSERT INTO stock_fysieke_winkels (Fysieke_winkel_ID, Product_ID, Aantal)
VALUES ('". $_POST['winkel'] . "', '" .
$_POST['product']. "', '" .
$_POST['aantal']. "')";
echo "Er is een nieuw product toegevoegd bij winkel ". $_POST['winkel'] . "" ;
}
mysqli_query($link, $query) or die("Er is een fout opgetreden bij het uitvoeren van de query: \"$query\"");
Thanks!
As i said in my comment that you missed Operator AND
in your query. Because multiple condition are there so you need to add AND
. do like this:-
$query = "UPDATE stock_fysieke_winkels Set Aantal = '" .$_POST['aantal']. "' WHERE Fysieke_winkel_ID = '". $_POST['winkel'] . "' AND Product_ID = '" . $_POST['product']. "'";
Note:- if any one of them is needed then you can use OR
instead of AND
.Thanks
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加