Copy link to clipboard
Copied
Hi Chaps,
I'm having some trouble with a PHP Form page and an Update Script page.
I've tested this on my Apache server and it works fine, but fails on my 'Live' IIS server:
Form Code:
<input type='text' name='jobpriority[]' value="<?php echo $row_rsWorkload_All['jobpriority'];?>"/>
<?php echo $row['jobcount']; ?>
<?php echo $row_rsWorkload_All['jobpriority'];?>
<?php
$table_name = $row_rsWorkload_All['fromtable'];
$item_id = $row_rsWorkload_All['jobid'];
?>
<input type="hidden" name="setpriority[]" value="<?php echo $table_name; ?>:<?php echo $item_id; ?>" />
The 'hidden' input did look like this:
<input type="hidden" name="setpriority[]" value="<?php echo $table_name; ?>:<?php echo $item_id; ?>:<?php $_POST ['jobpriority']; ?>" />
:<?php $_POST ['jobpriority']
| PHP Notice: Undefined offset: 22 in C:\Inetpub\XxxxxXxxxx\NewFiles\Xxxxx\Xxxxx\scripts\script.php on line 64 |
$allowed_tables = Array('tbl_table1','tbl_table2','tbl_table3'); // to prevent SQL injection
$i = 1;
foreach($_POST['setpriority'] as $var) {
$arr = explode(':', $var);
if(in_array($arr[0], $allowed_tables)) {
$table = $arr[0];
$rowid = $arr[1];
$priority = $_POST['jobpriority'][$i];
$i++;
if(is_numeric($rowid)) {
// run your SQL query here to update $table where row matches $rowid
$query = sprintf("
UPDATE $table
SET jobpriority='$priority'
WHERE jobid=$rowid");
$result = mysql_query($query, $conndb2) or die(mysql_error());
$mess = $ref = $_SERVER['HTTP_REFERER']; header( 'refresh: 0; url='.$ref);
}
else {
$mess = "<p>There was a problem</p>";
}
}
}It would help if you indicated what was on line 64, rather than expecting others to look for a needle in a haystack.
However, I suspect the problem is on this line:
$priority = $_POST['jobpriority'][$i];
You initialize $i as 1, but PHP arrays begin at 0. There are probably 22 items in the $_POST['jobpriority'] array, but the 22nd item is not offset 22, but offset 21.
By the way, the code in your original hidden field was meaningless. To insert $_POST['jobpriority'] into the value attribute, you need
...Copy link to clipboard
Copied
It would help if you indicated what was on line 64, rather than expecting others to look for a needle in a haystack.
However, I suspect the problem is on this line:
$priority = $_POST['jobpriority'][$i];
You initialize $i as 1, but PHP arrays begin at 0. There are probably 22 items in the $_POST['jobpriority'] array, but the 22nd item is not offset 22, but offset 21.
By the way, the code in your original hidden field was meaningless. To insert $_POST['jobpriority'] into the value attribute, you need to use echo. It should be:
<?php echo $_POST['jobpriority']; ?>
Copy link to clipboard
Copied
Hi David, yes you are indeed correct, should have indicated line 64 earlier. It seems
like you are correct in your advice. I will check the remaining files and re-post if required.
Thanks for your help, and I'll remember to point out the necessary info from the outset next time.
Cheers
Find more inspiration, events, and resources on the new Adobe Community
Explore Now