Hey Guys
Wrote this script a few months ago and it seemed to work fine
Just come back to it and made a few changes but having problems updating
When i click the update button i dont get an error but the data in the database is not being updated
Any help would be gr8
Thanks
[code=php]
if (!empty($_POST[‘Update’]))
{
$query = “UPDATE `incidentlog` SET `source` = ‘”. $_POST[“source”] .”‘, `type` = ‘”. $_POST[“type”] .”‘, `logtime` = ‘”.$_POST[“logtime”].”‘, `logtext` = ‘”.$_POST[“logtext”].”‘ WHERE `logid` = ‘$logid'”;
$result = mysql_query($query);
if(!@header(“Location: incident_report.php”)){
echo(“<META HTTP-EQUIV=Refresh CONTENT=”1; URL=incident_report.php”>”);
echo(“<script>
window.top.location.href = ‘incident_report.php’;
</script>”);
echo(“You should now be redirected to the home page, click <a
href=’incident_report.php’>here</a> if you are not redirected.”);
};
}
[code=php]
$result = mysql_query($query);
if(!$result)
{
trigger_error("ERROR: Query failed: $query - ".mysql_error(), E_USER_ERROR);
}
elseif(mysql_affected_rows($result) == 0)
{
trigger_error("ERROR: no rows were updated.", E_USER_ERROR);
}
[/code]
Try some debugging:
[code=php]
[/QUOTE]
elseif(mysql_affected_rows($result) == 0)
[/code]
[code=php]elseif(mysql_affected_rows() == 0)[/code]
[code=php]<?php require_once('../../menu/ssw_menu.shtml'); ?>
<? include "mysql_connect_incident.php"; ?>
<?
//$logid = $_GET['logid'];
$logid = (false !== isset($_GET['logid']) ? $_GET['logid'] : '');
//$logid = (!empty($_GET['logid']));
$db_table = "incidentlog";
$query = "SELECT logid
, source
, type
, logtime
, logtext
from $db_table
WHERE logid
='$logid'" or die ("Could Not Run Query");
$result = mysql_query($query);
$get_info = mysql_fetch_array($result)
?>
<form action="<? echo($_SERVER['PHP_SELF']); ?>" method=POST>
<table width="129%" border="0">
<tr>
<td width="68"><strong>LogID:</strong></td>
<td colspan="9"><input type="TEXT" name="logid" size=50 value="<? echo($get_info["logid"]); ?>">
</td>
</tr>
<tr>
<td> </td>
<td colspan="9"> </td>
</tr>
<tr width="100%">
<?
$source = array("APP1",
"APP2",
"APP3",
"APP4");
# probably "nicer" to get above list of names from a database table?
echo <<<EOD
<td><strong>Source:</strong></td>
<td><select name="source" id="source">
EOD;
# add each eng as an option:
foreach($source as $value)
{
$selected = "";
if($value == $get_info["source"])
{
# mark this one as the selected entry:
$selected = " selected";
}
echo "<option$selected>$value</option>n";
}
echo <<<EOD
</select></td>
EOD;
?>
<?
$type = array("Event",
"Warning",
"Error");
# probably "nicer" to get above list of names from a database table?
echo <<<EOD
<td><strong>Type:</strong></td>
<td><select name="type" id="type">
EOD;
# add each eng as an option:
foreach($type as $value)
{
$selected = "";
if($value == $get_info["type"])
{
# mark this one as the selected entry:
$selected = " selected";
}
echo "<option$selected>$value</option>n";
}
echo <<<EOD
</select></td>
EOD;
?>
<td><strong>Time:</strong></td>
<td width="130">
<input name="logtime" type="TEXT" id="cal-field-1" value="<? echo($get_info["logtime"]); ?>" size="10" />
<button type="submit" id="cal-button-1">...</button>
<script type="text/javascript">
Calendar.setup({
inputField : "cal-field-1",
button : "cal-button-1",
align : "Tr"
});
</script>
</td>
</tr>
<tr>
<td> </td>
<td colspan="9"> </td>
</tr>
<tr>
<td><strong>Description:</strong></td>
<td colspan="9"><textarea class="textarea" name="logtext" rows=8 cols=120><? echo($get_info["logtext"]); ?></textarea></td>
</tr>
<tr>
<td> </td>
<td colspan="9"> </td>
</tr>
<tr>
<td> </td>
<td colspan="6"><input name="Update" type=SUBMIT class="button" id="Update2" value="Update">
<input type=button value="Cancel" onClick="history.go(-1)"></td>
<td width="315" colspan="2"><div align="right"> </div></td>
</tr>
</table>
<br>
</form>
<?
if (!empty($_POST['Update']))
{
$query = "UPDATE $db_table SET source
= '". $_POST["source"] ."', type
= '". $_POST["type"] ."', logtime
= '".$_POST["logtime"]."', logtext
= '".$_POST["logtext"]."' WHERE logid
= '$logid'";
$result = mysql_query($query);
if(!$result)
{
trigger_error("ERROR: Query failed: $query - ".mysql_error(), E_USER_ERROR);
}
elseif(mysql_affected_rows() == 0);
{
echo 'log id is', $logid;
trigger_error("ERROR: no rows were updated.", E_USER_ERROR);
}
if(!@header("Location: incident_report.php")){
echo("<META HTTP-EQUIV=Refresh CONTENT="1; URL=incident_report.php">");
echo("<script>
window.top.location.href = 'incident_report.php';
</script>");
echo("You should now be redirected to the home page, click <a
href='incident_report.php'>here</a> if you are not redirected.");
};
}
?>[/code]
[code=php]
$logid = (false !== isset($_GET['logid']) ? $_GET['logid'] : '');
[/code]
[code=php]
$logid = (false !== isset($_GET['logid'])) ? $_GET['logid'] : '';
[/code]
[code=php]
//near that line before it...
$result = mysql_query($query) or die("Query failed: ".mysql_error()); [/code]
[code=php]<?php require_once('../../menu/ssw_menu.shtml'); ?>
<? include "mysql_connect_incident.php"; ?>
<?
//$logid = isset($_GET['logid']);
//$logid = (false !== isset($_GET['logid']) ? $_GET['logid'] : '');
$logid = (false !== isset($_GET['logid'])) ? $_GET['logid'] : '';
//$logid = (!empty($_GET['logid']));
$db_table = "incidentlog";
$query = "SELECT logid
, source
, type
, logtime
, logtext
from $db_table
WHERE logid
= '$logid'" or die ("Could Not Run Query");
$result = mysql_query($query);
$get_info = mysql_fetch_array($result)
?>
<form action="<? echo($_SERVER['PHP_SELF']); ?>" method=POST>
<table width="129%" border="0">
<tr>
<td width="68"><strong>LogID:</strong></td>
<td colspan="9"><input type="TEXT" name="logid" size=50 value="<? echo($get_info["logid"]); ?>">
</td>
</tr>
<tr>
<td> </td>
<td colspan="9"> </td>
</tr>
<tr width="100%">
<?
$source = array("APP1",
"APP2",
"APP3",
"APP4");
# probably "nicer" to get above list of names from a database table?
echo <<<EOD
<td><strong>Source:</strong></td>
<td><select name="source" id="source">
EOD;
# add each eng as an option:
foreach($source as $value)
{
$selected = "";
if($value == $get_info["source"])
{
# mark this one as the selected entry:
$selected = " selected";
}
echo "<option$selected>$value</option>n";
}
echo <<<EOD
</select></td>
EOD;
?>
<?
$type = array("Event",
"Warning",
"Error");
# probably "nicer" to get above list of names from a database table?
echo <<<EOD
<td><strong>Type:</strong></td>
<td><select name="type" id="type">
EOD;
# add each eng as an option:
foreach($type as $value)
{
$selected = "";
if($value == $get_info["type"])
{
# mark this one as the selected entry:
$selected = " selected";
}
echo "<option$selected>$value</option>n";
}
echo <<<EOD
</select></td>
EOD;
?>
<td><strong>Time:</strong></td>
<td width="130">
<input name="logtime" type="TEXT" id="cal-field-1" value="<? echo($get_info["logtime"]); ?>" size="10" />
<button type="submit" id="cal-button-1">...</button>
<script type="text/javascript">
Calendar.setup({
inputField : "cal-field-1",
button : "cal-button-1",
align : "Tr"
});
</script>
</td>
</tr>
<tr>
<td> </td>
<td colspan="9"> </td>
</tr>
<tr>
<td><strong>Description:</strong></td>
<td colspan="9"><textarea class="textarea" name="logtext" rows=8 cols=120><? echo($get_info["logtext"]); ?></textarea></td>
</tr>
<tr>
<td> </td>
<td colspan="9"> </td>
</tr>
<tr>
<td> </td>
<td colspan="6"><input name="Update" type=SUBMIT class="button" id="Update2" value="Update">
<input type=button value="Cancel" onClick="history.go(-1)"></td>
<td width="315" colspan="2"><div align="right"> </div></td>
</tr>
</table>
<br>
</form>
<?
if (!empty($_POST['Update']))
{
$query = "UPDATE $db_table SET source
= '". $_POST["source"] ."', type
= '". $_POST["type"] ."', logtime
= '".$_POST["logtime"]."', logtext
= '".$_POST["logtext"]."' WHERE logid
= '$logid'";
//$result = mysql_query($query);
//near that line before it...
$result = mysql_query($query) or die("Query failed: ".mysql_error());
if(!$result)
{
trigger_error("ERROR: Query failed: $query - ".mysql_error(), E_USER_ERROR);
}
elseif(mysql_affected_rows() == 0);
{
echo 'log id is', $logid;
trigger_error("ERROR: no rows were updated.", E_USER_ERROR);
}
if(!@header("Location: incident_report.php")){
echo("<META HTTP-EQUIV=Refresh CONTENT="1; URL=incident_report.php">");
echo("<script>
window.top.location.href = 'incident_report.php';
</script>");
echo("You should now be redirected to the home page, click <a
href='incident_report.php'>here</a> if you are not redirected.");
};
}
?>[/code]
[code=php]
echo 'log id is', $logid;
trigger_error("ERROR: no rows were updated.", E_USER_ERROR);
}
[/code]
[code=php]
echo 'log id is', $logid;
trigger_error("ERROR: no rows were updated. SQL Statement:".$query."<br />n Error (if any):".mysql_error(), E_USER_ERROR);
}[/code]
[code=php]
$db_table = "incidentlog";
$query = "SELECT logid
, source
, type
, logtime
, logtext
from $db_table
WHERE logid
= '$logid'" or die ("Could Not Run Query");
$result = mysql_query($query);
$get_info = mysql_fetch_array($result)
[/code]
source
type
logtime
logtext
logid
logoid
0.1.9 — BETA 5.12