PHP & MySQL database updat

guzmanistan

Weaksauce
Joined
Jun 3, 2005
Messages
92
I don't really get arrays.
I've got this page that reads from one table in my database. I want to be able to click a checkbox and then send the data in a row to another database and delete that row. I don't really understand arrays and I think that's the key for this thing.
The page is http://yoursouthbridge.com/pendingevents.

Heres the necessary code:
Code:
<form action='<?php echo($_SERVER['PHP_SELF']) ?>' method='post'>
<?php
	$result = mysql_query("SELECT * FROM pending",$db);
	if ($result) {
		$row_num = 1;
		while ($row = mysql_fetch_array($result)) {			
			$numrows = mysql_num_rows($result);
			echo '<tr><td>'.$row['date'].'</td>';
			echo '<td>'.$row['event'].'</td>';
			echo '<td>'.$row['location'].'</td>';
			echo '<td>'.$row['time'].'</td>';
			echo '<td>'.$row['details'].'</td>';
			echo '<td>'.$row['name'].'</td>';
			echo '<td>'.$row['site'].'</td>';
			echo '<td>'.$row['email'].'</td>';
			echo '<td>'.$row['phone'].'</td>';
			echo '<td><input type="checkbox" name="cb'.$row_num.'"></td></tr>';
			$row_num++;
			}
		}
?>
<tr><td colspan="10"><?php echo $row_num ?><input type='Submit' name='submit' />
</form>
</table>
<?php
	if (isset($_POST['submit'])) {
		$row_count=1;
		while ($row_count < $row_num) {
			$cbnum= 'cb'.$row_count;
			echo $cbnum;
			if (isset($_POST['$cbnum'])) {
			mysql_query("INSERT INTO eventt VALUE $row", $db);
			}
			$row_count++;
			}
			}

?>

Any help appreciated.
Thanks again you guys are always helpful.
 
You can try this ...

PHP:
<form action='<?php echo($_SERVER['PHP_SELF']) ?>' method='post'>
<?php
	$result = mysql_query("SELECT * FROM pending",$db);
	if ($result) {
		$row_num = 1;
		while ($row = mysql_fetch_array($result)) {			
			$numrows = mysql_num_rows($result);
			echo '<tr><td>'.$row['date'].'</td>';
			echo '<td>'.$row['event'].'</td>';
			echo '<td>'.$row['location'].'</td>';
			echo '<td>'.$row['time'].'</td>';
			echo '<td>'.$row['details'].'</td>';
			echo '<td>'.$row['name'].'</td>';
			echo '<td>'.$row['site'].'</td>';
			echo '<td>'.$row['email'].'</td>';
			echo '<td>'.$row['phone'].'</td>';
			echo '<td><input type="checkbox" name="'.$row_num.'" value="' . $row_num . '"></td></tr>';
			$row_num++;
			}
			
			echo '<input type="hidden" name="row_numbers" value="' . $row_num . '" />';
		}
		
?>
<tr><td colspan="10"><?php echo $row_num ?><input type='Submit' name='submit' />
</form>
</table>
<?php //form action
if (isset($_POST['submit'])) {

    for($i=1; $i<=$_POST['row_numbers']; $i++){
    
        if(isset($_POST[$i]) ){
        
            mysql_query("INSERT INTO eventt VALUE $i", $db);
        
        }
    
    }

}
?>
 
Didn't work. I probably am getting this wrong, but does your code send the database the row number? What I wanted to have the code do is take the information that was presented in the table, and send it to the other table. So like if you look at the page, if you clicked checkbox "cb1," the information from that row would be sent to the table in that order.

I guess what I REALLY wanna know is a couple of things:
a) $result, since there are 3 rows shown on the page, does that mean that the array has 3 rows and 9 columns?
b) can I read from $result in a way like $result[2,6] to get whatever information is in the 2nd row, 6th column?

Thanks, especially mod man
 
Back
Top