Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
u1_insert [2017-10-27 12:21]
Joakim Forsgren
u1_insert [2018-11-09 13:41]
Joakim Forsgren
Line 40: Line 40:
 mysqli_set_charset($link, "utf8"); mysqli_set_charset($link, "utf8");
    
-error_reporting (E_ALL ^ E_NOTICE); 
-  
-$query="INSERT INTO `Items` ( 
-  `ItemID` , 
-  `Item` , 
-  `Date` 
-) 
-VALUES ( 
-  NULL , '" . $_POST['Item'] . "', NOW( ) 
-); 
-"; 
 /* /*
  * Lägger in data i databasen om man har tryckt på submit,  * Lägger in data i databasen om man har tryckt på submit,
  * laddar om sidan för att tömma POST cachen.  * laddar om sidan för att tömma POST cachen.
  */  */
-if ($_POST['submit']) {+if (!empty($_POST['Item'])) { 
 +  $query="INSERT INTO `Items` ( 
 +  `ItemID` , 
 +  `Item` , 
 +  `Date` 
 +  ) 
 +  VALUES ( 
 +  NULL , '" . $_POST['Item'] . "', NOW( ) 
 +  )";
   mysqli_query($link,$query);   mysqli_query($link,$query);
   header('location: ' . basename($_SERVER['SCRIPT_NAME']));   header('location: ' . basename($_SERVER['SCRIPT_NAME']));
Line 75: Line 72:
   </form>   </form>
   <h3>Mina items</h3>   <h3>Mina items</h3>
-<?+<?php
 // 3. Ställ en fråga // 3. Ställ en fråga
 $query="SELECT * FROM Items ORDER BY Date DESC"; $query="SELECT * FROM Items ORDER BY Date DESC";