I'm trying to get this script to work and it is only giving me a blank white page, can someone take a look at it and see if you can tell whats wrong with it.

<?php
// Show simple format of the records so person can choose the reference name/number
// this is then passed to the next page, for all details

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

//Connecting to MYSQL
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

//Select the database we want to use
mysql_select_db($db) or die ("Could not find database");

// Get all records in all columns from table and put it in $result.
$query = "SELECT * FROM people"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

// Get all records in all columns from table and put it in $result.
$result=mysql_query("select * from people");

/*Split records in $result by table rows and put them in $row.
Make it looping by while statement. */
while($row=mysql_fetch_assoc($result)){

// Output
echo "ID : $row['id'] <br/>";
echo "First Name : $row['fname'] <br/>";
echo "Last Name : $row['lname'] <br/>";
echo "Phone Number : $row['phone_num'] <br/>";
echo "Extension : $row['ext'] <br/>";
echo "Title : $row['title'] <br/>";
echo "Department : $row['dept'] <br/>";
echo "Fax Number : $row['fax'] <hr>";

// Add a link with a parameter(id) and it's value.
echo '<a href="phoneupdate1.php?id='.$row['id'].'">Update</a>';

}

mysql_close();
?>

I must be missing something simple but I just can't find it. This is a form to update a record in a MySQL database.

Thanks.

Recommended Answers

All 48 Replies

add this before the while():

if(mysql_num_rows($result)<1) {
echo 'No Results';
} else {
// while statement here
}

This will determine if the query is returning a result

No, still same result. Here is how I put it in:

if(mysql_num_rows($result)<1) {
echo 'No Results';
} else {
// while statement here
while($row=mysql_fetch_assoc($result)){

echo "ID : $row['id'] <br/>";
echo "First Name : $row['fname'] <br/>";
echo "Last Name : $row['lname'] <br/>";
echo "Phone Number : $row['phone_num'] <br/>";
echo "Extension : $row['ext'] <br/>";
echo "Title : $row['title'] <br/>";
echo "Department : $row['dept'] <br/>";
echo "Fax Number : $row['fax'] <hr>";

// Add a link with a parameter(id) and it's value.
echo '<a href="phoneupdate1.php?id='.$row['id'].'">Update</a>';
}

mysql_close();
?>

I thought it looked like it needed one more closing bracket (}) after the echo but that didn't improve anything either.

add error_reporting(E_ALL); to the top of the page to override any php.ini config which may be blocking errors from displaying.

Still just a blank white screen. Hmm perplexing.

Do other PHP pages work?

It looks like you are missing one more } in your code. It seems like the one you put after the last echo closes your new while statement, but your else statement is still open.

Also, in your original code you had 2 statements to execute queries.. was the 2nd for testing purposes?

Yes, all of my other scripts are running just fine.

I took a look at the }'s and agree that it looks like there needs to be one more. I played with adding one but its not making any difference. I think i did have an extra $results in there as well and took that out. Here is what I have now. I've made so many changes now that I don't even remember what I started with :)
In my while statement, some examples have shown to use fetch_row and some have fetch_assoc, I've got fetch_row in there now. :

<?php
error_reporting(E_ALL);

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

//Connecting to MYSQL
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

//Select the database we want to use
mysql_select_db($db) or die ("Could not find database");

// Get all records in all columns from table and put it in $result.
$query = "SELECT * FROM people ORDER BY fname ASC"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

// Get all records in all columns from table and put it in $result.

if (mysql_num_rows($result) > 0) {

while($row=mysql_fetch_row($result)){

echo "ID : .$row['id'] <br/>";
echo "First Name : $row['fname'] <br/>";
echo "Last Name : $row['lname'] <br/>";
echo "Phone Number : $row['phone_num'] <br/>";
echo "Extension : $row['ext'] <br/>";
echo "Title : $row['title'] <br/>";
echo "Department : $row['dept'] <br/>";
echo "Fax Number : $row['fax'] <hr>";

// Add a link with a parameter(id) and it's value.
echo '<a href="phoneupdate1.php?id='.$row['id'].'">Update</a>';
}
else { 
    // no 
    // print status message 
    echo "No rows found!";
	} 
} 
//mysql_close();
?>

This is getting frustrating. If I could get it to display something, i could work with it. The phoneupdate1.php file it is sending to displays fine but needs the info from this page.

All i want to do is be able to change data in my MySQL database if anyone has a more simple way of doing it.

Thanks for all your help guys.

A couple of problems with your current code:

mysql_fetch_row returns a row in a numerical array, you would need to use $row[0], $row[1] for displaying the data, to use what you are, you will need to use mysql_fetch_assoc to call the cells by the column names.

There is a slight problem here:

if (mysql_num_rows($result) > 0) {

while($row=mysql_fetch_row($result)){

echo "ID : .$row['id'] <br/>";
echo "First Name : $row['fname'] <br/>";
echo "Last Name : $row['lname'] <br/>";
echo "Phone Number : $row['phone_num'] <br/>";
echo "Extension : $row['ext'] <br/>";
echo "Title : $row['title'] <br/>";
echo "Department : $row['dept'] <br/>";
echo "Fax Number : $row['fax'] <hr>";

// Add a link with a parameter(id) and it's value.
echo '<a href="phoneupdate1.php?id='.$row['id'].'">Update</a>';
}
[B]else { 
    // no 
    // print status message 
    echo "No rows found!";
	} [/B]
}

You have put it as this:
If {
While {
End While }
Else {}
End If }

It should be:

if (mysql_num_rows($result) > 0) {
  while($row=mysql_fetch_row($result)){
    echo "ID : .$row['id'] <br/>";
    echo "First Name : $row['fname'] <br/>";
    echo "Last Name : $row['lname'] <br/>";
    echo "Phone Number : $row['phone_num'] <br/>";
    echo "Extension : $row['ext'] <br/>";
    echo "Title : $row['title'] <br/>";
    echo "Department : $row['dept'] <br/>";
    echo "Fax Number : $row['fax'] <hr>";
    // Add a link with a parameter(id) and it's value.
    echo '<a href="phoneupdate1.php?id='.$row['id'].'">Update</a>';
  }
} else { 
  // no 
  // print status message 
  echo "No rows found!";
}

I'm afraid I cant see any other problems with the actual code, I suggest you also check the database and make sure that the column names are correct (they are case sensitive) and that there is actually data in the table you are using.

Ok, you got it there, i changed it to $row and included the row numbers instead of the names and it is now displaying the data I want. Thank you so much.
Here is what I've got now:

<?php
error_reporting(E_ALL);
// Show simple format of the records so person can choose the reference name/number
// this is then passed to the next page, for all details

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

//Connecting to MYSQL
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

//Select the database we want to use
mysql_select_db($db) or die ("Could not find database");

// Get all records in all columns from table and put it in $result.
$query = "SELECT * FROM people ORDER BY fname ASC"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

// Get all records in all columns from table and put it in $result.

if (mysql_num_rows($result) > 0) {
  while($row=mysql_fetch_row($result)){
    echo "ID : $row[0] <br/>";
    echo "First Name : $row[1] <br/>";
    echo "Last Name : $row[2] <br/>";
    echo "Phone Number : $row[3] <br/>";
    echo "Extension : $row[4] <br/>";
    echo "Title : $row[5] <br/>";
    echo "Department : $row[6] <br/>";
    echo "Fax Number : $row[7] <hr>";
    // Add a link with a parameter(id) and it's value.
    echo '<a href="phoneupdate1.php?id='.$row[0].'">Update</a>';
  }
} else { 
  // no 
  // print status message 
  echo "No rows found!";
} 
//mysql_close();
?>

This is how it displays with the word "Update" being a link to my update form:

UpdateID : 4
First Name : Edward
Last Name : ScissorHands
Phone Number : xxx-123-456
Extension : 111
Title : Hedgetrimmer
Department : Roads & Grounds
Fax Number :

So far so good, when i click on the update link, it takes me to my update form but does not display the data. Here is what it displays:

Reference:

Last Name :<? echo $row; ?>
First Name :<? echo $row; ?>
Phone Number :<? echo $row; ?>
Extension :<? echo $row; ?>
Title :<? echo $row; ?>
Department :<? echo $row; ?>
Fax Number :<? echo $row; ?>

SUBMIT BUTTON

Here is the form it is using:

<?php
$record = $_POST['record'];
echo "Reference: $record<br><BR>";

$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($_POST['Submit']){

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

// Do update statement.
mysql_query("update phonebook set First Name='$fname', Last Name='$lname', Phone Number='$phone_num', Extension='$ext', Title='$title', Department='$dept' where id='$id'");

// Re-direct this page to select.php.
header("location:phoneupdate.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$id=$_POST['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from people where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

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

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>Last Name :
<!-- name of this text field is "Last Name" -->
<input name="lname" type="text" id="lname" value="<? echo $row['lname']; ?>"/>
<br />
First Name :
<!-- name of this text field is "fname" -->
<input name="fname" type="text" id="fname" value="<? echo $row['fname']; ?>"/>
<br />
Phone Number :
<!-- name of this text field is "phone_num" -->
<input name="phone_num" type="text" id="phone_num" value="<? echo $row['phone_num']; ?>"/>
</p>
Extension :
<!-- name of this text field is "ext" -->
<input name="ext" type="text" id="ext" value="<? echo $row['ext']; ?>"/>
<br />
Title :
<!-- name of this text field is "title" -->
<input name="title" type="text" id="title" value="<? echo $row['title']; ?>"/>
<br />
Department :
<!-- name of this text field is "dept" -->
<input name="dept" type="text" id="dept" value="<? echo $row['dept']; ?>"/>
<br />
Fax Number :
<!-- name of this text field is "fax" -->
<input name="fax" type="text" id="fax" value="<? echo $row['fax']; ?>"/>
<br />
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>

So now when i use this form does

$id=$_POST['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];

need to reflect the $row[0] instead of the as well? I'm not getting the data from the first form for some reason.

The problem there is that you have gone to a new page, all data in $row will have been lost. You either need to send the data between the pages in the URL query string or re-query the database on phoneupdate1.php, for example:
if(is_numeric($_REQUEST)) {
SELECT * FROM people WHERE id = `$id`
}

Ok, I understand what you mean, but am not sure how to do that. Can you give me a hint :)
Sorry, I'm new at this.

On the phoneupdate1.php page, update it to something similar to the following:

//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");

// 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'])) {
    mysql_query("SELECT * FROM people WHERE id = `$id`") or die(mysql_error);
    if(mysql_num_rows > 0) {
      // add the SQL data to an array using mysql_fetch_assoc or mysql_fetch_assoc
    } else {
      echo 'No Record';
    }
  }
}

// ***** This part will process when you Click on "Submit" button *****
// continue with the script

I think its not getting the data from the first page where it should be seen 'id', i'm getting :

NO RECORD
ID : <? echo $row; ?>
Last Name :<? echo $row; ?>
First Name :<? echo $row; ?>
Phone Number :<? echo $row; ?>
Extension :<? echo $row; ?>
Title :<? echo $row; ?>
Department :<? echo $row; ?>
Fax Number :<? echo $row; ?>

SUBMIT

Doesn't this mean that it is not finding any records?

Your second page should look similar to this: I have highlighted the changes on bold text, also changed the form output details.

<?php
$record = $_POST['record'];
echo "Reference: $record<br><BR>";

$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");

[B]// 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'])) {
    mysql_query("SELECT * FROM people WHERE id = `$id`") or die(mysql_error);
    if(mysql_num_rows > 0) {
      $row=mysql_fetch_row($result);
    } else {
      echo 'No Record';
    }
  }
}[/B]

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

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

// Do update statement.
mysql_query("update phonebook set First Name='$fname', Last Name='$lname', Phone Number='$phone_num', Extension='$ext', Title='$title', Department='$dept' where id='$id'");

// Re-direct this page to select.php.
header("location:phoneupdate.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$id=$_POST['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from people where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

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

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>Last Name :
<!-- name of this text field is "Last Name" -->
<input name="lname" type="text" id="lname" value="<? echo $row[2]; ?>"/>
<br />
First Name :
<!-- name of this text field is "fname" -->
<input name="fname" type="text" id="fname" value="<? echo $row[1]; ?>"/>
<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>

Arrggggg. Sorry, now I'm getting a blank white page on the second form (phoneupdate1.php).

What looks funny to me is:

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

Where it says _POST; should it be going by the row number instead of the name?
Like $_POST']; or something like that? My thinking is that we put the row number on the previous form to make it work, so does this one need to read the same way? I'm shooting in the dark here, really.

Above post edited, I missed the ; on the end on the mysql_fetch_row line which may be causing the problem

Those pesky little ;'s, i missed it too. That got rid of the white page, but i still don't have data in the form. I think i'm over my head. I Appreciate all your help.

In the SQL update query, put the field names in ``, also the names such as First Name and Last Name do not look correct, make sure that the names you use in the query are exactly what shows on the database (through phpmyadmin or similar)

The $_POST[] values are fine, they relate to the input fields on the form so that is not a problem.

Also, your SQL update query uses $id which has not been passed to the function from the form, change the form action from "<? echo $PHP_SELF; ?>" to "<? echo $PHP_SELF; ?>?id=$id" and change

// Get parameters from form.
$id=$_POST['id'];

to

// Get parameters from form.
$id=$_REQUEST['id'];

sorry, spotted another problem with my code, change

if(is_numeric($_REQUEST['id'])) {
    mysql_query("SELECT * FROM people WHERE id = `$id`") or die(mysql_error);

to

if(is_numeric($_REQUEST['id'])) {
    $id=$_REQUEST['id'];
    mysql_query("SELECT * FROM people WHERE id = `$id`") or die(mysql_error);

otherwise the script isnt being told which ID to get :)

No change. Still getting the same results from before. :(

Whats the code you are actually using at the moment.

If i replace all the ' with ` , then i get a MySql error. I change them back and I get a form without good data.

Whats the code you are actually using at the moment.

My current code:

<?php
error_reporting(E_ALL);
$record = $_POST['record'];
echo "Reference: $record<br><BR>";

$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");

// 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'];
    mysql_query("SELECT * FROM people WHERE id = '$id'") or die(mysql_error);
    if(mysql_num_rows > 0) {
      $row=mysql_fetch_row($result);
    } else {
      echo 'No Record';
    }
  }
}

// ***** This part will process when you Click on "Submit" button *****
// Check, if you clicked "Submit" button
if($_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'];

// Do update statement.
mysql_query("update phonebook set First Name='$fname', Last Name='$lname', Phone Number='$phone_num', Extension='$ext', Title='$title', Department='$dept' where id='$id'");

// Re-direct this page to select.php.
header("location:phoneupdate.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$id=$_POST['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from people where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

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

<!-- END OF PHP CODES AND START HTML TAGS -->

<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $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>

this part of your code is incorrect, you don't have any POST data from the previous page so $_POST will return a null value, remove this:

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php
$id=$_POST['id'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from people where id='$id'");

// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);

as it is basically duplicating this part (move this to below the comment stating the end of the update if you wish):

// 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'];
    mysql_query("SELECT * FROM people WHERE id = '$id'") or die(mysql_error);
    if(mysql_num_rows > 0) {
      $row=mysql_fetch_row($result);
    } else {
      echo 'No Record';
    }
  }
}

Also, can you list the column names from the database.

Here is my table structure from mysql:

-- Table structure for table `people`
--

CREATE TABLE `people` (
`id` int(11) NOT NULL auto_increment,
`fname` varchar(30) NOT NULL default '',
`lname` varchar(50) NOT NULL default '',
`phone_num` varchar(12) NOT NULL default '',
`ext` varchar(3) NOT NULL default '',
`title` varchar(255) NOT NULL default '',
`dept` varchar(255) NOT NULL default '',
`fax` varchar(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
and here is the code after the changes you just told me to change.

<?php
error_reporting(E_ALL);
$record = $_POST['record'];
echo "Reference: $record<br><BR>";

$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($_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 phonebook set First Name='$fname', Last Name='$lname', Phone Number='$phone_num', Extension='$ext', Title='$title', Department='$dept', Fax='$fax' where id='$id'");

// 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'];
    mysql_query("SELECT * FROM people WHERE id = '$id'") or die(mysql_error);
    if(mysql_num_rows > 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>
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action="<? echo $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>

Sorry this is so messed up man!

change

mysql_query("update phonebook set First Name='$fname', Last Name='$lname', Phone Number='$phone_num', Extension='$ext', Title='$title', Department='$dept', Fax='$fax' where id='$id'");

to

mysql_query("update phonebook set `fname`='$fname', `lname`='$lname', `phone_num`='$phone_num', `ext`='$ext', `title`='$title', `dept`='$dept', `fax`='$fax' where `id`='$id'");

No change. I'll let you ponder this for a while, got to head home from work, i'll look at it some more when I get there. thank you for all your help so far, i really appreciate it.

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
[B]mysql_[/B]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
[B]if(isset($_POST['Submit'])){[/B]

// 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 [B]people[/B] SET `fname`='$fname', `lname`='$lname', `phone_num`='$phone_num', `ext`='$ext', `title`='$title', `dept`='$dept', `fax`='$fax' where `id`='$id'")[B]or die(mysql_error());[/B]

// 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);
    i[B]f(mysql_num_rows($result) > 0) {[/B]
      $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>
[B]Reference: <?=$id?><BR>[/B]
<!-- set this form to POST method and target this form to itself ($PHP_SELF;)-->
<form id="form1" name="form1" method="post" action=[B]"<?=$_SERVER['PHP_SELF']?>?id=<?=$id?>">[/B]
<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>

Still no change. I really don't understand. I've got 5 forms that access this data. 1 to view the phonebook, 1 to delete a record, 1 to insert a new record, and 2 we're working on to edit a record. All of them work great except for the 2 that edit. So I know the data is there and it is accessable. I just don't understand what is different with this one on my system, especially if you've got it working on yours. Here is what it looks like when I run the script.

Reference:

First Name : <? echo $row[1]; ?>
Last Name : <? echo $row[2]; ?>
Phone Number : <? echo $row[3]; ?>

Extension : <? echo $row[4]; ?>
Title : <? echo $row[5]; ?>
Department : <? echo $row[6]; ?>
Fax Number : <? echo $row[7]; ?>

SUBMIT

I can type in the box but get a page error when submit is pressed. I'm at a loss. Any ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.