Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created December 7, 2015 18:57
Show Gist options
  • Select an option

  • Save VictorFursa/77ac45102ed20bcd32a6 to your computer and use it in GitHub Desktop.

Select an option

Save VictorFursa/77ac45102ed20bcd32a6 to your computer and use it in GitHub Desktop.
<?php
include_once("connectDatabases.php");
?>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>Добовление товаров</title>
</head>
<body>
<h1 align="center">Работа с Mysql <br> (")(o_O)(")</h1>
<hr>
<form method="POST" action="Appliances.php">
<select name="appliances">
<?php
$result = mysql_query("SELECT * FROM appliances");
while ($res = mysql_fetch_array($result)){
echo "<option "." value='".$res['id']."'>".$res['categoria']."</option>";
}?>
</select>
<em>Добавить товар в категорию:<input type="text" name="product"> <br><br>
<input type="submit" value="Просмотреть" name="submit">
<input type="submit" value="Добавить" name="add">
</form>
<br>
<?php
if (isset ($_POST['submit'])) {
if (isset($_POST['appliances'])) {
$query = mysql_query("SELECT * FROM appliances JOIN product ON product.appliances_id = appliances.id");
while ($row = mysql_fetch_array($query)) {
if ($row['appliances_id'] == $_POST['appliances']) {
echo $row['product_name']."<br>";
}
}
}
}
if(isset($_POST['add'])) {
if (isset($_POST['product'])) {
$product = $_POST['product'];
if (isset($_POST['appliances'])) {
$id = $_POST['appliances'];
mysql_query("INSERT INTO product(appliances_id,product_name) VALUES('$id','$product') ");
echo " в категорию успешнно добавлен товар: <b>$product";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment