Update Delete sql-data with form field
Discuss coding issues, and scripts related to PHP and MySQL.
-
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 ?
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
- GET_id not working in UnLink (delete file)
PHP - MySQL
First post
I searching for an hour for a solution; unlink seems not to work with GET id
<?php
$id = (int) $_GET ;
echo $_GET ;
$file = fopen( '.$_GET...
Last post
Here is an answer `o god after 2 hours shame on me for this one`
<?php
$file_pointer = $_GET .'.txt';
if (!unlink($file_pointer)) {
echo (...