Advertisement

07.28.2006 at 05:31AM PDT, ID: 21935267
[x]
Attachment Details

Having Trouble UPDATING a MYSQL DB field  (UPDATE  SET command)

Asked by NJComputerNetworks in PHP and Databases

Tags: , , , ,

I'm a noob at PHP, MYSQL, and PHPADMIN..  But I am learning a lot.  So far, I have successfully installed all of the componts on one test server.  I can display data from the database using PHP scripts without any problem.  Now, I would like to try to add the ability for editing data in the database through a web page.  I have a basic script that I was wondering if you experts could help me troubleshoot... Sorry for the long post, but I wanted to give all the information I could.......

***************************************************************************
UpdateScheduleForm.html
~~~~This is the start of my project...  Here, a user will enter a server name in the form.  The server name will be saved in a variable and be used later to present some of the information related to the server name in the MYSQL database.  Note:  This part works fine.
***************************************************************************
<form action="updateSchedule.php" method="post">
You are about to alter the Deployment Schedule. Enter the Server Name for which you require the deployment schedule change: <input type="text" name="svrinput" value= ServerName><br>
<input type="Submit">
</form>


***********************************************************************************
updateschedule.php
~~~~ After the user enters a servername, this script will present related server information from the database.  In addition, another form will be presented for the three fields that they can modify: deployment schedule, Name, and Change Notes.  Note: This part works fine...
***********************************************************************************
<?
$svrinput=$_POST['svrinput'];

include("dbinfo.inc.php");
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Error!  Unable to select $database database from server $server");
$query="SELECT * FROM allserverdata WHERE DeviceName='$svrinput'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();


echo "<b><center>All Hosted Servers Database Output</center></b><br><br>";

/* Setting the Output Table format */

?>
<table border="5" cellspacing="8" cellpadding="8">
<tr>
<th><font face="Arial, Helvetica, sans-serif">DeviceName</font></th>
<th><font face="Arial, Helvetica, sans-serif">Deployment Date</font></th>
<th><font face="Arial, Helvetica, sans-serif">Name of Person Requesting Change</font></th>
<th><font face="Arial, Helvetica, sans-serif">Deployment Change Notes</font></th>
<th><font face="Arial, Helvetica, sans-serif">IP Address</font></th>
<th><font face="Arial, Helvetica, sans-serif">Business Unit</font></th>
<th><font face="Arial, Helvetica, sans-serif">Primary Application Contact</font></th>
<th><font face="Arial, Helvetica, sans-serif">Secondary Application Contact</font></th>
<th><font face="Arial, Helvetica, sans-serif">Primary Technical Contact</font></th>
<th><font face="Arial, Helvetica, sans-serif">Secondary Technical Contact</font></th>
<th><font face="Arial, Helvetica, sans-serif">Product Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Application</font></th>
<th><font face="Arial, Helvetica, sans-serif">Reboot Instructions</font></th>
<th><font face="Arial, Helvetica, sans-serif">Grid Location</font></th>
<th><font face="Arial, Helvetica, sans-serif">Installed Site Code</font></th>
<th><font face="Arial, Helvetica, sans-serif">Site</font></th>
</tr>





<?

/* Gathering data from MYSQL database */
$i=0;
while ($i < $num) {
$DeviceName=mysql_result($result,$i,"DeviceName");
$DeploymentDate1=mysql_result($result,$i,"Deployment Date 1");
$ChangeRequestor=mysql_result($result,$i,"Change Requestor");
$ChangeNotes=mysql_result($result,$i,"Change Notes");
$IPAddress=mysql_result($result,$i,"IPAddress");
$BU=mysql_result($result,$i,"BU");
$PrimaryAppContact=mysql_result($result,$i,"Primary App Contact");
$SecondaryAppContact=mysql_result($result,$i,"Secondary App Contact");
$PrimaryTechnicalContact=mysql_result($result,$i,"Primary Technical Contact");
$SecondaryTechnicalContact=mysql_result($result,$i,"Secondary Technical Contact");
$ProductName=mysql_result($result,$i,"Product Name");
$Application=mysql_result($result,$i,"Application");
$RebootInstructions=mysql_result($result,$i,"Reboot Instructions");
$GridLocation=mysql_result($result,$i,"Grid Location");
$InstalledSiteCode=mysql_result($result,$i,"Installed Site Code");
$Site=mysql_result($result,$i,"Site");


/* Printing data to output table */  
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$DeviceName"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$DeploymentDate1"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$ChangeRequestor"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$ChangeNotes"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$IPAddress"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$BU"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$PrimaryAppContact"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$SecondaryAppContact"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$PrimaryTechnicalContact"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$SecondaryTechnicalContact"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$ProductName"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Application"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$RebootInstructions"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$GridLocation"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$InstalledSiteCode"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$Site"; ?></font></td>
</tr>

<?
++$i;
}
echo "</table>";



?>

<form action="UpScheduleupdated.php" method="post">
Enter the Server NAme for the Schedule You Want to Modify: <input type="text" name="ud_svrinput" value="<? echo "$svrinput"?>"><br>
Enter New Deployment Day: <input type="text" name="ud_DeploymentDate1" value="<? echo "$DeploymentDate1"?>"><br>
Enter Your First and Last Name: <input type="text" name="ud_ChangeRequestor"><br>
Enter Reason for Schedule Day Change: <input type="text" name="ud_ChangeNotes"><br>
<input type="Submit" value="Update">
</form>


***************************************************************************
UpScheduleupdated.php
~~~~  This script actually tries to update the database.  I am only trying to modify one field at the moment for a test.  My database name is TEST, my table is called allserverdata and the field is called BU.  However, the database never gets modified and there is no error presented.  Note:  This part of the script is NOT working....and I don't know why????
***************************************************************************

<?
$ud_DeploymentDate1=$_POST['ud_DeploymentDate1'];
$ud_ChangeRequestor=$_POST['ud_ChangeRequestor'];
$ud_ChangeNotes=$_POST['ud_ChangeNotes'];
$ud_svrinput=$_POST['ud_svrinput'];


print($ud_DeploymentDate1);  <-- just printing these out so, I know I am passing them from the form correctly

print($ud_ChangeRequestor);  <-- just printing these out so, I know I am passing them from the form correctly

print($ud_ChangeNotes);  <-- just printing these out so, I know I am passing them from the form correctly I AM ONLY REALLY USING THIS VAR AT THE MOMENT

print($ud_svrinput);  <-- just printing these out so, I know I am passing them from the form correctly


include("dbinfo.inc.php");
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Error!  Unable to select $database database from server $server");


$query="UPDATE allserverdata SET BU='$ud_ChangeNotes', WHERE ID=1065";
mysql_query($query);
echo "Record Updated";
mysql_close();

?>

******************************************************************************
dbinfo.inc.php
~~~ This is just my connection to the database as ROOT.
******************************************************************************
<?
$username="root";
$password="Password123";
$database="test";
$server="localhost";
?>

Any help would be greatly appreciated....Start Free Trial
[+][-]07.28.2006 at 05:32AM PDT, ID: 17200483

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: php, set, field, having, mysql
Sign Up Now!
Solution Provided By: Roonaan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.28.2006 at 05:36AM PDT, ID: 17200532

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 05:42AM PDT, ID: 17200583

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 05:43AM PDT, ID: 17200603

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 06:53AM PDT, ID: 17201164

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.28.2006 at 07:02AM PDT, ID: 17201245

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32