Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MrSugar

macrumors 6502a
Original poster
Hi guys,

I have been doing a contact list tutorial for php and mysql. I already use php on my site but I was excited to get more into MySQL (which is really awesome btw).

So I have created the page to add a contact:

http://www.fluidvision.net/php/connect.html

a place to see the added contacts:

http://www.fluidvision.net/php/pull.php

and now I am working on a way to update them,

http://www.fluidvision.net/php/update.php
you notice it displays nothing, that's the problem.

check page 7 of that tutorial up above to see what I am trying to do.

My problem is, I can't see the html of my update form inside the update.php file.

Let me show you:

PHP:
<?

$username="-----";
$password="-----";
$database="---------";

mysql_connect("127.0.0.1",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query=" SELECT * FROM contacts WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");

?>


<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo "$id"; ?>">
First Name: <input type="text" name="ud_first" value="<? echo "$first"?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo "$last"?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<? echo "$phone"?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<? echo "$mobile"?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<? echo "$fax"?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<? echo "$email"?>"><br>
Web Address: <input type="text" name="ud_web" value="<? echo "$web"?>"><br>
<input type="Submit" value="Update">
</form>

<?

++$i;
}

?>

The html for my form can't be seen by the browser. And I have even uploaded the guys official tutorial script

http://www.fluidvision.net/php/official/update.php

and his can't be seen either.

So, my question is, how can I get my update form to work?

Any help is SOOO greatly appreciated.
 
Try this in your page:
PHP:
<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>
<input type="Submit" value="Update">
</form>
 
edesignuk said:
Try this in your page:
PHP:
<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>
E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>
<input type="Submit" value="Update">
</form>


Did it, didn't work 🙁. I actually had tried that earlier thinking the " 's could be the problem. Doesn't seem to go though. I am pretty confused, I wonder if it could be something with my host and the php setup?


http://fluidvision.net/php/update.php
 
It's confusing to read...it could be more simple...at least for my eyes...try this instead...does the exact same thing...I'm assuming the name of your table columns and I'm assuming that the form is using POST.

PHP:
<?php 
$username="-----"; 
$password="-----"; 
$database="---------"; 

mysql_connect("127.0.0.1",$username,$password); 
@mysql_select_db($database) or die ("Unable to select database"); 

$query = mysql_query ("SELECT * FROM contacts WHERE id='$id'");
$row = mysql_fetch_array($query);
?> 


<form action="updated.php" method="post"> 
<input type="hidden" name="ud_id" value="<?php echo $row['id']; ?>"> 
First Name: <input type="text" name="ud_first" value="<?php echo $row['first']; ?>"><br> 
Last Name: <input type="text" name="ud_last" value="<?php echo $row['last']; ?>"><br> 
Phone Number: <input type="text" name="ud_phone" value="<?php echo $row['phone']; ?>"><br> 
Mobile Number: <input type="text" name="ud_mobile" value="<?php echo $row['mobile']; ?>"><br> 
Fax Number: <input type="text" name="ud_fax" value="<?php echo $row['fax']; ?>"><br> 
E-mail Address: <input type="text" name="ud_email" value="<?php echo $row['email']; ?>"><br> 
Web Address: <input type="text" name="ud_web" value="<?php echo $row['web']; ?>"><br> 
<input type="Submit" value="Update"> 
</form>
 
jvaska said:
It's confusing to read...it could be more simple...at least for my eyes...try this instead...does the exact same thing...I'm assuming the name of your table columns and I'm assuming that the form is using POST.

PHP:
<?php 
$username="-----"; 
$password="-----"; 
$database="---------"; 

mysql_connect("127.0.0.1",$username,$password); 
@mysql_select_db($database) or die ("Unable to select database"); 

$query = mysql_query ("SELECT * FROM contacts WHERE id='$id'");
$row = mysql_fetch_array($query);
?> 


<form action="updated.php" method="post"> 
<input type="hidden" name="ud_id" value="<?php echo $row['id']; ?>"> 
First Name: <input type="text" name="ud_first" value="<?php echo $row['first']; ?>"><br> 
Last Name: <input type="text" name="ud_last" value="<?php echo $row['last']; ?>"><br> 
Phone Number: <input type="text" name="ud_phone" value="<?php echo $row['phone']; ?>"><br> 
Mobile Number: <input type="text" name="ud_mobile" value="<?php echo $row['mobile']; ?>"><br> 
Fax Number: <input type="text" name="ud_fax" value="<?php echo $row['fax']; ?>"><br> 
E-mail Address: <input type="text" name="ud_email" value="<?php echo $row['email']; ?>"><br> 
Web Address: <input type="text" name="ud_web" value="<?php echo $row['web']; ?>"><br> 
<input type="Submit" value="Update"> 
</form>

Okay, first off thanks for the help from everyone. I figured there was probably an easier way to do it.

But now that I look at it I am confused as to how this update script is going to work anyway, because how is the script going to know which contact/id to update in the db?

By the way I have placed your code into the update.php file and uploaded it. Now the HTML can be seen but those echo commands still aren't coming through. And yes, the name of the db is contacts and the table names you used were correct.
 
Yes, they do come up...I checked...

http://fluidvision.net/php/update.php?id=1

Actually, I'm assuming you realize that you need the correct link for each record...on your pull page....like...

PHP:
<a href='update.php?id=12'>Edit the record</a>

It would be something as simple as adding it to the loop...

PHP:
<a href='update.php?id=<?php echo $id ?>'>Edit the record</a>
 
jvaska said:
Yes, they do come up...I checked...

http://fluidvision.net/php/update.php?id=1

Actually, I'm assuming you realize that you need the correct link for each record...on your pull page....like...

PHP:
<a href='update.php?id=12'>Edit the record</a>

It would be something as simple as adding it to the loop...

PHP:
<a href='update.php?id=<?php echo $id ?>'>Edit the record</a>


BING, okay, that clicked. Sorry, I am way new to this but I see.

So when I have for instance an update page, it would be best to have the display of all the contact info. Then have a link to the update script for each specific contact right next to their name.

Okay, thanks sooo much. Wow, really awesome, I am already seeing ways I could impliment this type of system into my site.
 
MrSugar said:
So when I have for instance an update page, it would be best to have the display of all the contact info. Then have a link to the update script for each specific contact right next to their name.

Yeah...assuming it's for you...if it's public you'll want to come up with something else...like a private page...all of this stuff should have some authentication too...

Name
Addess
Email
Etc.
[Edit]
 
jvaska said:
Yeah...assuming it's for you...if it's public you'll want to come up with something else...like a private page...all of this stuff should have some authentication too...

Name
Addess
Email
Etc.
[Edit]

right, I gottcha, I was refering to a personal update page just for me.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.