Jump to content

[SOLVED] modifying record


bundred

Recommended Posts

Hi i have three files

 

act5select.php  -  This selects all records from a oracle database and displays them, it also has the AccomID clickable to another page to modify that record

 

<?php
putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$conn = OCILogon("rbundred","000000","shu10g");

IF ($_POST[HouseNo]=="") $HouseNo='null';
ELSE $HouseNo=$_POST[HouseNo];
IF ($_POST[Postcode]=="") $Postcode='null';
ELSE $Postcode=$_POST[Postcode];
IF ($_POST[NumberOfRooms]=="") $NumberOfRooms='null';
ELSE $NumberOfRooms=$_POST[NumberOfRooms];


$sql="update Accommodation set Street ='$_POST[street]', Town='$_POST[Town]', Type='$_POST[Type]', Furnished='$_POST[Furnished]'";


$stmt = ociparse($conn,$sql);
ociexecute($stmt);
print "record updated ok";

?>

 

act5update.php  - which is where the row is displayed and u can modify it.

 

<html>
<?php
$sql="select * from Accommodation where AccomID =".$_GET["AccomID"];
putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$conn = OCILogon("rbundred","111111","shu10g");
$stmt = ociparse($conn,$sql);
ociexecute($stmt);
ocifetchinto($stmt,$row);
?>
<form name="form1" method="post" action="act5ahandler.php">
<input name="AccomID" type=hidden id="AccomID" value=<?php print $row[0];?>>

<table width="50%" border="0">
<tr>
<td><strong>AccomID</strong></td>
<td><?php print $row[0];?></td>
</tr>
<tr>
<td><strong>OwnerID</strong></td>
<td><?php print $row[1];?></td>
</tr>
<tr>
<td><strong>HouseNo</strong></td>
<td><input name="HouseNo"type="text"id="HouseNo"value=<?php print $row[2];?>></td>
</tr>
<tr>
<td><strong>Street</strong></td>
<td><input name="Street"type="text"id="Street"value=<?php print $row[3];?>></td>
</tr>
<tr>
<td><strong>Town</strong></td>
<td><input name="Town"type="text"id="Town"value=<?php print $row[4];?>></td>
</tr>
<tr>
<td><strong>PostCode</strong></td>
<td><input name="Postcode"type="text"id="Postcode"value=<?php print $row[5];?>></td>
</tr>
<tr>
<td><strong>NumberOfRooms</strong></td>
<td><input name="NumberOfRooms"type="text"id="Furnished"value=<?php print $row[6];?>></td>
</tr>
<tr>
<td><strong>Type</strong></td>
<td><input name="Type"type="text"id="Furnished"value=<?php print $row[7];?>></td>
</tr>
<tr>
<td><strong>Furnished</strong></td>
<td><input name="Furnished"type="text"id="Furnished"value=<?php print $row[8];?>></td>
</tr>
</table><p>
<input type="submit" name="submit"value="submit">
</p>
</form>
</html>

 

 

and finally act6handle.php  - this is where it is supposed to update the record

 

<html>

<?php
putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$conn = OCILogon("rbundred","222222","shu10g");

IF ($_POST[HouseNo]=="") $HouseNo='null';
ELSE $HouseNo=$_POST[HouseNo];
IF ($_POST[Postcode]=="") $Postcode='null';
ELSE $Postcode=$_POST[Postcode];
IF ($_POST[NumberOfRooms]=="") $NumberOfRooms='null';
ELSE $NumberOfRooms=$_POST[NumberOfRooms];


$sql="update Accommodation set Street ='$_POST[street]', Town='$_POST[Town]', Type='$_POST[Type]', Furnished='$_POST[Furnished]'";


$stmt = ociparse($conn,$sql);
ociexecute($stmt);
print "record updated ok";

?>


</html>

 

The problem i have is the first two files are ok but when i modify a record it modifys every record in the table instead of only that row

 

Rob

Link to comment
https://forums.phpfreaks.com/topic/101354-solved-modifying-record/
Share on other sites

First: The act5select.php file you posted is the same as the handle one...i assume you just got the files mixed up when posting....

 

Easy fix. You need to specify which record to update in your UPDATE command. For this, you will want the records ID. So, first we need to pass the ID to the handle page.

 

on the update page, change the form tag to this:

<form name="form1" method="post" action="act5ahandler.php?AccomID=<?php print $_GET['AccomID']; ?>">

 

and then on the handle page:

$sql="update Accommodation set Street ='$_POST[street]', Town='$_POST[Town]', Type='$_POST[Type]', Furnished='$_POST[Furnished]' WHERE AccomID = '$_GET['AccomID']'";

 

hi i tryed what u said but get this error

 

http://ivy.shu.ac.uk/~rbundred/assignment/act5ahandler.php

 

 

PS the code for act5select.php is

<html>
<body>
<?php
putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$conn = OCILogon("rbundred","oftiz4","shu10g");
$query = "select * from Accommodation";
$stmt = ociparse($conn,$query);
ociexecute($stmt);
while (ocifetchinto($stmt,$row))
{
print "<a HREF=act5aupdate.php?AccomID=" .$row[0]. ">" .$row[0]. "</a>";
print " " . $row[1]. " " . $row[2]. " " . $row[3]. " " . $row[4]. " " . $row[5]. " " . $row[6]. " " . $row[7]. "<br>";

}
ocifreestatement($stmt);
ocilogoff($conn);
?>
</html>

 

 

sorry for the mix up

This doesnt give any errors now but it doesnt update the database.

 

try for you self if you like

 

http://ivy.shu.ac.uk/~rbundred/assignment/act5aselect.php

 

 

then to check the database for the update

 

http://ivy.shu.ac.uk/~rbundred/assignment/select_all_from_accom.php

 

Rob

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.