Hey there i am new to PHP and need to delete a record from MYSQL TABLE where my username resides in html table! my code for fetching mysql table data into html table is:
while($data=mysqli_fetch_array($result)){
$count+=1;
echo "<tr>";
echo "<td>";
echo "<p>";
echo $count;
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['myusername'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['logincount'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['signindate'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['signupdate'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo "<a href='deluser.php?id=" . $data['myusername'] . "'>Del</a>"; //here i want to use this link to delete a user
echo "</p>";
echo "</td>";
echo "</tr>";
}
my deluser.php is:
<?php
//$user=$_GET['myusername'];
$isConnected=mysqli_connect('localhost','root','','mydb');
if($isConnected){
if (isset($_GET["myusername"])) {
$query = "DELETE FROM users WHERE myusername = " . $_GET["myusername"];
$result = mysqli_query($con, $query);
// Check the result and post confirm message
if(!$result){
echo 'error'.mysqli_error($isConnected);
}
else{
echo 'success';
}
}
}
?>
suppose that the connection have been set and then i want to delete a record using a wildcard ie myusername='value for html table'!
The problem is that nothing is showing to me nor an error neither success so is it me doing something wrong can somebody please help me!
$result = mysqli_query($con, $query);
mysqli_query()
function first argument must be connection link, why you use $con
variable? Your connection link to database in $isConnected
variable. Try use this:
$result = mysqli_query($isConnected, $query);
And if your myusername
value is string, you need take this value in single quotes:
$query = "DELETE FROM users WHERE myusername = '" . $_GET["myusername"] . "'";
For update information in database, you need use POST
method, GET
method is good for information required but not for update, it is not safe.
It looks like you set up your query incorrect. Should be:
$query = "DELETE FROM users WHERE myusername = '" . $_GET["myusername"] . "'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.