Current location: Hot Scripts Forums » Programming Languages » PHP » two questions....deleting mysql values and adding array value through forms


two questions....deleting mysql values and adding array value through forms

Reply
  #11 (permalink)  
Old 03-18-04, 09:30 AM
ciggie ciggie is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
-- Here is my view code --
<form action="removeteach.php" method="post">
<?
$link = mysql_connect("localhost", "jjamies_ciggie", "cas483") or die ("Could not connect to database");
mysql_select_db("jjamies_users", $link) or die ('Can\'t use db : ' . mysql_error());
$result = mysql_query("SELECT teachid FROM teacherid") or die ('Can\'t use db : ' . mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records in the database.<p>";
print "<table border=1 width=75%>\n";
print "<tr>\n";
print "<td colspan=2>\n";
print "<b>Techer ID</b>\n";
print "</td>\n";
print "</tr>\n";
while ($get_info = mysql_fetch_row($result)) {
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><input type=\"checkbox\" name=\"remove[]\" value=\"" . $get_info['teachid'] . "\" /></td>\n";
print "\t<td>$field</td>\n";
print "</tr>\n";
}
print "</table>\n";
?>

<input type="submit" name="submit" value="remove">
</form>

-- here is my remove code (removeteach.php) --
<?php

if (isset($HTTP_POST_VARS['remove'])) {

foreach ($HTTP_POST_VARS['remove'] as $teachid)
mysql_query("DELETE FROM teacherid WHERE teachid = '" . $teachid . "'") or die ('Can\'t delete : ' .

mysql_error());

}
else
echo "No items selected";

?>

If you'd like to see what it does now: http://www.jjamieson.com/cas483/php/viewteach.php
Reply With Quote
  #12 (permalink)  
Old 03-18-04, 09:49 AM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
so--says no db selected... what means your not connected ( or selected ) to a database
Reply With Quote
  #13 (permalink)  
Old 03-18-04, 12:05 PM
ciggie ciggie is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Infinite_Hackers
so--says no db selected... what means your not connected ( or selected ) to a database

No it connects to the db just fine.
Reply With Quote
  #14 (permalink)  
Old 03-18-04, 03:12 PM
ciggie ciggie is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I figured out my own problem. It's mysql_fetch_assoc not mysql_fetch_row. Thanks for all your help guys.
Reply With Quote
  #15 (permalink)  
Old 03-18-04, 03:25 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
*SMASHES HIS HEAD ON THE TABLE*
LOL
don't use mysql_fetch_assoc use mysql_fetch_array
*kills him self*
can't belive i didn't see that!!!!!!
Reply With Quote
  #16 (permalink)  
Old 03-18-04, 05:34 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
Quote:
Originally Posted by ciggie
I figured out my own problem. It's mysql_fetch_assoc not mysql_fetch_row. Thanks for all your help guys.
That's what i had in the original script! Why ask for help then change what you're given?? I noticed that, but I figured that if you changed it you must know what's going on.


Last edited by Keith; 03-18-04 at 05:38 PM.
Reply With Quote
  #17 (permalink)  
Old 03-18-04, 09:41 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Keith
That's what i had in the original script! Why ask for help then change what you're given?? I noticed that, but I figured that if you changed it you must know what's going on.

it seems that...you did post the right script and i don't think looked at it close enough lol (then i used the same mistak in the scripts i posted *dang*)
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Uploaded Name To Mysql CarBoffin PHP 0 02-27-04 03:32 PM
Problem with adding content to mysql from php HasansWeb PHP 3 01-10-04 05:26 PM


All times are GMT -5. The time now is 10:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.