Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

one-component querying won't work

Status
Not open for further replies.

molly2ka

Programmer
Mar 20, 2004
27
US
Hi all,

I'm running apache and php on windows xp and I've got a problem with one-component querying. I've looked through forums but can't find any answers!! Ok so this is what happens, I'm displaying a page which takes variables in the url when it was called, and uses them to fetch a record from a database (mysql) and it displays them in a form. When the user makes changes to the record and clicks on save, i'd like to update the database by calling a new script which does the job, but the user should not see this happen and the browser should just stay the same. Problem is when I use $HTTP_REFERER, when the user clicks on the save button, it takes them localhost which displays all my php files in a list.Any ideas???

Relevant part of Calling page:


$query = "SELECT * FROM composition WHERE comp_id =\"".$ID."\"";

if (!$result= mysql_query($query))
showerror();


$row = mysql_fetch_array($result);

$formVars = array();

$formVars["comp_id"] = $row["comp_id"];
$formVars["title"] = $row["title"];
$formVars['composer'] = $row['composer'];
$formVars ['comp_date'] = $row['comp_date'];
$formVars ['genre'] = $row['genre'];
$formVars ['note'] = $row['note'];

?>
<p>You can edit details of this record from here
<br>(<font color="red">*</font> denotes a mandatory field)</p>


<form method = "POST" action = "editReceipt.php?table=composition" onsubmit ="return checkForm()">

<table cellpadding=5 border=5 align = "center">
<th>Field
<th>Value


<input type = "hidden" name = "id" value = "<? echo $formVars["comp_id"]; ?>" size = 30>


<tr>
<td>Title <font color='red'>*</font> </td>
<td><input type = "text" name = "title" value = "<? echo $formVars["title"]; ?>" size = 30></td>
</tr>


<tr>
<td>Composer <font color='red'>*</font> </td>
<td><input type = "text" name = "composer" value = "<? echo $formVars["composer"]; ?>" size = 30></td>
</tr>

<tr>
<td>Composition Year <font color='red'>*</font> </td>
<td><input type = "text" name = "comp_date" value = "<? echo $formVars["comp_date"]; ?>" size = 4 maxlength = 4></td>
</tr>

<tr>
<td>Genre <font color='red'>*</font> </td>
<td><input type = "text" name = "genre" value = "<? echo $formVars["genre"]; ?>" size = 30></td>
</tr>

<tr>
<td>Note</td>
<td>
<textarea rows="3" name= "note" cols="20"><? echo $formVars["note"]; ?></textarea>
</td>
</tr>
<br>
</table>
<p>
<input type = "submit" value = "Save">
<input type = "reset" value = "Reset">
</form>


This is how i use HTTP_REFERER in the editReceipt.php script:

//all the database querying goes here

if(!$result = mysql_query($query))
{
echo "<p>Sorry the record was not updated successfully</p>";
}else
{
header("Location: $HTTP_REFERER");
exit;
}

I know that it updates correctly because in the past i just display a page saying how it was successful. Any ideas??? Also, it is part of a frame document and all of this loads into the main frame.

Manni xxx
 
...the browser should just stay the same

PHP is a server side technology and applications built in PHP are discontinuous. That means the browser cannot stay the same, it has to send the information to be updated to the updating script.
However, what you can do is to rebuild the page the same way it appeared before. There's no way to get around that.
Suggestion:
Have a branch in the file that builds the page which does the database update and make it only be called when the SAVE button is pressed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top