/    Sign up×
Community /Pin to ProfileBookmark

Syntax Problems

My code is to allow the user to edit data, this is my edit.php but no matter which line i choose it only ever updates the top row of the database, can anyone see why this is happening?

<?
$db_table = “pcr”;
$query = “SELECT `pcrid`, `pcrtitle`, `taskdesc`, `raisedby`, `status`, `nextstep`, `engineer`, `pcrdate` from `$db_table` WHERE `pcrid` =’$pcrid'”;
$result = mysql_query($query);
$get_info = mysql_fetch_array($result);
?>
<form action=”<? echo($PHP_SELF); ?>” method=POST>
<table width=”75%” border=”0″>
<tr>
<td> PCRTitle: </td>
<td><input type=”TEXT” name=”pcrtitle” size=75 value=”<? echo($get_info[“pcrtitle”]); ?>”>
</td>
</tr>
<tr>
<td>RaisedBy:</td>
<td><select name=”raisedby” id=”raisedby” value=”<? echo($get_info[“raisedby”]); ?>”>
<option>Plant</option>
<option>PCC</option>
</select></td>
</tr>
<tr>
<td>TaskDesc:</td>
<td><textarea name=”TaskDesc” rows=8 cols=90 value=”<? echo($get_info[“taskdesc”]); ?>”></textarea></td>
</tr>
<tr>
<td>Status:</td>
<td><select name=”status” id=”status” value=”<? echo($get_info[“status”]); ?>”>
<option>Raised</option>
<option>On Hold</option>
<option>In Progress</option>
<option>Rejected</option>
<option>Completed</option>
</select></td>
</tr>
<tr>
<td>NextStep:</td>
<td><textarea name=”NextStep” rows=5 cols=50 value=”<? echo($get_info[“nextstep”]); ?>”></textarea></td>
</tr>
<tr>
<td>Engineer:</td>
<td><select name=”engineer” id=”engineer” value=”<? echo($get_info[“engineer”]); ?>”>
<option>John Kelly</option>
<option>Paul Fox</option>
<option>Paul West</option>
<option>Mike Elliot</option>
<option>Robert Tate</option>
<option>Barry Jones</option>
</select></td>
</tr>
<tr>
<td>PCRDate:</td>
<td><input type=”TEXT” name=”pcrdate” size=30 value=”<? echo($get_info[“pcrdate”]); ?>”></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name=”Submit” type=”submit” value=”Submit”></td>
</tr>
</table>
<br>
</form>

<?
//display the info you want to edit in textboxes.
//after it has been submitted do this:
$query = “UPDATE `pcr` SET `PCRTitle` = ‘”. $_POST[“pcrtitle”] .”‘, `RaisedBy` = ‘”. $_POST[“raisedby”] .”‘, `taskdesc` = ‘”. $_POST[“taskdesc”] .”‘, `Status` = ‘”. $_POST[“status”] .”‘, `NextStep` = ‘”. $_POST[“nextstep”] .”‘, `Engineer` = ‘”. $_POST[“engineer”] .”‘, `PCRDate` = ‘”. $_POST[“pcrdate”] .”‘ WHERE `pcrid` = ‘$pcrid'”;
$result = mysql_query($query);
echo(“<SCRIPT LANGUAGE=’JavaScript’>
window.alert(‘PCR Has Been Updated’)</SCRIPT>”);
?>

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@scragarDec 13.2004 — have you defined $pcrid?

are you retriveing the correct value?

it appears to be that your PHP code is using a value of 0 or 1...
Copy linkTweet thisAlerts:
@bazjonesauthorDec 13.2004 — This is where i am haiving problems i think, on the previous page where the user decides which line to edit i have the following code,

// Loop through each row printing out values

for ( $i=1; $i <= $num_rows; $i++ )

{

$row = mysql_fetch_row($result);

echo '<tr>';
// Loop through each column
for ( $j=0; $j <= $num_cols; $j++ )
{
if ($j==0){
echo '<td><a href="edit.php?pcrid='.$row[0].'">'.$row[0].'</a></td>';
}
else{
echo '<td>'.$row[$j].'</td>';
}
}
echo '</tr>';
}


echo '</table><br>';

Does the above code have any impact on how i declare the $pcrid??
Copy linkTweet thisAlerts:
@scragarDec 13.2004 — try changing the page you posted first so this:
[code=php]$pcrid = $_GET['pcrid'];[/code]
appears on the second line above:
[code=php]$db_table = "pcr"; [/code]
Copy linkTweet thisAlerts:
@bazjonesauthorDec 13.2004 — Thanks thats all i was missing, its the most annoying thing in the world when the reason something isnt working properly is because u have missed something little and daft like that!!

Thanks again mate!!
Copy linkTweet thisAlerts:
@scragarDec 13.2004 — missing something simple like that is often the main error, I think that it's always best to get someone else to look through your code, it provides a fresh eye and a new method of thinking(which is why me and a freind at college share most of your prodjects, I'll spot something he missed and he'll spot an error in my code...)
Copy linkTweet thisAlerts:
@bazjonesauthorDec 13.2004 — Yeah definetly the best way, thats why forums always come in handy especially if you dont really know anyone else who knows about php!
×

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.18,
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,
)...