Question : PHP/MySQL hyperlink to view specific record (on new page) from table of records from database

Hi

I am displaying all table data on my page and I want to create a link next to each record that once clicked takes you to a new page with that records details displayed, so they can be updated. I am new to PHP and also I apologise if my code is messy, however I was going to pretty it up once I got the functionality I need working.

I have got the table showing the records from the 'users' table and have created a link. However I don't think the link has been coded correctly from the users.php page to pass onto the view_user.php file (URL doesn't actually include id when hover over button) and also the code in the view_user.php page to accept the id and display the record is returning the following error message (I've tried manually putting the id into the URL and I still get the following):

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/training/public_html/view_user.php on line 39


users.php

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
<?php
[indent][/indent]mysql_connect("localhost", "training", "******") or die(mysql_error()); [indent][/indent]mysql_select_db("training_users") or die(mysql_error()); 
[indent][/indent]$data = mysql_query("SELECT * FROM users") or die(mysql_error()); 
[indent][/indent]Print "<table border cellpadding=3  >"; 
[indent][/indent]while($info = mysql_fetch_array( $data )) 
[indent][/indent]{ 
[indent][/indent][indent][/indent]Print "<tr>"; 
[indent][/indent][indent][/indent]Print "<th>Username:</th> <td>".$info['username'] . "</td> "; 
[indent][/indent][indent][/indent]Print "<th>Password:</th> <td>".$info['password'] . "</td> ";
[indent][/indent][indent][/indent]Print '<th><a href="http://89.145.90.66/~training/view_user.php?id='.$id.'"/>"Update</a></th> </tr>';
[indent][/indent] }
[indent][/indent]Print "</table>";  [code]


[b]view_user.php[/b]
[code]

 <?php
[indent][/indent]$id=$_GET['id'];
[indent][/indent]$username="training";
[indent][/indent]$password="******";
[indent][/indent]$database="training_users";
[indent][/indent]mysql_connect(localhost,$username,$password);

[indent][/indent]$query="SELECT * FROM users WHERE id = '$id'";
[indent][/indent]$result=mysql_query($query);
[indent][/indent]$num=mysql_num_rows($result);

[indent][/indent]$i=0;
[indent][/indent]while ($i < $num) 
[indent][/indent]{
[indent][/indent][indent][/indent]$first=mysql_result($result,$i,"id");
[indent][/indent][indent][/indent]$last=mysql_result($result,$i,"username");
[indent][/indent][indent][/indent]$last=mysql_result($result,$i,"password");
[indent][/indent][indent][/indent]$phone=mysql_result($result,$i,"title");
[indent][/indent][indent][/indent]$mobile=mysql_result($result,$i,"forename");
[indent][/indent][indent][/indent]$fax=mysql_result($result,$i,"surname");
[indent][/indent][indent][/indent]$email=mysql_result($result,$i,"sex");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"email");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"contact_no");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"account_manager_email");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"account_created_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"introduction_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"introduction_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"diagnosis_faculty_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"diagnosis_faculty_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"send_a_case_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"send_a_case_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"impression_tracking_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"impression_tracking_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"ipr_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"ipr_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"summary_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"summary_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"training_complete");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"training_complete_date");
[indent][/indent][indent][/indent]$web=mysql_result($result,$i,"active");
[indent][/indent]?>

<span class="Content" >
<form action="updated.php" method="post">
[indent][/indent]<input type="hidden" name="ud_id" value="<? echo $id; ?>">
[indent][/indent]Username: <input type="text" name="ud_username" value="<? echo $username; ?>"><br/>
[indent][/indent]Password: <input type="text" name="ud_password" value="<? echo $password; ?>"><br/>
[indent][/indent]Title: <input type="text" name="ud_title" value="<? echo $title; ?>"><br/>
[indent][/indent]Forename: <input type="text" name="ud_forename" value="<? echo $forename; ?>"><br/>
[indent][/indent]Surname: <input type="text" name="ud_surname" value="<? echo $surname; ?>"><br/>
[indent][/indent]Sex: <input type="text" name="ud_sex" value="<? echo $sex; ?>"><br/>
[indent][/indent]Email: <input type="text" name="ud_email" value="<? echo $email; ?>"><br/>
[indent][/indent]Contact No: <input type="text" name="ud_contact_no" value="<? echo $contact_no; ?>"><br/>
[indent][/indent]Account Manager Email: <input type="text" name="ud_account_manager_email" value="<? echo $account_manager_email; ?>"><br/>
[indent][/indent]Account Created Date: <input type="text" name="ud_account_created_date" value="<? echo $account_created_date; ?>"><br/>
[indent][/indent]Introduction Complete: <input type="text" name="ud_introduction_complete" value="<? echo $introduction_complete; ?>"><br/>
[indent][/indent]Introduction Completed Date: <input type="text" name="ud_introduction_complete_date" value="<? echo $introduction_complete_date; ?>"><br/>
[indent][/indent]Diagnostic Faculty Complete: <input type="text" name="ud_diagnosis_faculty_complete" value="<? echo $diagnosis_faculty_complete; ?>"><br/>
[indent][/indent]Diagnostic Faculty Complete Date: <input type="text" name="ud_diagnosis_faculty_complete_date" value="<? echo $diagnosis_faculty_complete_date; ?>"><br/>
[indent][/indent]Send a Case Complete: <input type="text" name="ud_send_a_case_complete" value="<? echo $send_a_case_complete; ?>"><br/>
[indent][/indent]Send a Case Complete Date: <input type="text" name="ud_send_a_case_complete_date" value="<? echo $send_a_case_complete_date; ?>"><br/>
[indent][/indent]Impression Tracking Complete: <input type="text" name="ud_impression_tracking_complete" value="<? echo $impression_tracking_complete; ?>"><br/>
[indent][/indent]Impression Tracking Complete Date: <input type="text" name="ud_impression_tracking_complete_date" value="<? echo $impression_tracking_complete_date; ?>"><br/>
[indent][/indent]IPR Complete: <input type="text" name="ud_ipr_complete" value="<? echo $ipr_complete; ?>"><br/>
[indent][/indent]IPR Complete Date: <input type="text" name="ud_ipr_complete_date" value="<? echo $ipr_complete_date; ?>"><br/>
[indent][/indent]Summary Complete: <input type="text" name="ud_summary_complete" value="<? echo $summary_complete; ?>"><br/>
[indent][/indent]Summary Complete Date: <input type="text" name="ud_summary_complete_date" value="<? echo $summary_complete_date; ?>"><br/>
[indent][/indent]Training Complete: <input type="text" name="ud_training_complete" value="<? echo $training_complete; ?>"><br/>
[indent][/indent]Training Complete Date: <input type="text" name="ud_training_complete_date" value="<? echo $training_complete_date; ?>"><br/>
[indent][/indent]Account Active: <input type="text" name="ud_active" value="<? echo $active; ?>"><br/>
[indent][/indent]<input type="Submit" value="Update">
</form> </span>

<?php
[indent][/indent]++$i;
}
  mysql_close();
?>

Answer : PHP/MySQL hyperlink to view specific record (on new page) from table of records from database

I have given this the most cursory of glances, but what instantly strikes me is that error message means you have not run your query against the database. line 23 stands out

mysql_connect(localhost,$username,$password);

Local host should be in quotes

mysql_connect('localhost', $username, $password);
Random Solutions  
 
programming4us programming4us