User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,160 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,425 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

a little help

Join Date: May 2008
Location: UK
Posts: 51
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 10
xan's Avatar
xan xan is offline Offline
Junior Poster in Training

Re: a little help

  #29  
May 8th, 2008
Right, I think this will sort it, I have run the script on my pc with no errors.

I have made a couple of changes to the script, these are in bold.

<?php
error_reporting(E_ALL);

$host = "localhost";
$user = "xxx";
$pass = "xxx";
$db = "phonebook";

//Connecting to MYSQL
mysql_connect("$host","$user","$pass");
//Select the database we want to use
mysql_select_db($db) or die("Could not find database");


// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if(isset($_POST['Submit'])){

// Get parameters from form.
$id=$_REQUEST['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$phone_num=$_POST['phone_num'];
$ext=$_POST['ext'];
$title=$_POST['title'];
$dept=$_POST['dept'];
$fax=$_POST['fax'];

// Do update statement.
mysql_query("UPDATE people SET `fname`='$fname', `lname`='$lname', `phone_num`='$phone_num', `ext`='$ext', `title`='$title', `dept`='$dept', `fax`='$fax' where `id`='$id'")or die(mysql_error());

// Re-direct this page to select.php.
header("location:phoneupdate.php");
exit;
}
// Check to see if the link from the previous page was clicked
if(isset($_REQUEST['id'])) {
  // Check that the id value in the URL is a number
  if(is_numeric($_REQUEST['id'])) {
    $id=$_REQUEST['id'];
    $result=mysql_query("SELECT * FROM people WHERE id = '$id'") or die(mysql_error);
    if(mysql_num_rows($result) > 0) {
      $row=mysql_fetch_row($result);
    } else {
      echo 'No Record';
    }
  }
}
// ************* End update part *************

// Close database connection.
mysql_close();
?>

<!-- END OF PHP CODES AND START HTML TAGS -->
<html>
<body>
Reference: <?=$id?><BR>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>?id=<?=$id?>">
<p>First Name :
<!-- name of this text field is "fname" -->
<input name="fname" type="text" id="fname" value="<? echo $row[1]; ?>"/>
<br />
Last Name :
<!-- name of this text field is "lname" -->
<input name="lname" type="text" id="lname" value="<? echo $row[2]; ?>"/>
<br />
Phone Number :
<!-- name of this text field is "phone_num" -->
<input name="phone_num" type="text" id="phone_num" value="<? echo $row[3]; ?>"/>
</p>
Extension :
<!-- name of this text field is "ext" -->
<input name="ext" type="text" id="ext" value="<? echo $row[4]; ?>"/>
<br />
Title :
<!-- name of this text field is "title" -->
<input name="title" type="text" id="title" value="<? echo $row[5]; ?>"/>
<br />
Department :
<!-- name of this text field is "dept" -->
<input name="dept" type="text" id="dept" value="<? echo $row[6]; ?>"/>
<br />
Fax Number :
<!-- name of this text field is "fax" -->
<input name="fax" type="text" id="fax" value="<? echo $row[7]; ?>"/>
<br />
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
Last edited by xan : May 8th, 2008 at 6:52 pm.
Reply With Quote  
All times are GMT -4. The time now is 3:42 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC