Update Delete sql-data with form field

Discuss coding issues, and scripts related to PHP and MySQL.
User avatar
JanMolendijk
Posts:282
Location:Holland Rotterdam

Update Delete sql-data with form field

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";

Admin Posts:805
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;
  }
}

JanMolendijk Posts:282
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 ?

Admin Posts:805
See the script and code from this tutorial: https://coursesweb.net/php-mysql/update- ... ql-form_s2

JanMolendijk Posts:282
You doing Great Work `thanks for the support`

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

Similar Topics