Undefined variable: result1 in D:\wamp\www\update_multiple.php on line 70

Getting error on line no 70

[php]<?php

mysql_connect (“localhost”,“root”,"") or die (“could not connect to server”);
mysql_select_db(“cpe”) or die (“database error”);

$sql = “select * from test_mysql”;
$result = mysql_query($sql);

$count = mysql_num_rows ($result);
?>

<?php while ($rows = mysql_fetch_array($result)) { ?> <?php } ?>
ID Name Job No Time1 Time2
<? $id [] = $rows['id'];?>
<?php if (isset($_post['Submit'])){ for ($i=0;$i<$count;$i++){ $sql1 = "update test_mysql set name='$name[$i]', job='$job[$i]', time1='$time1[$i]', time2='$time2[$i]' where id='$id[$i]'"; $result1 = mysql_query ($sql1); } } if ($result1){ header('location:update_multiple.php'); } mysql_close(); ?>[/php]

Simply put, where do you see $result1 defined?

Just pust [php]$result1=null;[/php] before the if statement.

The reason why you get this notice is that when the execution does not go inside the if statement or for loop the variable is not initialized.

Sponsor our Newsletter | Privacy Policy | Terms of Service