HOW CAN I DELETE SPECIFIC ROW FROM ARRAY TABLE :D

+1 Richmond Padraque · December 17, 2014
GUYS :D can you help me :unsure::unsure: . i cant figure out a way on deleting a row from my fetch_object array .. i was trying  to delete each row by using a delete button which I include in my while loop .. but its not deleting it :'(:'( 
HELP HELP PLSS ..:unsure:

Post a Reply

Replies

Oldest  Newest  Rating
+1 Steven the awesome · December 17, 2014
So can you give some more details please. Your code perhaps. ;)
+1 Steven the awesome · December 18, 2014
To be absolutely honest, I don't use this to often I still learning how to work with prepared statements in PHP. But what I did is cleaning up your'e whole code, and I have removed some bugs. Hope this works.



<!DOCTYPE html>
<html lang = "en">
<head>
<title>add edit delete retrieve data</title>
</head>
<body>
<form action = "#" method="POST">
<input type="text" name="name" placeholder="name of hero">
<input type="text" name="type" placeholder="type of hero">
<input type="submit" name="submit" value="submit">
</form>

<?php
require 'db/connect2.php';

if(isset($_POST['submit']))
{
$name = $_POST['name'];
$type = $_POST['type'];

if($result = $db->query("INSERT INTO hero (name, type) VALUES ('".$name."','".$type."'))
{
echo $db->affected_rows;


if($result2 = $db->query("SELECT * FROM hero"))
{


if($result2->num_rows)
{

while($row = $result2->fetch_object())
{
echo '<label style="position:absolute;margin: 0 0 0 0;width:80px;border: solid 1px black;text-align:center;">', $row->name, '</label >','<label id="membername" style="position:absolute;margin: 0 0 0 px;width:280px;border: solid 1px black;text-align:center;">', $row->type,
'</label>','<input type="button" name="delete" value="delete" style="position:absolute;margin: 0 0 0 300px;">','<input type="button" name="update" value="update" style="position:absolute;margin: 0 0 0 400px;">','<br>';


$result2->free();
}
}

}
?>
</body>
</html>

 
And btw next time when you post your'e code please ad code tags around you source code please. 
0 Richmond Padraque · December 18, 2014
<!DOCTYPE html>
<?php
require 'db/connect2.php';
?>
<html lang = "en">
<head>
<title>add edit delete retrieve data</title>
</head>

<body>

<?php 
if(isset($_POST[submit]))
//------- insert records ---------------------
$name  = $_POST['name'];
$type    = $_POST['type'];

if($result  = $db -> query("INSERT INTO hero  (name, type)
VALUES ('{$name}', '{$type}')
")) echo $db -> affected_rows;
//----------end insert records ----------------
?>

<form action = " " method = "POST">
<input type = "text" name = "name" placeholder = "name of hero">
<input type = "text" name = "type" placeholder = "type of hero">
<input type = "submit" name = "submit" value = "submit">
</form>
<?php
if($result2 = $db -> query("SELECT * FROM hero")){
if($result2  -> num_rows){
while($row = $result2 -> fetch_object( )){
echo '<label style="position:absolute;margin: 0 0 0 0;width:80px;border: solid 1px black;text-align:center;">', $row -> name, '</label >','<label  id="membername" style="position:absolute;margin: 0 0 0 px;width:280px;border: solid 1px black;text-align:center;">', $row -> type, 
'</label>','<input type="button" name="delete" value="delete" style="position:absolute;margin: 0 0 0 300px;">','<input type="button" name="update" value="update" style="position:absolute;margin: 0 0 0 400px;">','<br>';
} $result2 -> free( );
}
}


?>
</body>
</html>

 Ohh .. thankyou for responding sir:D, well anyways this is my scratch code :(:(.. its kinda messy but i hope you can help me sir:D 
0 Richmond Padraque · December 19, 2014
thankyou sir .. and sorry for not using the code tag .. :D
  • 1

PHP

106,930 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators