/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Update Problem

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]

to post a comment
PHP

18 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 27.2006 — Try some debugging:
[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]
Copy linkTweet thisAlerts:
@bazjonesauthorMar 27.2006 — Was getting an error so changed this

Try some debugging:
[code=php]
elseif(mysql_affected_rows($result) == 0)
[/code]
[/QUOTE]


to

[code=php]elseif(mysql_affected_rows() == 0)[/code]

and now i get this error

Fatal error: ERROR: no rows were updated. in C:/blah/blah/blah
Copy linkTweet thisAlerts:
@NogDogMar 27.2006 — Sounds like your where condition is not matching any rows. You might want to echo $logid as part of the second error message to see if it's really set to what you expected it to be.
Copy linkTweet thisAlerts:
@NogDogMar 27.2006 — Also, if logid is a numeric field, you might need to remove the quotes from around '$logid' so that it's treated as a number and not as a string. (I'm not sure how picky MySQL is about that.)
Copy linkTweet thisAlerts:
@bazjonesauthorMar 27.2006 — Ok so getting somewhere now

When i take out the '' from around $logid i get this error

Fatal error: ERROR: Query failed:

When i try and echo $logid nothing is displayed for $logid

If its any use i can post all of my code?
Copy linkTweet thisAlerts:
@bazjonesauthorMar 27.2006 — [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>&nbsp;</td>
<td colspan="9">&nbsp;</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>&nbsp;</td>
<td colspan="9">&nbsp;</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>&nbsp;</td>
<td colspan="9">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</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]
Copy linkTweet thisAlerts:
@chazzyMar 27.2006 — your parenthesis are off on this line

[code=php]
$logid = (false !== isset($_GET['logid']) ? $_GET['logid'] : '');
[/code]


should just be
[code=php]
$logid = (false !== isset($_GET['logid'])) ? $_GET['logid'] : '';
[/code]


at least, that's how it makes sense to me.
Copy linkTweet thisAlerts:
@bazjonesauthorMar 27.2006 — lol still getting the same error

log id is

Fatal error: ERROR: no rows were updated. in c:documents and settingsbarry jonesmy documentsuni workcom326 projectwebsitequality_managementincident_logedit.php on line 158
Copy linkTweet thisAlerts:
@chazzyMar 28.2006 — you never implemented the error checking!

[code=php]
//near that line before it...
$result = mysql_query($query) or die("Query failed: ".mysql_error()); [/code]
Copy linkTweet thisAlerts:
@bazjonesauthorMar 28.2006 — Sorry bout this guys

Ive got implemnted the error checing and im still getting the same error

Fatal error: ERROR: no rows were updated. in c:documents and settingsbarry jonesmy documentsuni workcom326 projectwebsitequality_managementincident_logedit.php on line 158
Copy linkTweet thisAlerts:
@chazzyMar 28.2006 — show your code, doesn't look like you did.

I wouldn't rely on user_errors, don't show enough detail.
Copy linkTweet thisAlerts:
@bazjonesauthorMar 28.2006 — [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>&nbsp;</td>
<td colspan="9">&nbsp;</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>&nbsp;</td>
<td colspan="9">&nbsp;</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>&nbsp;</td>
<td colspan="9">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</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]
Copy linkTweet thisAlerts:
@chazzyMar 28.2006 — Try changing this:

[code=php]
echo 'log id is', $logid;
trigger_error("ERROR: no rows were updated.", E_USER_ERROR);
}
[/code]


to
[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]


Also, this entire block doesn't work right:
[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]


move the die to the mysql_query line and you're missing a semicolon on the last line
Copy linkTweet thisAlerts:
@bazjonesauthorMar 28.2006 — ok so now im gettin a slightly different error

log id is

Fatal error: ERROR: no rows were updated. SQL Statement:UPDATE incidentlog SET source = 'APP1', type = 'Event', logtime = '0000-00-00 00:00:00', logtext = 'blah' WHERE logid = ''

Error (if any): in c:documents and settingsbarry jonesmy documentsuni workcom326 projectwebsitequality_managementincident_logedit.php on line 160
Copy linkTweet thisAlerts:
@bazjonesauthorMar 29.2006 — Hi

Does anyone have any ideas coz i still cant get this updating properly

Thanks
Copy linkTweet thisAlerts:
@balloonbuffoonMar 29.2006 — Well, the SQL statement says "WHERE logoid = ''"

Are you really searching for logoid's that are blank? You might not be setting $logoid correctly if your looking for an actual logoid. Also, is logoid a number field? If so, (like NogDog previously stated) remove the single quotes from around $logoid.

--Steve
Copy linkTweet thisAlerts:
@bazjonesauthorMar 29.2006 — i see where the problem is because when i have my WHERE logid = $logid it is displaying $logid as nothing

i have removed the single quotes from aroudn the $ logid and now i get this error

Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Copy linkTweet thisAlerts:
@bazjonesauthorMar 29.2006 — ok guys thanks for everyones help ive managed to get it working ok

thanks again
×

Success!

Help @bazjones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...