Click to See Complete Forum and Search --> : Syntax Problems


bazjones
12-13-2004, 04:50 AM
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>");
?>

scragar
12-13-2004, 04:58 AM
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...

bazjones
12-13-2004, 05:04 AM
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??

scragar
12-13-2004, 05:10 AM
try changing the page you posted first so this:
$pcrid = $_GET['pcrid'];
appears on the second line above:
$db_table = "pcr";

bazjones
12-13-2004, 05:14 AM
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!!

scragar
12-13-2004, 05:28 AM
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...)

bazjones
12-13-2004, 05:35 AM
Yeah definetly the best way, thats why forums always come in handy especially if you dont really know anyone else who knows about php!