Jump to content

[SOLVED] Php update script problem


Krunk

Recommended Posts

Hi all,

I cannot understand why the form does not show up in the browser. The connection works fine

in the select and output scripts but this one is stubborn.

when I comment out the php tags, the form shows. I've commented out and rearranged  in

every way that I can think of.

When it works, the values from the table are supposed to appear in the textboxes so that when you change them the form calls updated.php to do the work.  I can post updated.php if you need me to. Thanks in advance.

 

<?

include("dbinfo.inc.php");

mysql_connect(localhost,$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;

}

?>

Link to comment
https://forums.phpfreaks.com/topic/57458-solved-php-update-script-problem/
Share on other sites

King,

Oh sorry about that. It's in the table as an auto_increment primary key.

Should I still define it? Possibly with $_POST['id']  somewhere in the script?

or $id =$_POST['id']; in the html. 

Thanks for the reply. Let me go try that.

Here is the output script (which works fine)where I've used all the post variables, but I've also used them in the update.php file and it still comes back blank.

 

<?

$user="root";

$password="farscape1";

$database="test";

 

//values taken from form.html

 

$first=$_POST['first'];

$last=$_POST['last'];

$phone=$_POST['phone'];

$mobile=$_POST['mobile'];

$fax=$_POST['fax'];

$email=$_POST['email'];

$web=$_POST['web'];

 

 

 

 

 

mysql_connect("192.168.2.6",$user,$password);

 

@mysql_select_db($database) or die( "Unable to select database");

 

$query="SELECT * FROM contacts";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

echo "<b><center>Database Output</center></b><br><br>";

 

$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");

 

echo "<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>";

 

$i++;

}

 

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.