Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2006, 03:10 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble Updating My Database

Hello to everyone reading this.

Im a beginner of PHP and MySQL, and i'm having a little difficulty updating one of my databases.

Basically, i have a single page consisting of a table, where i echo some information from the database. This echoing occurs without fail.

I also have x3 drop down menus, one for a Comment, another for Progress and the last for confirming whether the job is Complete or not.

When i make my selections and press submit, it looks as though it updates the database, but it does not. Although the clear button works.

Here's my code.

--------------------------

<?
session_start();
?>

<?
include "conn.inc.php";
$query ="SELECT * FROM admin WHERE AdminID= '" . $_SESSION['admin_logged']."'
AND password =(password('" . $_SESSION['admin_password'] . "'));";
$result = mysql_query($query) or die(mysql_error());
$new = mysql_fetch_array($result);
?>

<html>
<head>
<title>Fault Reporting System : : Complete A Call</title>
<body background="h.gif">
<body>
<br>
<div align="center"><h2>Welcome <? echo $new['First_Name']; ?>.<br> Please Select A Call You Would Like To Complete</h2></div>
<br>

<?
include "conn1.inc.php";

$q1 = "SELECT FaultID, AdminID, StaffID, Location, Problem_Desc,
              Date, Technician_Comment, Progress, Complete
       FROM FAULT
       WHERE AdminID= '" . $_SESSION['admin_logged']."'
       AND Progress = 'Ongoing'";

$result = mysql_query($q1) or die(mysql_error());
$ans= mysql_num_rows($result);

?>

<?
// updating the database

include "conn1.inc.php";

    if ($_POST['submit'] == "Update")
    {
    if ($_POST['AdminID'] != "" && $_POST['Technician_Comment'] != "" && $_POST['Complete'] != ""
    && $_POST['Progress'] != "")

    $q8 = "INSERT INTO Fault(Technician_Comment, Progress)
       VALUES('" . $_POST['Techncian_Comment'] . "', '" . $_POST['Progress'] . "');";

      $result = mysql_query($q8) or die(mysql_error());
      $_SESSION['admin_logged'] = $_POST['AdminID'];
      $_SESSION['admin_password'] = $_POST['password'];
    }
?>


<?

//EOD, all table variables held between EOD statements;

$progress_table=<<<EOD
<div align="center"><h4>Here Are Your Outstanding Calls</h4></div>
<form action="Fault_All_My_Completed_Calls.php" method="post">
<table width="100%" border="5" cellpadding="1" cellspacing="1" align="center">
  <tr>
    <th>FaultID</th>
    <th>AdminID</th>
    <th>StaffID</th>
    <th>Location</th>
    <th>Problem Description</th>
    <th>Technician Comment</th>
    <th>Date</th>
    <th>Progress</th>
    <th>Complete</th>
  </tr>

EOD;

while($row = mysql_fetch_array($result))
{
    $FaultID = $row['FaultID'];
    $AdminID = $row['AdminID'];
    $StaffID = $row['StaffID'];
    $Location = $row['Location'];
    $Problem_Desc = $row['Problem_Desc'];
    $Technician_Comment = $row['Technician_Comment'];
    $Date = $row['Date'];
    $Progress = $row['Progress'];
    $Complete = $row['Complete'];

    $progress_table_info .=<<<EOD
    <tr>
      <td>$FaultID</td>
      <td>$AdminID</td>
      <td>$StaffID</td>
      <td>$Location</td>
      <td>$Problem_Desc</td>
      <td><select name="Technician_Comment">
    <option value="" SELECTED>Select Comment...</option>
    <option value="Working fine now">Working fine now</option>
    <option value="Sent back to manufacturer">Sent back to manufacturer</option>
    <option value="3rd party coming in to look at it">3rd party coming in to look at it</option>
    <option value="Need more time">Need more time</option>
          </select></td>
      <td>$Date</td>
      <td><select name="Progress">
    <option value="" SELECTED>Select Progress...</option>
    <option value="Ongoing">Ongoing</option>
    <option value="Complete">Complete</option>
          </select></td>

    <td><select name="Complete">
    <option value="" SELECTED>Complete...</option>
    <option value="Yes">Yes</option>
    <option value="No">No</option>
    </select></td>

    </tr>

EOD;
}
$progress_table_info .=<<<EOD


<tr>
  <td> </td>

EOD;

$progress_table_end ="</table>";
$progress =<<<PROGRESS
    $progress_table
    $progress_table_info
    $progress_table_end
PROGRESS;
echo $progress;
?>
<br>
<br>
<input type="submit" name="submit" value="Submit">
<input type="reset" value="Clear">
</body>
</html>

----------------------------

If anyone has any solutions i'd be glad to hear them. Thankyou.

H.



 
Old March 12th, 2006, 07:56 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

$q8 = "INSERT INTO Fault(Technician_Comment, Progress)
       VALUES('" . $_POST['Techncian_Comment'] . "', '" . $_POST['Progress'] . "');";

You misspelled Technician; Techncian_Comment should be Technician_Comment


- A.Kahtava
 
Old March 12th, 2006, 08:31 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A tip on naming variables, functions, procedures, etc...:
• Avoid misspelled words in names
• Avoid words that are commonly misspelled in English

- A.Kahtava
 
Old March 13th, 2006, 06:50 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I made the changes to the code, thanks for that by the way. But the database is STILL NOT updating for some reason.

The modified code is below. I can't see much wrong with it to be honest. But then again i did not notice the spelling mistake neither. .

My initial thoughts were, are you able to echo information and update information in a single form? I'm not sure, although i don't see why not, and thats why i have made this such attempt.

Again, if anyone can help, i'd be glad to hear.

Heres the newly modified code.

------------------

<?
session_start();
?>

<?
include "conn.inc.php";
$query ="SELECT * FROM admin WHERE AdminID= '" . $_SESSION['admin_logged']."'
AND password =(password('" . $_SESSION['admin_password'] . "'));";
$result = mysql_query($query) or die(mysql_error());
$new = mysql_fetch_array($result);
?>

<html>
<head>
<title>Fault Reporting System : : Complete A Call</title>
<body background="h.gif">
<body>
<br>
<div align="center"><h2>Welcome <? echo $new['First_Name']; ?>.<br> Please Select A Call You Would Like To Complete</h2></div>
<br>

<?
include "conn1.inc.php";

$q1 = "SELECT FaultID, AdminID, StaffID, Location, Problem_Desc,
              Date, Technician_Comment, Progress, Complete
       FROM FAULT
       WHERE AdminID= '" . $_SESSION['admin_logged']."'
       AND Progress = 'Ongoing'";

$result = mysql_query($q1) or die(mysql_error());
$ans= mysql_num_rows($result);

?>

<?
// updating the database

include "conn1.inc.php";

    if ($_POST['submit'] == "Update")
    {
    if ($_POST['AdminID'] != "" && $_POST['Technician_Comment'] != "" && $_POST['Complete'] != ""
    && $_POST['Progress'] != "")

    $q8 = "INSERT INTO Fault(Technician_Comment, Progress, Complete)
       VALUES('" . $_POST['Technician_Comment'] . "', '" . $_POST['Progress'] . "', '" . $_POST['Complete'] . "');";

      $result = mysql_query($q8) or die(mysql_error());
      $_SESSION['admin_logged'] = $_POST['AdminID'];
      $_SESSION['admin_password'] = $_POST['password'];
    }
?>


<?

//EOD, all table variables held between EOD statements;

$progress_table=<<<EOD
<div align="center"><h4>Here Are Your Outstanding Calls</h4></div>
<form action="Fault_All_My_Completed_Calls.php" method="post">
<table width="100%" border="5" cellpadding="1" cellspacing="1" align="center">
  <tr>
    <th>FaultID</th>
    <th>AdminID</th>
    <th>StaffID</th>
    <th>Location</th>
    <th>Problem Description</th>
    <th>Technician Comment</th>
    <th>Date</th>
    <th>Progress</th>
    <th>Complete</th>
  </tr>

EOD;

while($row = mysql_fetch_array($result))
{
    $FaultID = $row['FaultID'];
    $AdminID = $row['AdminID'];
    $StaffID = $row['StaffID'];
    $Location = $row['Location'];
    $Problem_Desc = $row['Problem_Desc'];
    $Technician_Comment = $row['Technician_Comment'];
    $Date = $row['Date'];
    $Progress = $row['Progress'];
    $Complete = $row['Complete'];

    $progress_table_info .=<<<EOD
    <tr>
      <td>$FaultID</td>
      <td>$AdminID</td>
      <td>$StaffID</td>
      <td>$Location</td>
      <td>$Problem_Desc</td>
      <td><select name="Technician_Comment">
    <option value="" SELECTED>Select Comment...</option>
    <option value="Working fine now">Working fine now</option>
    <option value="Sent back to manufacturer">Sent back to manufacturer</option>
    <option value="3rd party coming in to look at it">3rd party coming in to look at it</option>
    <option value="Need more time">Need more time</option>
          </select></td>
      <td>$Date</td>
      <td><select name="Progress">
    <option value="" SELECTED>Select Progress...</option>
    <option value="Ongoing">Ongoing</option>
    <option value="Complete">Complete</option>
          </select></td>

    <td><select name="Complete">
    <option value="" SELECTED>Complete...</option>
    <option value="Yes">Yes</option>
    <option value="No">No</option>
    </select></td>

    </tr>

EOD;
}
$progress_table_info .=<<<EOD


<tr>
  <td> </td>

EOD;

$progress_table_end ="</table>";
$progress =<<<PROGRESS
    $progress_table
    $progress_table_info
    $progress_table_end
PROGRESS;
echo $progress;
?>
<br>
<br>
<input type="submit" name="submit" value="Submit">
<input type="reset" value="Clear">
</body>
</html>

-----------------------
Thankyou.

H.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble writing to an Access Database JAdkins Classic ASP Basics 5 June 27th, 2007 03:05 PM
trouble updating pages to server using dreamweaver ramona72 Dreamweaver (all versions) 2 August 21st, 2006 11:55 AM
Trouble writing database MDrumm Classic ASP Databases 5 August 4th, 2005 03:27 PM
Trouble connecting to an online database. toddbryan Classic ASP Databases 2 October 27th, 2004 12:04 AM
trouble with database connection databass Classic ASP Databases 1 August 15th, 2003 08:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.