Page 1 of 1

Update Delete sql-data with form field

Posted: 21 Sep 2016, 14:38
by JanMolendijk
I wanna Delete records from a database, but i want to choose what record i delete into an text-area with delete-button
(i where able to find this code)

Code: Select all

<?php
// connect to the "tests" database
$conn = new mysqli('localhost', 'root', 'pass', 'tests');

// check connection
if (mysqli_connect_errno()) {
  exit('Connect failed: '. mysqli_connect_error());
}

// DELETE sql query
$sql = "DELETE FROM `users` WHERE `name`='MarPlo'";

// perform the query and check for errors
if (!$conn->query($sql)) {
  echo 'Error: '. $conn->error;
}

$conn->close();
?>
- Also, how can I make update, the code is wrong but something like this i mean

Code: Select all

// UPDATE sql query
$sql = "UPDATE `users` SET `email`='<form action="Testing.php" method="post"><input type="text" value="'. $row['name']. '" name="name" /><input type="submit" value="Send" /></form>' WHERE `name`='MarPlo' AND `id`=2";

Delete sql-data with form text field

Posted: 21 Sep 2016, 19:01
by Admin
Hello,
With $_POST['field_name'] you can get in php the value of the input form field which has name="field_name" (when form data from web page is sent to php).
So, in php you can use something like this:

Code: Select all

if(isset($_POST['field_name'])){
  $name = $conn->real_escape_string($_POST['field_name']);
  $sql = "DELETE FROM `users` WHERE `name`='$name'";

  // perform the query and check for errors
  if(!$conn->query($sql)){
    echo 'Error: '. $conn->error;
  }
}

Update Delete sql-data with form field

Posted: 21 Sep 2016, 21:05
by JanMolendijk
Thanks for the answer but i do not understand it to well

How can i make an clickable link-adress to delete an field_name (into html or php) & how can i Update an field_name with an html or php form ?

Update Delete sql-data with form field

Posted: 22 Sep 2016, 14:49
by Admin
See the script and code from this tutorial: https://coursesweb.net/php-mysql/update- ... ql-form_s2

Update Delete sql-data with form field

Posted: 22 Sep 2016, 16:22
by JanMolendijk
You doing Great Work `thanks for the support`

& also thanks to coursesweb.net i have
this Web-Site: http://jan-molendijk.16mb.com/