Need help with multiple update into Mysql

I have this code I have put together. It retrieves records and shows them in the table just fine. I need to be able to change the info in the table and update the DB. I found this code for updating multiple rows in a tutorial. I cannot get it to work. Here is the code in its entirety:

[php]

Edit Template

CQ Simple Phone Provisioning System -- Template Edit


Template to edit:
<?php require('/var/www/html/cqadmin/utils/connect.php'); $tempname = $_POST['tname']; print ("Editing Template: $tempname");

$link = mysql_connect(“localhost”, “root”, “XXXX”) or die (‘Error connecting to mysql’ . mysql_error());
mysql_select_db(“cqadmin”);

$sql2 = “SELECT id,templatename,keyname,keyid,keytype,keyvalue,keylabel from cqadmin.keys where templatename = ‘$tempname’;”;
$result2 = mysql_query($sql2) or die(mysql_error());
echo "











";

while($row = mysql_fetch_assoc($result2))
{
$sql = “SELECT id , keyname FROM keytypes;”;
$result = mysql_query($sql) or die(mysql_error());
echo “

“;
echo "”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo””;

}
echo “

Keys Type Templatename Key ID Key type id Key value Key label Id
<input type=‘text’ name=‘keyname[]’ value=’” . $row[‘keyname’] . "’ readonly> “;
while($rowA = mysql_fetch_assoc($result)) {
echo ‘’ . $rowA[‘keyname’] . ‘’;
}
echo “
<input type=‘text’ name=‘templatename[]’ value=’” . $row[‘templatename’] . “’><input type=‘text’ name=‘keyid[]’ value=’” . $row[‘keyid’] . “’><input type=‘text’ name=‘keytype[]’ value=’” . $row[‘keytype’] . “’><input type=‘text’ name=‘keyvalue[]’ value=’” . $row[‘keyvalue’] . “’><input type=‘text’ name=‘keylabel[]’ value=’” . $row[‘keylabel’] . “’><input type=‘text’ name=‘id[]’ value=’” . $row[‘id’] . “’>
”;
// Count table rows
$count=mysql_num_rows($result2);
echo $count;

// Check if button name “Submit” is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql3=“UPDATE keys SET templatename=’$templatename[$i]’, keyname=’$keyname[$i]’, keyid=’$keyid[$i],‘keytype=’$keytype[$i]’,keyvalue=’$keyvalue[$i]’,keylabel=’$keylabel[$i]’ WHERE id=’$id[$i]’”;
$result3=mysql_query($sql3);
}
}
if($result1){
header(“location:droptest.php”);
}
mysql_close();
?>
[/php]

The last bit for the Submit button is the code I got from the tutorial. When I hit the submit I get an error saying there is an unexpected > in line 57. I can’t see the difference in that line and the ones above it.

I really appreciate any ideas that you guys can offer. I know the code is messy. I am just a hack here so far.

Thanks again

You are using obsolete dangerous code that has been completely removed from Php. You need to use PDO with prepared statements. You need to trash that code.

https://phpdelusions.net/pdo

Thanks Kevin I will work on migrating to PDO

Sponsor our Newsletter | Privacy Policy | Terms of Service