<?php
$link = new mysqli('localhost','root','','pawel_barszcz');
$query = 'select * from pawel_barszcz';
$result = $link->query($query);
$row = $result->fetch_assoc();
if($result->num_rows==1){
$variable = 'disabled';
$variable2 = $row["fruit"];
$variable3 = $row["color"];
}else{
$variable2 = null;
$variable3 = null;
}
?>
<form method="post" action="">
Fruit: <input type="text" value="<?= $variable2 ?>" name="fruit" />
Color: <input type="text" value="<?= $variable3 ?>" name="color"/>
<input type="submit" <?= (!isset($variable) ? null : $variable );?> value="add record"/>
</form>
<?php
if(empty($_POST['fruit'])||empty($_POST['color'])){
null;// Nie możesz zostawić pustych pól
}else{
$query2 = "INSERT INTO `pawel_barszcz` values(null,\"{$_POST['fruit']}\",\"{$_POST['color']}\")";
var_dump($link->query($query2));
header('Refresh: 0');
}
?>
<form method="post" action="">
<input type="submit" name="delete_record" value="delete record"/>
</form>
<?php
if(isset($_POST['delete_record'])){
$link->query("delete from `pawel_barszcz`");
header('Refresh: 0');
}
?>
Nie wiem za bardzo jak ustawić w bazie danych, żeby blokował dodawanie rekordów jak już jeden istnieje.