update problems

General discussions related to php

Moderators: macek, egami, gesf

genetix
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jun 06, 2012 10:05 am

update problems

Postby genetix » Wed Jun 06, 2012 10:18 am

Hi everyone,

im fairly new to this. Can someone please help me out. Basically i have two issue. i have created a fault reporting website for a uni, on the admin cp, they go onto a page to complete faults, when they select the button underneath each fault it then runs a seperate page. The issue here is that it updates which ever fault it wants not the one the admin has clicked for.


the main code on the page for completing faults:

Code: Select all

<?php

  session_start();

  if ( isset($_SESSION['username']) )      // Check if the session variable named username exists.  It only exists if the user has correctly logged in.
   {
    echo "Welcome ".$_SESSION['username'].", You are now viewing the Admin page<br /><br />";
 
      // Make a connection to the MySQL database server


       $dbserverIP="cet-mysql-01.cet.bolton.ac.uk";
       $dbusername="lrh1gcc";
       $dbuserpassword="0803549";
       $connection = mysql_connect($dbserverIP,$dbusername,$dbuserpassword) or die("Couldn't connect to the dbserver.");

      // Make a connection to the database

       $dbname="lrh1gcc_db";  // Use your own database name
       $dbselectok = mysql_select_db($dbname,$connection) or die("Couldn't select the remote database.");
   

   $sqlstatement = "SELECT * FROM fault WHERE faultFixed = 0";
        $sql_result = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement");


//  Process the information retrieved from the database and display to the user's browser

   echo "<br /><br />Below is a list of all the new faults, that have not been fixed yet. <br /><br /><br />";

       while ($row = mysql_fetch_array($sql_result))
     {
    $fid = $row["faultId"];
         $rn = $row["roomNo"];
         $pn = $row["pcNo"];
         $id = $row["idNo"];
         $ft= $row["faultType"]; 
   $des = $row["description"];
        $comment= $row["faultComment"];

   $_SESSION['fault'] = $fid;

  echo  "Fault id is: $fid, <BR>Room Number is: $rn <BR> PC Number is: $pn <BR> Your ID Number is: $id <BR> The fault type is: $ft <BR> Your description is: $des <BR> Admin added the following comments about the fault:<BR> $comment<BR><BR>\n";
?>
<form action="fixFault.php">
 <input type="submit" name="fix"  value="Complete"/><BR><BR><BR><BR>
</form>
<?php

//ends log in session
          }



         
 else
 {
   echo "You must be logged in.<br />";
 echo "<a href='login.php'>Login</a>";
   }

?>



the code that runs the complete script:

Code: Select all

<?php
   session_start();

   $FAULTID = $_SESSION['fault'];


      // Make a connection to the MySQL database server
       $dbserverIP="cet-mysql-01.cet.bolton.ac.uk";
       $dbusername="lrh1gcc";
       $dbuserpassword="0803549";
       $connection = mysql_connect($dbserverIP,$dbusername,$dbuserpassword) or die("Couldn't connect to the dbserver.");

   // Make a connection to the database
       $dbname="lrh1gcc_db";  // Use your own database name
       $dbselectok = mysql_select_db($dbname,$connection) or die("Couldn't select the remote database.");
   
   //create a query to retrieve the fault id from the db.
   $sqlstatement = "SELECT * FROM fault WHERE faultId=$FAULTID ";
        $sql_result = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement");


        //CHANGE THE FAULT FIXED TO 1 SO THAT IT IS NO LONGER DISPLAYED ON THE NEWfAULTS PAGE
   $sql="UPDATE fault SET faultFixed='1' WHERE faultId = $FAULTID";
        $sql_resultfix = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement");
   $resultfix=mysql_query($sql);



if(!session_is_registered(fixedFault)){
   header("location:newFaults.php");
   }




    //Free up any memory holding the database records
    mysql_free_result($sql_result);

?>




the second issue i have is on my other admin page. I need to be able to update the file. i have put a text box under each fault so the admin can just write any comments and then click to update, however it is not updating the mySQL database.

again main php for this issue:

Code: Select all

<?php

  session_start();

  if ( isset($_SESSION['username']) )      // Check if the session variable named username exists.  It only exists if the user has correctly logged in.
   {
    echo "Welcome ".$_SESSION['username'].", You are now viewing the Admin page<br /><br />";
 
      // Make a connection to the MySQL database server


       $dbserverIP="cet-mysql-01.cet.bolton.ac.uk";
       $dbusername="lrh1gcc";
       $dbuserpassword="0803549";
       $connection = mysql_connect($dbserverIP,$dbusername,$dbuserpassword) or die("Couldn't connect to the dbserver.");

      // Make a connection to the database

       $dbname="lrh1gcc_db";  // Use your own database name
       $dbselectok = mysql_select_db($dbname,$connection) or die("Couldn't select the remote database.");
   

   $sqlstatement = "SELECT * FROM fault WHERE faultFixed = 0";
        $sql_result = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement");

//  Process the information retrieved from the database and display to the user's browser

   echo "<br /><br />Below is a list of all the new faults, that have not been fixed yet. <br /><br /><br />";
       while ($row = mysql_fetch_array($sql_result))
     {
    $fid = $row["faultId"];
         $rn = $row["roomNo"];
         $pn = $row["pcNo"];
         $id = $row["idNo"];
         $ft= $row["faultType"]; 
   $des = $row["description"];

   $_SESSION['fault'] = $fid;
 
  echo  "Fault id is: $fid, <BR>Room Number is: $rn <BR> PC Number is: $pn <BR> Your ID Number is: $id <BR> The fault type is: $ft <BR> Your description is: $des <BR> Please add any comments for this fault below<BR>\n";

  ?>

  <form action="updateFault.php" method="post">
  <textarea name="desc"  cols="20" rows="3" class="required" title="update."></textarea>
  <input type="submit",  value="Update"/>
  </form>
  <?php
        }


}           
 else
 {
   echo "You must be logged in.<br />";
   echo "<a href='login.php'>Login</a>";
   }
   

?>



and the script in the external file:

Code: Select all

<?php
   session_start();
   $UPDATE = $_POST['desc'];
   $FAULTID = $_SESSION['fault'];
   

      // Make a connection to the MySQL database server
       $dbserverIP="cet-mysql-01.cet.bolton.ac.uk";
       $dbusername="lrh1gcc";
       $dbuserpassword="0803549";
       $connection = mysql_connect($dbserverIP,$dbusername,$dbuserpassword) or die("Couldn't connect to the dbserver.");

   // Make a connection to the database
       $dbname="lrh1gcc_db";  // Use your own database name
       $dbselectok = mysql_select_db($dbname,$connection) or die("Couldn't select the remote database.");
   
   //create a query to retrieve the fault id from the db.
   $sqlstatement = "SELECT * FROM fault WHERE faultId=$FAULTID ";
        $sql_result = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement");


        //UPDATE THE COMMENT TO WHAT EVER THE USER HAS INPUTTED.
   $sql="UPDATE fault SET faultComment=$UPDATE WHERE faultId = $FAULTID";
        $sql_resultfix = mysql_query($sqlstatement,$connection) or die("Couldn't execute the SQL SELECT statement");
   $resultfix=mysql_query($sql);

   if(!session_is_registered(updateFault)){
   header("location:update.php");
   }




    //Free up any memory holding the database records
    mysql_free_result($sql_result);

 


?>



Any help at all with this would be hugely appreciated. thanks

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron