Jump to content

A little confused...please help!


INeedAGig

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.