PHP problem
#1

This code should show all people who donated to our server. But if we want to delete a record, it doesn't. So something must be wrong with the checkbox, but I don't know what.

I hope you guys can help me outta here.

Код:
<?php
$host="*Noneofyourbusiness*"; // Host name*
$username="*Noneofyourbusiness*"; // Mysql username*
$password="*Noneofyourbusiness*"; // Mysql password*
$db_name="*Noneofyourbusiness*"; // Database name*
$tbl_name="*Noneofyourbusiness*"; // Table name



// Connect to server and select databse.
mysql_connect("$host", "$username", "$password") or die ("Cannot connect");
mysql_select_db("$db_name")or die ("Cannot connect");




$sql="SELECT * FROM $tbl_name";
$result = mysql_query($sql);




$count=mysql_num_rows($result);




?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Username</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Amount of money</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Link of screen</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['Id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Username']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Amount']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Link']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this*
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}




// if successful redirect to delete_multiple.php*
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=donatedp.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
Reply
#2

Try looking into your mysql logs what's happening over there, any erorrs, look at the sql statements..

btw
PHP код:
$tbl_name="*Noneofyourbusiness*"// Table name 
Well, PHP help is non of sa-mp community business so why don't you post at a PHP/programming forum?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)