Jump to content

[SOLVED] cant get this to work.. probably something simple..


clown[NOR]

Recommended Posts

why wont this print out the form? i don't get any errors, just a blank page

 

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

 

i've also tried echo... but nothing... I must be missing something really simple here..

thanks... not it showed this message:

Notice: Use of undefined constant localhost - assumed 'localhost' in F:\root\edit.php on line 12

 

$id = $_GET['id'];
$user = "root";
$password = "*******";
$database = "adressebok";

mysql_connect(localhost,$user,$password); // This is line 12
@mysql_select_db($database) or die ("Unable to select database");

$query = "SELECT * FROM contacts WHERE id='$id'";

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

 

Try that

this i the whole code

<html>
  <head><title>Edit Contact</title></head>
<body>
<?php
error_reporting(E_ALL);

$id = $_GET['id'];
$user = "root";
$password = "*****";
$database = "adressebok";

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

$query = "SELECT * FROM contacts WHERE id='$id'";

$result = mysql_query($query);
$num = mysql_numrows($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");

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

	$i++;
}
?>
</body>
</html>

You should always check mysql operations for success or failure and don't use the "@" operator when developing code. It will suppress error messages.

<?php
$query = "SELECT * FROM contacts WHERE id='$id'";
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error());
?>

 

You can make your coding task easier by using one of the mysql_fetch functions instead of mysql_result. I prefer the mysql_fetch_assoc() function. Also, you don't have to call mysql_close().

 

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

 

You will notice that I made a few other changes to your code...

 

Ken

 

Sorry the "$rw_" in this line:

<?php
echo '<input type="hidden" name="ud_id" value="' . $_rw['id'] . '">';
?>

should be "$rw"

<?php
echo '<input type="hidden" name="ud_id" value="' . $rw['id'] . '">';
?>

 

The "$rw" array is set in the "while" statement

<?php
while ($rw = mysql_fetch_assoc($result)) {
?>

the mysql_fetch_assoc() function returns an associative array containing all the fields in the row just retrieved.

 

Ken

i'm sorry to report this, but still the same result... :(

 

<?php
error_reporting(E_ALL);

$id = $_GET['id'];
$user = "root";
$password = "*****";
$database = "adressebok";

mysql_connect("localhost", $user, $password);
mysql_select_db($database) or die ("Unable to select database" . mysql_error());

$query = "SELECT * FROM contacts WHERE id='$id'";
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error());

$num = mysql_numrows($result);

mysql_close();

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

?>

 

and there's no error message(s)

Are you sure you have something in the database that will be retrieved?

 

Change your code to:

<?php
$num = mysql_num_rows($result);
        if ($num > 0) {
  echo '<form action=updated.php method=post>';
	  while ($rw = mysql_fetch_assoc($result)) {
	echo '<input type="hidden" name="ud_id" value="' . $rw['id'] . '">';
	echo 'First Name: <input type="text" name="ud_first" value="' . $rw['first'] . '"><br>';
	echo 'Last Name: <input type="text" name="ud_last" value="' . $rw['last'] . '"><br>';
	echo 'Phone Number: <input type="text" name="ud_phone" value="' . $rw['phone'] . '"><br>';
	echo 'Mobile Number: <input type="text" name="ud_mobile" value="' . $rw['mobile'] . '"><br>';
	echo 'Fax Number: <input type="text" name="ud_fax" value="' . $rw['fax'] . '"><br>';
	echo 'E-mail Address: <input type="text" name="ud_email" value="' . $rw['email'] . '"><br>';
	echo 'Web Address: <input type="text" name="ud_web" value="' . $rw['web'] . '"><br>';
  }
echo '<input type="submit" value="Update">';
echo '</form>';
        }
        else
            echo 'No records selected for id = ' . $id . '<br>';
?>

 

Ken

oh my god!! I feel so super stupid now! how could i know that even when i fysicaly went into the database and deleted the contacts then made 3 new trough the add contact form the ID continued counting.. haha.. the id was 3-4-5 not 0-1-2 as i thought it was :)  :-[

 

thanks for all the help.. it's working fine now =)

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.