Forum Moderators: coopster
table as following;
TCid UserName Topic Content
1 q1 aa aa
2 q2 aa aa
3 q3 aa aa
4 q1 aa aa
5 q2 aa aa
And i code as following steps;
1) ask user input user name
2) Display out all the data which the users got. (it is in delete.php file.)
in here, i will use the check box, to let the user choices which data they will delete.
note: i will try to make the Cid relate with the input name, so later on i can delete
the data base on Cid.
3) i will delete the data base on the user choice(it is in deleteR.php file).
but at the movement, i just want to test where i can get the value of the TCid or not
(because i will delete some datas base on the TCid which the user choiced).
The problem i go now, it is from the step 3, i could not get the TCid's value out,
that's mean, i could not delete some data base on the user choiced.
input user name (step 1)
<html>
<body><form action='delete.php' method="POST">
Please eneter your userName:
<input type="text" name="userName" value=0>
<br>
<input type="submit" value="submit">
<input type="reset" value="reset">
</form>
</body>
</html>
delete.php (step 2)
<html>
<body><form action='deleteR.php' method="POST">
<?
$con = mysql_connect("localhost", "#*$!xx","#*$!xx");
if (! $con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("#*$!x", $con);
$result = mysql_query("select * from Customer2 where UserName='$_POST[userName]'");
$CArray = array();
$i=0;
while($row = mysql_fetch_array($result)){
$CArray['$i']=$row['TCid'];
?>
<input type="checkbox" name=" <? $CArray['$i']?> " >
<?
echo $row['Topic'];
$i++;
?>
<br>
<?
}
?>
<input type="submit" value="submit">
<input type="reset" value="reset">
</form>
</body>
</html>
deleteR.php (step 3)
<?$i=0;
while(isset($_POST['$CArray[$i]'])){
echo "The customer will delete their data from the TCid= ";
echo $CArray[$i];
echo "<br>";
$i++;
}
?>
<form>
<?
while($row = mysql_fetch_array($result))
{
?>
<input type="checkbox" name="id_delete[]" value="<? echo $row['TCid'];?>">
<?
}
?>
</form>
This way all your checked ids will be at the $id_delete array.
On post, all you have to do is make a loop in all array values and echo the ids easily
after i change to same as above, that's not problem for that.
but after change for the third step as following. I could not received value and print out.
<?
if(isset($_POST['$id_delete'])){
$numId=count($_POST['$id_delete']);
echo $numId; // there is not value in the $numId
while($numId>0){
echo "The TCid is ";
echo $id_delete[$numId];
$numId--;
echo "<br>";
}
}
?>
in the deleteR.php
$arrdelete = $_REQUEST['id_delete'];
if(is_array($arrdelete)){
$arrdelete = $_REQUEST['id_delete'];
$numId=count($arrdelete);
echo $numId; // i can get this value
echo "<br>";
echo $arrdelete['$num']; // but i could not get this value
$arrdelete = $_POST['id_delete'];// here you pass an array of ids
if(is_array($arrdelete)){//if it's an array, then move further
//$arrdelete = $_REQUEST['id_delete']; delete this line - it's defined above
$numId=count($arrdelete);//here you count how many ids there are for deletion
echo $numId; // now you print it out to the browser
echo "<br>";
echo $arrdelete['num']; //Here you are declaring a new field in array $arrdelete, which is of course empty
So I really don't know what you want to accomplish by using $arrdelete['num']? when the number of rows you have in $numId and the ids you have in $arrdelete[0], $arrdelete[1], etc...
Michal
In my mind a better solution consists in adding two columns:
published char(1) NOT NULL default 'y'
and a timestamp
To display the user content on your site your original query should include:
whatever from whatever WHERE user_id=’$user_id’ AND published=’y’ ”;
Use the check box system (for the user)
Default=Published
Check=unpublished (which triggers the timestamp)
If unpublished is checked then the user content does not show
By doing so you have a better DB protection
Then after a while you could query for example for:
Timestamp plus a month and delete them all
It will be your delete action and not a user action.
>and this way you see is any values are in your array...
>so you could check if the error is in the submit form or after
yes, it can print out the value of Tid.
i known the reason now, because i use the wrong index for array.
the $numId is used to find out how many Tcid in the array. And in that case, it just has one Tid in the array, so the value of the numId is 1.
Basing on the above case, i need to print out the Tid which the array hold shold like that
$index=$numId-1;
echo $arrdelete[$index];
before i wrote like that
//$numId=1, and the array just got one element at the movement, so the index should be 0.
echo $arrdelete[$numId]
Thanks a lot
Hi Michal;
i am very sorry that i make mistake with the typing. it should be $arrdelete[$numId].
and also i make mistake with the index of the array, because the $numId just represent the numId in the arry, and at that time, it just got one element in the array,
so if do like
echo $arrdelete[1] // it does not work.
it should like this
echo $arrdelete[0] //so i can print out the value.
I am appreciate your helping, sorry to bother so much.