Hi all!
I found this code from a website called phpeasystep, and having corrected it all I can, I was just wondering how I might 'get it to work'. Probably an easy question for php/mysql pros! :-)
Before you look, yes there isn't any security :eek: The main things that flumux me, is that there is no value for $submit and that the variable $result1 isn't being passed.
HERE'S MY MODIFIED VERSION:
<html>
<head>
<title>Kember Loudon Williams Ltd. All entries</title>
</head>
<body>
<?php
$username="xxx";
$password="xxxx";
$database="xxx";
$mysqli = mysqli_connect("localhost", $username, $password, $database);
echo ($mysqli) ? "<b>Actually working.</b> .\r\n" : "Problem.\r\n";
$sql="SELECT * FROM project_workdone";
$result=mysqli_query($mysqli,$sql);
$count=mysqli_num_rows($result);
?>
<table width="700" borders="1" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td align="center"><b>Entryref</b></td>
<td align="center"><b>Projno</b></td>
<td align="center"><b>Description</b></td>
<td align="center"><b>Invoiced</b></td>
</tr>
<?php
while($rows=mysqli_fetch_array($result)){
?>
<tr>
<td><?php $entryref[]=$rows['entryref']; ?><?php echo $rows['entryref']; ?></td>
<td><?php $entryref[]=$rows['entryref']; ?><?php echo $rows['projno']; ?></td>
<td><?php $entryref[]=$rows['entryref']; ?><?php echo $rows['description']; ?></td>
<td><input name="invoiced[]" type="text" invoiced="invoiced" value="<?php echo $rows['invoiced']; ?>"></td>
</tr>
<?php
}
?>
</table>
<input type="submit" name="submit" value="submit">
</form>
<?php
if($submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE 'project_workdone' SET invoiced='$invoiced[$i]' WHERE entryref='$entryref[$i]'";
$result1=mysqli_query($sql1);
}
}
if($result1){
header("location:klw-showall-testing.php");
}
mysqli_close($mysqli);
?>
</body>
</html>
ANY HELP APPRECIATED, I'VE SPENT TOOOO LONG ON THIS! :-(
ERROR MESSAGE:
Notice: Undefined variable: submit in C:\wamp\www\file.php on line 48
Notice: Undefined variable: result1 in C:\wamp\www\file.php on line 54
HERE IS THE ORIGINAL CODE FROM PHPEASYSTEP (FOR REFERENCE, JUST IN CASE):
<strong>Update multiple rows in mysql</strong><br>
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$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);
}
}
if($result1){
header("location:update_multiple.php");
}
mysql_close();
?>