Jump to content

header() function question


netfrugal

Recommended Posts

I found a tutorial online from this site: [URL=http://www.phpeasystep.com/mysql/10.html]http://www.phpeasystep.com/mysql/10.html[/URL]

Now, I have attempted using the code provided, but I consistantly get an error concerning the header() function found on the bottom on the script.

What am I not understanding about header information?
I always get this error:

[B]Warning: Cannot modify header information - headers already sent by (output started at C:\apache\Apache2\htdocs\PHP\update\update.php:9) in C:\apache\Apache2\htdocs\PHP\update\update.php on line 71[/B]

Is the tutorial not correct?  Because I've seen similar tutorials that put the header() function in similar places too.

Here is the code:

<strong>Update multiple rows in mysql</strong><br>

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">


<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td>
<td align="center"><input name="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td>
<td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}
}

[B][COLOR=DarkRed]if($result1){
header("location:update.php");
}[/COLOR][/B]
mysql_close(); 
?>

This is a script to update multiple rows from one form.

It is driving me crazy!
Link to comment
https://forums.phpfreaks.com/topic/29022-header-function-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.