Hi everyone, just a couple of questions.
At the moment I'm stuck with a piece of code, I can't see why it won't work.
The page below has the variable $Repair_No posted to it from another page, the code to select the details from the database work fine and information is displayed, the problem i'm having is with the $storesupdate query. For some reason it will not write to the database. A second issue is that currently when the page does write to the database it creates a new record and doesn't update the record I want.
Many thanks for any help!
Heres a copy of the entire code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
// Include important information
require_once('common/important.inc');
//Include the header
require_once($fullpath."common/header.inc");
//Check that user is logged in
if (isset($userid))
{
$firstname = strtok($username,' ');
?>
<h1>Customer Repair Form</h1>
<?php
//Selects the highest repair number from the Repairs table and increase it by one, this number is then used as the repair
//number in the new repairs forms.
$maxq = "select max(Repair_No) from Repairs" ;
$maxqresult = mysql_query($maxq, $link_id);
while($query_data = mysql_fetch_row($maxqresult))
{
$Maxrecord = $query_data[0];
}
$Maxrecord++;
?>
<?php
//changes the status depending on what fields have been filled in on the form.
if($Repair_No == "")
{
$Status = 'New Repair Order';
}
elseif($Repair_No != "")
{
$Status = 'Awaiting Stores Booking In';
}
elseif($Recieved_by != "" && $Quantity_Recieved != "" && $Date_Recieved != "")
{
$Status = 'Booked in and Awaiting Inspection';
}
?>
<?php
if($Repair_No != "")
{
$selectquery = "SELECT * FROM Repairs WHERE Repair_No ='$Repair_No'";
$selectresult = mysql_query($selectquery, $link_id);
$query_data = mysql_fetch_assoc ($selectresult);
$Repair_No = $query_data['Repair_No'];
$Customer_Name = $query_data['Customer_Name'];
$Customer_Location = $query_data['Customer_Location'];
$Part_Description = $query_data['Part_Description'];
$Raised_By = $query_data['Raised_By'];
$Contact = $query_data['Contact'];
$Part_No = $query_data['Part_No'];
$Date_Entered = $query_data['Date_Entered'];
$Quantity = $query_data['Quantity'];
$Quantity_Recieved = $query_data['Quantity_Recieved'];
$Recieved_By = $query_data['Recieved_By'];
$Date_Recieved = $query_data['Date_Recieved'];
}
?>
<?php
//Once data has been inserted into the form and the update button clicked this will run and insert it into the database.
if(isset($insert)){
$insertquery = "INSERT INTO Repairs SET Repair_No = '$Maxrecord', Customer_Name = '$Customer_Name', Customer_Location = '$Customer_Location',
Raised_By = '$Raised_By', Contact = '$Contact', Part_No = '$Part_No' , Date_Entered = '$Date_Entered',
Part_Description = '$Part_Description' , Quantity = '$Quantity'";
$CreateResult = mysql_query($insertquery, $link_id);
$numrows = mysql_fetch_row($CreateResult);
//echo $insertquery;
header ("location: {$_SERVER["PHP_SELF"]}");
}
?>
<?php
//If there is no repair number then select the customer name and location from Custom2.
if($Repair_No == ""){
$CustomerDetails = "SELECT Customer_Name, Customer_Location FROM Custom2 WHERE Customer_Reference = '$CustomerReference'";
$Customerresult = mysql_query($CustomerDetails , $link_id);
$query_data = mysql_fetch_assoc ($Customerresult);
$Customer_Name = $query_data['Customer_Name'];
$Customer_Location = $query_data['Customer_Location'];
//echo $CustomerDetails;
header ("location: {$_SERVER["PHP_SELF"]}");
}
?>
<?php
if (isset($insert))
{
{
if ($Quantity_Recieved != "" && $Recieved_By != "" && $Date_Recieved != "")
$storesupdate = "UPDATE Repairs SET Repair_No = '$Repair_No', Quantity_Recieved = '$Quantity_Recieved', Recieved_By = '$Recieved_By',
Date_Recieved = '$Date_Recieved' WHERE Repair_No = '$Repair_No'";
$CreateResult = mysql_query($storesupdate, $link_id);
$numrows = mysql_fetch_row($CreateResult);
echo $storesupdate;
header ("location: {$_SERVER["PHP_SELF"]}");
}
}
?>
At the moment I'm stuck with a piece of code, I can't see why it won't work.
The page below has the variable $Repair_No posted to it from another page, the code to select the details from the database work fine and information is displayed, the problem i'm having is with the $storesupdate query. For some reason it will not write to the database. A second issue is that currently when the page does write to the database it creates a new record and doesn't update the record I want.
Many thanks for any help!
Heres a copy of the entire code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
// Include important information
require_once('common/important.inc');
//Include the header
require_once($fullpath."common/header.inc");
//Check that user is logged in
if (isset($userid))
{
$firstname = strtok($username,' ');
?>
<h1>Customer Repair Form</h1>
<?php
//Selects the highest repair number from the Repairs table and increase it by one, this number is then used as the repair
//number in the new repairs forms.
$maxq = "select max(Repair_No) from Repairs" ;
$maxqresult = mysql_query($maxq, $link_id);
while($query_data = mysql_fetch_row($maxqresult))
{
$Maxrecord = $query_data[0];
}
$Maxrecord++;
?>
<?php
//changes the status depending on what fields have been filled in on the form.
if($Repair_No == "")
{
$Status = 'New Repair Order';
}
elseif($Repair_No != "")
{
$Status = 'Awaiting Stores Booking In';
}
elseif($Recieved_by != "" && $Quantity_Recieved != "" && $Date_Recieved != "")
{
$Status = 'Booked in and Awaiting Inspection';
}
?>
<?php
if($Repair_No != "")
{
$selectquery = "SELECT * FROM Repairs WHERE Repair_No ='$Repair_No'";
$selectresult = mysql_query($selectquery, $link_id);
$query_data = mysql_fetch_assoc ($selectresult);
$Repair_No = $query_data['Repair_No'];
$Customer_Name = $query_data['Customer_Name'];
$Customer_Location = $query_data['Customer_Location'];
$Part_Description = $query_data['Part_Description'];
$Raised_By = $query_data['Raised_By'];
$Contact = $query_data['Contact'];
$Part_No = $query_data['Part_No'];
$Date_Entered = $query_data['Date_Entered'];
$Quantity = $query_data['Quantity'];
$Quantity_Recieved = $query_data['Quantity_Recieved'];
$Recieved_By = $query_data['Recieved_By'];
$Date_Recieved = $query_data['Date_Recieved'];
}
?>
<?php
//Once data has been inserted into the form and the update button clicked this will run and insert it into the database.
if(isset($insert)){
$insertquery = "INSERT INTO Repairs SET Repair_No = '$Maxrecord', Customer_Name = '$Customer_Name', Customer_Location = '$Customer_Location',
Raised_By = '$Raised_By', Contact = '$Contact', Part_No = '$Part_No' , Date_Entered = '$Date_Entered',
Part_Description = '$Part_Description' , Quantity = '$Quantity'";
$CreateResult = mysql_query($insertquery, $link_id);
$numrows = mysql_fetch_row($CreateResult);
//echo $insertquery;
header ("location: {$_SERVER["PHP_SELF"]}");
}
?>
<?php
//If there is no repair number then select the customer name and location from Custom2.
if($Repair_No == ""){
$CustomerDetails = "SELECT Customer_Name, Customer_Location FROM Custom2 WHERE Customer_Reference = '$CustomerReference'";
$Customerresult = mysql_query($CustomerDetails , $link_id);
$query_data = mysql_fetch_assoc ($Customerresult);
$Customer_Name = $query_data['Customer_Name'];
$Customer_Location = $query_data['Customer_Location'];
//echo $CustomerDetails;
header ("location: {$_SERVER["PHP_SELF"]}");
}
?>
<?php
if (isset($insert))
{
{
if ($Quantity_Recieved != "" && $Recieved_By != "" && $Date_Recieved != "")
$storesupdate = "UPDATE Repairs SET Repair_No = '$Repair_No', Quantity_Recieved = '$Quantity_Recieved', Recieved_By = '$Recieved_By',
Date_Recieved = '$Date_Recieved' WHERE Repair_No = '$Repair_No'";
$CreateResult = mysql_query($storesupdate, $link_id);
$numrows = mysql_fetch_row($CreateResult);
echo $storesupdate;
header ("location: {$_SERVER["PHP_SELF"]}");
}
}
?>