Jump to content

Help with script please


wgoldschagg

Recommended Posts

I am trying to create an update database script that loads the existing data and allows the user to update only the fields the user needs to update.

 

I have created 2 files for this purpose (preupdate.php which recalls the existing data and update.php which does the actual apdate). Sofar I can't seem to get the preupdate file to post the changed data - it simply posts whatever it recalled from the database.  Please help.

 

Here is my preupdate.php code:

 

 

<?php 

       

include 'src.php';

 

$id = $_POST['ClientNo'];

 

$result = mysql_query("select * from client where $id like ClientNo"); 

 

echo "<Center><table width=\"60%\" border=\"2\" cellpadding=\"2\" cellspacing=\"0\">\n";

echo "<td>\n";   

echo "<Center><table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";

echo "<tr><td colspan=\"2\"><center><b><Font Size=\"6\"><b><u>Update Details</u></b></font></center></td></tr>\n";

 

$row = mysql_fetch_array($result); 

 

   

    echo "<form name=\"form1\" method=\"post\" action=\"update.php\" style=\"padding:5px;\">\n";

    echo "<tr><td style=\"padding:5px;\">Client Number: </td><td><input type=\"hidden\" name=\"ClientNo\" id=\"ClientNo\" value=\"$row[ClientNo]\"></td></tr>\n"; 

    echo "<tr><td style=\"padding:5px;\">Name: </td><td><input type=\"text\" name=\"Name\" id=\"Name\" value=\"$row[Name]\"></td></tr>\n";

    echo "<tr><td style=\"padding:5px;\">Surname: </td><td><input type=\"text\" name=\"SName\" id=\"SName\" value=\"$row[sName]\"></td></tr>\n";

    echo "<tr><td style=\"padding:5px;\">I.D. Number: </td><td><input type=\"text\" name=\"IDNo\" id=\"IDNo\" value=\"$row[iDNo]\"></td></tr>\n"; 

    echo "<tr><td style=\"padding:5px;\">Telephone Number: </td><td><input type=\"text\" name=\"Tel\" id=\"Tel\" value=\"$row[Tel]\"></td></tr>\n";

    echo "<tr><td style=\"padding:5px;\">Fax Number: </td><td><input type=\"text\" name=\"Fax\" id=\"Fax\" value=\"$row[Fax]\"></td></tr>\n";

    echo "<tr><td style=\"padding:5px;\">Email Adress: </td><td><input type=\"text\" name=\"Email\" id=\"Email\" value=\"$row\"></td></tr>\n";

       

    echo "<tr><td colspan=\"2\"><center><input type=\"submit\" name=\"submit\" value=\"Update Details\"></center></td></tr>\n";   

?>

Link to comment
Share on other sites

This file(preupdate.php) is meant to recall the existing data and display it in a textfield so the user can edit it.  The preupdate.php file currently doesn't post any data that has been changed. It Simply posts what it recalled in the first place. my 2nd file (update.php) code looks like this:

 

 

<?php

 

if ($_POST['Submit'] == 'Update Details')

{

  if (strlen($_POST['IDNo']) < 16)

  {

    die ("Invalid I.D. Number. Please enter a valid I.D. Number.");

 

}

 

include 'src.php';

 

        $ClientNo=$_Post['ClientNo'];

        $Name=$_Post['Name'];

        $SName=$_Post['SName'];

        $IDNo=$_Post['IDNo'];

        $Tel=$_Post['Tel'];

        $Fax=$_Post['Fax'];

        $Email=$_Post['Email'];

        $AgreeDate=$_Post['AgreeDate'];

        $UI4In=$_Post['UI4In'];

        $UI4Date=$_Post['UI4DateI'];

        $UI19In=$_Post['UI19In'];

        $UI19Date=$_Post['UI19Date'];

        $UI27In=$_Post['UI27In'];

        $UI27Date=$_Post['UI27Date'];

        $UI23In=$_Post['UI23In'];

        $UI23Date=$_Post['UI23Date'];

        $UI28In=$_Post['UI28In'];

        $UI28Date=$_Post['UI28Date'];

        $CopyID=$_Post['CopyID'];

        $CopyIDDate=$_Post['CopyIDDate'];

        $CopyMar=$_Post['CopyMar'];

        $CopyMarDate=$_Post['CopyMarDate'];

        $CopyDev=$_Post['CopyDev'];

        $CopyDevDate=$_Post['CopyDevDate'];

               

        mysql_query("UPDATE client set Name = '$Name', SName = '$SName', IDNo = '$IDNo', Tel = '$Tel', Fax = '$Fax', Email = '$Email', AgreeDate = $AgreeDate', UI4In = '$UI4In', UI4Date = '$UI4Date', UI19In = '$UI19In', UI19Date = '$UI19Date',  UI27In = '$UI27In', UI27Date = '$UI27Date', UI23In = '$UI23In', UI23Date = '$UI23Date', UI28In = '$UI28In', UI28Date = '$UI28Date', CopyID = '$CopyID', CopyIDDate = '$CopyIDDate', CopyMar = '$CopyMar', CopyMarDate = '$CopyMarDate', CopyDev = '$CopyDev', CopyDevDate = '$CopyDevDate' Where ClientNo = '$ClientNo'") or die(mysql_error());

        echo ("Details Successfully Updated");

exit;

}

?>

Link to comment
Share on other sites

No errors. It goes to update.php, but the the update.php loads a blank page.

 

I think i need a way to display the data recalled in the textfield without actually setting it as a value - I may be wrong.

 

For example:

 

my current code says:

 

echo "<tr><td style=\"padding:5px;\">Name: </td><td><input type=\"text\" name=\"Name\" id=\"Name\" value=\"$row[Name]\"></td></tr>\n";

 

 

I think the form posts this value regardless of whether it was edit or not.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.