Jump to content

Problem with mysql DB and Arrays...


eXtaZa

Recommended Posts

Hello,
so... I have this code(and I have a connection to the DB before, its just a example... ):

[code]
<html>
<body>
<form action="<?php Print $PHP_SELF ?>" method="POST">
<input type="submit" name="asd" value="Delete!"><BR>
<?php
$Result = mysql_query("SELECT * FROM GuestBook ORDER BY Date DESC");
while($a_row = mysql_fetch_row($Result)){
    echo "<input type='checkbox' name='DeleteMe[]' value='$a_row'><BR>";
    echo "</form>";
}

if($_POST['asd']){
$a=$_POST['DeleteMe'];
if(is_array($a)){
echo "yes";
foreach($a as $value)
echo $value;
}
else
echo "no";
}
?>
</body>
</html>
[/code]

I dont here that it will print me each time CheckBox, and to the CheckBox will be the value of the row that he get out of the DataBase.
Then I dont that it check if what I'm sending is a array, If it is, he need to print me "yes", and then he need to print me every var that in the array.
now, the problem is that just if im mark the first Checkbox, prints me:
"yesArray"
But why? Its true that it's array, but why he doesnt print every var in the array?
And if I'm marking other CheckBox, except of the first CheckBox, it's print s me "no". But why? Its doesn't a array?
Why just if I'm marking the firs CheckBox It's prints that its a array, And why he doesn't prints me all the vars that exist in the array?

Thanks!
Link to comment
Share on other sites

1 ) you output "</form>" after every chekbox so only the first one is in the form.

2 ) if you only echo a checkbox with no other details, how do you which record you are selecting for deletion?

3 ) the value you assign to the checkbox should just be the id of the record to be deleted, not an array of the fields in the record.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.