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 329,722 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,578 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
Views: 561 | Replies: 48 | Solved
Reply
Join Date: May 2008
Location: UK
Posts: 49
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
xan's Avatar
xan xan is offline Offline
Light Poster

Re: a little help

  #11  
4 Days Ago
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['id'])) {
SELECT * FROM people WHERE id = `$id`
}
Last edited by xan : 4 Days Ago at 2:55 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 60
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
rickarro rickarro is offline Offline
Junior Poster in Training

Re: a little help

  #12  
4 Days Ago
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.
Reply With Quote  
Join Date: May 2008
Location: UK
Posts: 49
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
xan's Avatar
xan xan is offline Offline
Light Poster

Re: a little help

  #13  
4 Days Ago
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
Last edited by xan : 4 Days Ago at 3:18 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 60
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
rickarro rickarro is offline Offline
Junior Poster in Training

Re: a little help

  #14  
4 Days Ago
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['id']; ?>
Last Name :<? echo $row['lname']; ?>
First Name :<? echo $row['fname']; ?>
Phone Number :<? echo $row['phone_num']; ?>
Extension :<? echo $row['ext']; ?>
Title :<? echo $row['title']; ?>
Department :<? echo $row['dept']; ?>
Fax Number :<? echo $row['fax']; ?>

SUBMIT

Doesn't this mean that it is not finding any records?
Reply With Quote  
Join Date: May 2008
Location: UK
Posts: 49
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
xan's Avatar
xan xan is offline Offline
Light Poster

Re: a little help

  #15  
4 Days Ago
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");

// 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';
    }
  }
}

// ***** 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>
Last edited by xan : 4 Days Ago at 4:19 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 60
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
rickarro rickarro is offline Offline
Junior Poster in Training

Re: a little help

  #16  
4 Days Ago
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['id']; should it be going by the row number instead of the name?
Like $_POST['$row[0]']; 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.
Reply With Quote  
Join Date: May 2008
Location: UK
Posts: 49
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
xan's Avatar
xan xan is offline Offline
Light Poster

Re: a little help

  #17  
4 Days Ago
Above post edited, I missed the ; on the end on the mysql_fetch_row line which may be causing the problem
Last edited by xan : 4 Days Ago at 4:21 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 60
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
rickarro rickarro is offline Offline
Junior Poster in Training

Re: a little help

  #18  
4 Days Ago
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.
Reply With Quote  
Join Date: May 2008
Location: UK
Posts: 49
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
xan's Avatar
xan xan is offline Offline
Light Poster

Re: a little help

  #19  
4 Days Ago
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'];
Reply With Quote  
Join Date: May 2008
Location: UK
Posts: 49
Reputation: xan is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
xan's Avatar
xan xan is offline Offline
Light Poster

Re: a little help

  #20  
4 Days Ago
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
Last edited by xan : 4 Days Ago at 4:29 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC