INeedAGig Posted March 23, 2011 Share Posted March 23, 2011 Hi there, I have been following this tutorial: http://www.freewebmasterhelp.com/tutorials/phpmysql/6 I have everything working, but I am a little confused when it comes to the "Links for Single Records" part. The following code snippet is what I am using to display the data that is in the database on the page after it is inserted, inside of a table. It is working fine, but the "edit" link just brings up a blank page, that has my edit code on it. <table border="1" bordercolor="#000000" cellspacing="2" cellpadding="10"> <tr> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Name</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">E-Mail</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Age</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Gender</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Location</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Home Phone</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Other Phone</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Best Time to Reach</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2">Referrer</font></th> <th bgcolor="#01337f"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Options</font></th> </tr> <? $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $email=mysql_result($result,$i,"email"); $age=mysql_result($result,$i,"age"); $gender=mysql_result($result,$i,"gender"); $location=mysql_result($result,$i,"location"); $homephone=mysql_result($result,$i,"homephone"); $otherphone=mysql_result($result,$i,"otherphone"); $besttime=mysql_result($result,$i,"besttime"); $referrer=mysql_result($result,$i,"referrer"); ?> <tr> <td><font class="lead_txt"><? echo $name; ?></font></td> <td><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $email; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $age; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $gender; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $location; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $homephone; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $otherphone; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $besttime; ?></font></td> <td align="center"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $referrer; ?></font></td> <td bgcolor="#01337f""><a href="db_edit.php?id=$id"><img src="edit.png" width="25" height="25" alt="Edit"></a> <a href=""><img src="delete.png" width="25" height="25" alt="Delete"></a> <a href=""><img src="email.png" width="25" height="25" alt="E-Mail"></a></td> </tr> Any ideas? Thanks in advance!! Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/ Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 Any ideas?? Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191108 Share on other sites More sharing options...
jcbones Posted March 23, 2011 Share Posted March 23, 2011 What is the code to db_edit.php? Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191114 Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 This is my code in db_edit.php <? $id=$_GET['id']; $username="myusernameishere"; $password="mypasswordishere"; $database="mydatabaseishere"; mysql_connect("localhost",$username,$password); $query="SELECT * FROM leads WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $email=mysql_result($result,$i,"email"); $age=mysql_result($result,$i,"age"); $gender=mysql_result($result,$i,"gender"); $location=mysql_result($result,$i,"location"); $homephone=mysql_result($result,$i,"homephone"); ?> <form action="db_updated.php" method="post"> <input type="hidden" name="ud_id" value="<? echo $id; ?>"> Name: <input type="text" name="ud_name" value="<? echo $name; ?>"><br> E-Mail: <input type="text" name="ud_email" value="<? echo $email; ?>"><br> Age: <input type="text" name="ud_company" value="<? echo $age; ?>"><br> Gender: <input type="text" name="ud_phone" value="<? echo $gender; ?>"><br> Location: <input type="text" name="ud_message" value="<? echo $location; ?>"><br> Home Phone: <input type="text" name="ud_referrer" value="<? echo $homephone; ?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191116 Share on other sites More sharing options...
jcbones Posted March 23, 2011 Share Posted March 23, 2011 You need to select your database: $con = mysql_connect("localhost",$username,$password); mysql_select_db($database,$con); Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191121 Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 Wow, I didn't even notice that. I went ahead and took care of that, but I am still drawing a blank page. Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191125 Share on other sites More sharing options...
jcbones Posted March 23, 2011 Share Posted March 23, 2011 Change: $result=mysql_query($query); To: $result=mysql_query($query) or die($query . ' encountered an error <br /><br /> ' . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191128 Share on other sites More sharing options...
darkfreaks Posted March 23, 2011 Share Posted March 23, 2011 your server may not have short tags ENABLED put the FULL <?php ?> tags instead of <? ?> Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191130 Share on other sites More sharing options...
jcbones Posted March 23, 2011 Share Posted March 23, 2011 already spotted the problem. Change: <a href="db_edit.php?id=$id"> To: <a href="db_edit.php?id=<?php echo $id; ?>"> First page displays, so short tags are enabled, although I do agree with darkfreaks that the long tags they should be. Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191131 Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 Okay, I reviewed the last few posts and made all suggested changes, but, I am still drawing a blank page. The only difference is in the url in the taskbar now, before it was displaying the ?id=$id but now it is displaying only ?id= and of course...still a blank page...thanks for the help so far!! Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191135 Share on other sites More sharing options...
jcbones Posted March 23, 2011 Share Posted March 23, 2011 $id is null, because you haven't set it in the first script. Therefore it isn't being passed to the second script. See, there is no ID <? $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $email=mysql_result($result,$i,"email"); $age=mysql_result($result,$i,"age"); $gender=mysql_result($result,$i,"gender"); $location=mysql_result($result,$i,"location"); $homephone=mysql_result($result,$i,"homephone"); $otherphone=mysql_result($result,$i,"otherphone"); $besttime=mysql_result($result,$i,"besttime"); $referrer=mysql_result($result,$i,"referrer"); ?> Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191138 Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 Problem solved. Just had to fetch the id from the database, which I failed to add to my code. Changed it to: <? $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $name=mysql_result($result,$i,"name"); $email=mysql_result($result,$i,"email"); $age=mysql_result($result,$i,"age"); $gender=mysql_result($result,$i,"gender"); $location=mysql_result($result,$i,"location"); $homephone=mysql_result($result,$i,"homephone"); $otherphone=mysql_result($result,$i,"otherphone"); $besttime=mysql_result($result,$i,"besttime"); $referrer=mysql_result($result,$i,"referrer"); ?> The edit is now working Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191140 Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 Okay, I have the edit and delete working, with confirmation with an echo statement. But, for some reason it is not showing up as edited or deleted on the main page, it keeps the same information that was originally there, what might the issue be with it not displaying the updated information or being deleted? Thanks! Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191150 Share on other sites More sharing options...
darkfreaks Posted March 23, 2011 Share Posted March 23, 2011 whats the code for the edit and delete statement Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191155 Share on other sites More sharing options...
INeedAGig Posted March 23, 2011 Author Share Posted March 23, 2011 Well, I resolved the delete issue, its just the edit that isn't fully working, it doesn't display the updated information. Link to comment https://forums.phpfreaks.com/topic/231446-a-little-confusedplease-help/#findComment-1191173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.