SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 122
Thread: deleting records with checkboxes
-
Oct 11, 2004, 18:22 #26
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
deleteArray ( [0] => )
that's exactly what appeared
-
Oct 11, 2004, 18:24 #27
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<table>
<tr>
<td>
<?php
global $delete;
global $submit;
global $eventid;
global $del;
global $record;
if (isset($_POST['action'])){
$enventid = "2004-10-20";}
else{
//$enventid = $_GET['eventid'];
$enventid = "2004-10-20";
}
echo "<html><body bgcolor=#FFFFFF>";
//echo "<form method=\"POST\" action=\"testresults.php\">";
$db = mysql_connect("localhost","root");//,"password");
//mysql_select_db("database",$db);
mysql_select_db("t1",$db);
$sql = "SELECT * from timetable where Date='$enventid'";
$result = mysql_query($sql, $db) or die ("Invalid query");
?>
<br><hr noshade>
<table cellpadding=0 cellspacing=0 width=200>
<tr><td>
<table border=1>
<tr><td>RoomID</td>
<td>Date</td>
<td>Time_Start</td>
<td>Time_Finish</td>
<td>Persons_Inc</td>
<td>Guests</td>
<td>Delete?</td>
</tr>
<?php
while ($row = mysql_fetch_array($result)){
echo "<tr><td>$row[RoomID]</td><td>";
echo "$row[Date]</td><td>";
echo "$row[Time_Start]</td><td>";
echo "$row[Time_Finish]</td><td>";
echo "$row[Persons_inc]</td><td>";
echo "$row[Guests]</td><td>";
echo "<input type=\"radio\" value=\"$row[RoomID],$row[Date],$row[Time_Start]\" name=\"delete\"></td></tr>";
}
//--------------------------------------
?> </table></td><td> </td><td>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
RoomID: <br />
<select name="book[roomid]">
<option value="1">BoardRoom
<option value="2">SmallRoom
</select><br>
Date: yyyy/mm/dd <input type="text" name="book[date]" /><br />
Start Time : <input type="text" name="book[start_time]" /><br />
Finish Time: <input type="text" name="book[finish_time]" /><br />
Persons Included: <input type="text" name="book[persons_inc]" /><br />
Guests: <input type="text" name="book[guests]" /><br />
<br />
<form method = "POST" action="delrecord.php">
<input type="hidden" name="action" value="submitted" />
<input type="submit" name="submit" value="Submit Booking" />
</form>
<form method = "POST" action="delrecord.php">
<input type="hidden" name="action2" value="submitted2" />
<input type="submit" name="submit2" value="Delete" />
</form>
<?php
if (isset($_POST['action']) == 'submitted'){
$RmID = $_POST['book']['roomid'];
if ($RmID == '2'){
$RoomID = "SmallRoom";}
else { $RoomID = "BoardRoom";}
$Date = $_POST['book']['date'];
$Time_Start = $_POST['book']['start_time'];
$Time_Finish = $_POST['book']['finish_time'];
$Persons_inc = $_POST['book']['persons_inc'];
$Guests = $_POST['book']['guests'];
$sql = "INSERT INTO timetable (RoomID,Date,Time_Start,Time_Finish,Persons_inc,Guests) VALUES('$RoomID','$Date','$Time_Start','$Time_Finish','$Persons_inc','$Guests')";
$result = mysql_query($sql, $db) or die ("Invalid query");
echo "<b>Submission Added</b><br><br>";
}
if (isset($_POST['action2']) == 'submitted'){
echo "you would like to delete";
$array = explode(",",$delete);
print_r($array);
//$sql = "DELETE FROM timetable WHERE RoomID='$array[0]' AND Date='$array[1]' AND Time_Start='$array[2]'";
$sql = "DELETE FROM timetable WHERE RoomID='$row[RoomID]' AND Date='$row[Date]' AND Time_Start='$row[Time_Start]'";
$result = mysql_query($sql, $db) or die ("Invalid query");
}
?>
</tr></table>
-
Oct 11, 2004, 18:31 #28
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok so what error are u getting now.
remove the
$array = explode(",",$delete);
print_r($array);
these 2 lines r not from anywhere."None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 18:36 #29
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
at the moment nothing happens, no error and no deletion of a record...
-
Oct 11, 2004, 18:56 #30
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is it possible u dont have a record that matches those dates?
"None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:01 #31
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the record displayed is exactly what is in the database... oh with those nah i've set my test data to be what the default is 2004-10-20 ... so yeh i can see the table of data on my page and phpmyadmin and they're the same...
i need to know how once i have selected a tickbox.... how i can get that specific row... i think i will have to use a unique number... hmmm.... even what cranial-bore suggested yesterday i couldn't get to work... it had the same problem as what i first started with... ie undefined indexes. hmmmm
-
Oct 11, 2004, 19:04 #32
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
maybe i could try the delete, but ask the user to enter in RoomID, Date, Time_Start...
not very nice... but if i can get that working... hmmm
-
Oct 11, 2004, 19:10 #33
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok noticed few things. first of all
$row[RoomID] isonly valid inside the while() { loop }
so that straight away makes it invalid query.
now what im trying to figure out is.... where r u trying to get values of date and roomid from? is there some where i can view this? maybe u have a form which has select list with date values?"None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:11 #34
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i quote u so yeh i can see the table of data on my page and phpmyadmin and they're the same...
so u r seeeing some dates and ids on ur page? which is actually not part of the form which u r submitting... iin fact its another form?"None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:15 #35
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
date roomid and time_start are all displayed in a table on the web page...
like so...
RoomID Date Time_Start Time_Finish Persons_Inc Guests Delete?
BoardRoom 2004-10-20 05:00:00 01:00:00 amir ELMO (tickbox)
but in a proper table... ummm nah you can't view it... it's for an intranet
umm not sure what you mean about the form... but on another page previous.. i have a table
October 2004
Su M T W Th F Sat
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
where all the dates are links, and the date ie 2004-10-20 is transferred in $eventid
-
Oct 11, 2004, 19:18 #36
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
the submit form is seperate from the form that shows the table that is viewed....the submit form works fine...
-
Oct 11, 2004, 19:18 #37
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
damm.... i just realised wot u have done wrong. its simple mistake.
u have 3 forms.... 1 is telliing u the values, 2. is just doing nothing and 3 also doing nothing..
form 2 and 3 are the ones u r trying to use... but on the same time.. ur form 1 is the one with the values.
lol
now let me think how to fix this lol."None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:19 #38
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
u said that $row[RoomID] is only valid in that while loop, would making this global, allow it to be passed down to the delete lines of code...
-
Oct 11, 2004, 19:20 #39
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
echo "<input type=\"radio\" value=\"$row[RoomID],$row[Date],$row[Time_Start]\"
this in the whole loop... is giving u the info ii think in ur table."None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:22 #40
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you mean that out of the 3 forms, one displays the table, one is for submit (ie the button) and the other is for delete....
echo "<input type=\"radio\" value=\"$row[RoomID],$row[Date],$row[Time_Start]\"
yeh i think that above bit is to identify a row... the tutorial used what i did.. just the primary key's i had three, the tute had 2....
-
Oct 11, 2004, 19:31 #41
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
do this..... this is your while loop in bold
<?php
while ($row = mysql_fetch_array($result)){
echo "<tr><td>$row[RoomID]</td><td>";
echo "$row[Date]</td><td>";
echo "$row[Time_Start]</td><td>";
echo "$row[Time_Finish]</td><td>";
echo "$row[Persons_inc]</td><td>";
echo "$row[Guests]</td><td>";
echo "<input type=\"radio\" value=\"$row[RoomID],$row[Date],$row[Time_Start]\" name=\"delete\"></td></tr>";
// here echo the form like this....
echo "<form method =\"POST\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<input type=\"hidden\" name=\"action\" value=\"submitted\">";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit Booking\">";
echo "<input type=\"hidden\" name=\"roomid\" value=\"".$row[RoomID]."\">";
echo "<input type=\"hidden\" name=\"date\" value=\"".$row[Date]."\">";
echo "<input type=\"hidden\" name=\"timestart\" value=\"".$row[Time_Start]."\">";
</form>
}
now that form is insdie the loop with values... u can do a query like this...
$sql = "DELETE FROM timetable WHERE RoomID='$_POST["roomid"]' AND Date='$_POST["date"]' AND Time_Start='$_POST["timestart"]'";"None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:38 #42
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
alright i'll give it a go
-
Oct 11, 2004, 19:40 #43
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
crap i have a parse error... on a html line... bugger... i'll just sort this out and i'll let you know how it went...
-
Oct 11, 2004, 19:43 #44
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
so sorry i forgot to put submit button.
ur while loop shud be like this in full.......
<?php
while ($row = mysql_fetch_array($result)){
echo "<tr><td>$row[RoomID]</td><td>";
echo "$row[Date]</td><td>";
echo "$row[Time_Start]</td><td>";
echo "$row[Time_Finish]</td><td>";
echo "$row[Persons_inc]</td><td>";
echo "$row[Guests]</td><td>";
echo "<input type=\"radio\" value=\"$row[RoomID],$row[Date],$row[Time_Start]\" name=\"delete\"></td></tr>";
// here echo the form like this....
echo "<form method =\"POST\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<input type=\"hidden\" name=\"action\" value=\"submitted\">";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit Booking\">";
echo "<input type=\"hidden\" name=\"roomid\" value=\"".$row[RoomID]."\">";
echo "<input type=\"hidden\" name=\"date\" value=\"".$row[Date]."\">";
echo "<input type=\"hidden\" name=\"timestart\" value=\"".$row[Time_Start]."\">";
echo "<input type=\"hidden\" name=\"action2\" value=\"submitted2\">";
echo "<input type=\"submit\" name=\"submit2\" value=\"Delete\">";
</form>
}
and then the query as i gave u before.... and get rid of ur second form which is to delete."None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:44 #45
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
tell me which line is the parse error. come on dont give up. its almost done. max 15 more mins.
"None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:45 #46
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
cheers mate... but the parse error wasn't your fault it was something else... still haven't fixed it, so i'll get back to ya soon as i can chuck that while loop in...
-
Oct 11, 2004, 19:47 #47
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
iexplore is weird... it said my script had a parse error, and even my backup script had one when i had not changed it from its working module... then i close iexplore opened a new one and it had no parse error... bloody thing... alright i'll try that while loop now
-
Oct 11, 2004, 19:49 #48
- Join Date
- Sep 2004
- Location
- ur monitor
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok.
"None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)
-
Oct 11, 2004, 19:50 #49
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hmm came up with a parse error at this line
<td>Persons_Inc</td>
just part of the html table....
hmmm
-
Oct 11, 2004, 19:52 #50
- Join Date
- Oct 2004
- Location
- australia
- Posts
- 424
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
did you turn the 3 forms into one...
Bookmarks