Page 1 of 1 [ 5 posts ] 

Scaramouche
Sea Gull
Sea Gull

User avatar

Joined: 25 Apr 2006
Gender: Male
Posts: 247

03 May 2006, 4:58 am

I'm trying to make a page for an assignment. The first section just enters and displays things. The second section produces a table of thigns in the database, with each row containing an Update button and a Delete button. But so far I have no idea how to make it work. :(

The entire file:

Code:
[?php

include("files/configuration.php");
include("files/top.php");
$row_count = 0;

/*******************************************************************/

echo '[h1]Rating list[/h1][hr][h2]Add a new rating[/h2]';

if (empty($_POST['description']))
{
 echo '[form action="'.$_SERVER['PHP_SELF'].'" method="post"]';
 echo '[b]Description: [/b][input type="text" name="description" maxlength="50" size="50" /][br][br]';
 echo '[input type="submit" value="Add rating" /]';
 echo '[/form]';
}
else
{
 $description  = stripslashes($_POST['description']);

 $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
 $query = "insert into rating (rating_id, rating_description) values (seq_rating.nextval, '".$description."')";
 $stmt  = oci_parse($conn, $query);

 if(@oci_execute($stmt))
 {
  echo '[script language="JavaScript"] alert("New record successfully added to database"); [/script]';
 }
 else
 {
  echo '[script language="JavaScript"] alert("Error adding record."); [/script]';
 }

 oci_free_statement($stmt);
 oci_close($conn);
}

/*******************************************************************/

echo '[hr][h2]List of current ratings[/h2]';

if(empty($_GET['action']))
{
 $listaction = "display";
}
else
{
 $listaction = $_GET['action'];
}

switch($listaction)
{

case "display":
 $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
 $query = "select * from ".TBL_RATING."";
 $stmt = oci_parse($conn, $query);
 oci_define_by_name($stmt, RATING_ID,          $id);
 oci_define_by_name($stmt, RATING_DESCRIPTION, $description);
 oci_execute($stmt);

 echo '[center][table class="form"]';

 echo '
  [tr align="left"]
  [th]Rating[/th]
  [th width="10%"]Update[/th]
  [th width="10%"]Delete[/th]
  [/tr]
 ';

 while($row = oci_fetch_array($stmt))
 {
  $id          = $row['RATING_ID'];
  $description = str_replace("  ", "", $row['RATING_DESCRIPTION']);
  $row_colour = ($row_count % 2) ? ROWCOLOUR1 : ROWCOLOUR2;
  echo '[tr class="form" bgcolor="'.$row_colour.'"]';
  echo '[form action="'.$_SERVER['PHP_SELF'].'?action=updatelist" method="post"]';
  echo '[input type="hidden" value="'.$id.'" /]';
  echo '[td class="form" width="80%"][input type="text" size="25" value="'.$description.'" /][/td]';
  echo '[td class="form" width="10%"][input type="submit" name="action" value="update" /][/td]';
  echo '[td class="form" width="10%"][input type="submit" name="action" value="delete" /][/td]';
  echo '[/tr]';
  $row_count++;
 }
 echo '[/table][/center]';

 oci_free_statement($stmt);
 oci_close($conn);
 break;

case "updatelist":
 if($_REQUEST["action"] == "update") // update the record
 {
  $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
  $query = "update rating set rating_description='$_POST[description]' where rating_id='".$id."'";
  $stmt  = oci_parse($conn, $query);
 }

 if($_REQUEST["action"] == "delete") // delete the record
 {
  $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
  $query = "delete from rating where rating_id='".$id."'";
  $stmt  = oci_parse($conn, $query);

  break;
 }

}

/*******************************************************************/

include("files/bottom.php");

?]


It's this section in particular which is giving me the trouble:
Code:

echo '[hr][h2]List of current ratings[/h2]';

if(empty($_GET['action']))
{
 $listaction = "display";
}
else
{
 $listaction = $_GET['action'];
}

switch($listaction)
{

case "display":
 $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
 $query = "select * from ".TBL_RATING."";
 $stmt = oci_parse($conn, $query);
 oci_define_by_name($stmt, RATING_ID,          $id);
 oci_define_by_name($stmt, RATING_DESCRIPTION, $description);
 oci_execute($stmt);

 echo '[center][table class="form"]';

 echo '
  [tr align="left"]
  [th]Rating[/th]
  [th width="10%"]Update[/th]
  [th width="10%"]Delete[/th]
  [/tr]
 ';

 while($row = oci_fetch_array($stmt))
 {
  $id          = $row['RATING_ID'];
  $description = str_replace("  ", "", $row['RATING_DESCRIPTION']);
  $row_colour = ($row_count % 2) ? ROWCOLOUR1 : ROWCOLOUR2;
  echo '[tr class="form" bgcolor="'.$row_colour.'"]';
  echo '[form action="'.$_SERVER['PHP_SELF'].'?action=updatelist" method="post"]';
  echo '[input type="hidden" value="'.$id.'" /]';
  echo '[td class="form" width="80%"][input type="text" size="25" value="'.$description.'" /][/td]';
  echo '[td class="form" width="10%"][input type="submit" name="action" value="update" /][/td]';
  echo '[td class="form" width="10%"][input type="submit" name="action" value="delete" /][/td]';
  echo '[/tr]';
  $row_count++;
 }
 echo '[/table][/center]';

 oci_free_statement($stmt);
 oci_close($conn);
 break;

case "updatelist":
 if($_REQUEST["action"] == "update") // update the record
 {
  $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
  $query = "update rating set rating_description='$_POST[description]' where rating_id='".$id."'";
  $stmt  = oci_parse($conn, $query);
 }

 if($_REQUEST["action"] == "delete") // delete the record
 {
  $conn = oci_connect(DB_USER,DB_PASS,DB_NAME) or die("Could not access database.");
  $query = "delete from rating where rating_id='".$id."'";
  $stmt  = oci_parse($conn, $query);

  break;
 }

}



jammie
Velociraptor
Velociraptor

User avatar

Joined: 2 Apr 2006
Gender: Male
Posts: 490
Location: UK

03 May 2006, 5:07 am

hiya,

still looking throught the code but the first thing thst strike me is you used the wrong type of braker / divider for you yags in and section whitch is HTML (should be XHTML...) all (X)HTML tags have < theas > brakets not the sqyare brakets. the[ square ] brakets are only used for bb code.

as for the rest of the script, can you please copy down the errors it is curretnly giving you, i assume you are running it ona localhost with the right software installed.

if you have any questions about the above then ask away i am happy to help.

jammie


_________________
<?php

$lion = "constant";
$lil_lion = "escape";
$baby = "dum dum, babo";
$jammie = $lion."sheepy and my comforts";


$jamie = $lion.$lil_lion.$baby.$jammie;
?>


Scaramouche
Sea Gull
Sea Gull

User avatar

Joined: 25 Apr 2006
Gender: Male
Posts: 247

03 May 2006, 5:17 am

I just did a Find/Replace and changed all the brackets to square brackets because the forum here doesn't support a lot of the HTML tags.



Scaramouche
Sea Gull
Sea Gull

User avatar

Joined: 25 Apr 2006
Gender: Male
Posts: 247

03 May 2006, 5:18 am

jammie wrote:
hiya,

as for the rest of the script, can you please copy down the errors it is curretnly giving you, i assume you are running it ona localhost with the right software installed.

Unfortunately I'm running it all off the university server, and I can't see error logs. The best I can do is ECHO things in my script.



jammie
Velociraptor
Velociraptor

User avatar

Joined: 2 Apr 2006
Gender: Male
Posts: 490
Location: UK

03 May 2006, 6:45 am

then download and install xampp. it is an all in one apche phph mysql sytem that has one installer and auto configure, it will help you emmensly.

if you have an issue installing it then let me know.

jammie


_________________
<?php

$lion = "constant";
$lil_lion = "escape";
$baby = "dum dum, babo";
$jammie = $lion."sheepy and my comforts";


$jamie = $lion.$lil_lion.$baby.$jammie;
?>