...

View Full Version : Urgent help needed on my codings



leex18
04-16-2004, 06:55 PM
I have a problem with my php coding and some how i can't retain my attributes when i submit the wrong infomation into form and the only thing it retains is the name form whereas the rest is blank. Please any help would be much appreciated.

The following codes are:

<html>
<head>
<title>Sign My GuestBook</title>
</head>

<body background="" bgcolor="9999FF" text="000000">
<h1>Feel free to sign our Guest Book</h1>

<?php

$db = mysql_connect("localhost", "", "");
mysql_select_db("guestbook", $db);




if ($submit) {

$errmsg1="";
$errmsg2="";
$errmsg3="";

$name1 .= "$name";
$location1 .= "$location";
$email1 .= "$email";
$url1 .= "$url";
$comments1 .= "$comments";

if (empty($name))
{
$errmsg1 .="<li>you have to put in a name, at least!\n";
printf($errmsg1);
}


if (empty($email) || !eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$",$email))
{
$errmsg2 .="<li>$email doesn't look like a valid email address\n";
printf($errmsg2);
}


if (!empty($url) && !eregi("^http://[A-Za-z0-9\%\?\_\:\~\/\.-]+$",$url))
{
$errmsg3 .="<li>$url doesn't look like a valid URL\n";
printf($errmsg3);
}

if ( !empty($errmsg1) || !empty($errmsg2) || !empty($errmsg3) )
{
?>
<form method="post" action="<?php echo $PHP_SELF?>">

<table border=0>

<tr>
<td align="right">Name:</td>
<td><input type= "text" name= "name" value="<?php echo "$name1" ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right">Location:</td>
<td><input type= "text" name= "location" value="<?php "$location1" ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right">E-mail:</td>
<td><input type= "text" name= "email" value="<?php "$email1" ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right">URL:</td>
<td><input type= "text" name= "url" value="<?php "$url1" ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right" valign="top">Comments:</td>
<td><textarea wrap=virtual rows=5 cols=45 name="comments" value= "<?php "$comments1" ?>" ></textarea><br /></td>
</tr>

<tr>
<td>
<input type="Submit" name="submit" value="Submit"></td>
<td><input type=reset value="Reset form">
</td>
</tr>

</table>
</form>

<?php
exit();
}





if (empty($errmsg1) && empty($errmsg2) && empty($errmsg3))
{
$sql = "INSERT INTO guestbook (name,location,email,url,comments)
VALUES ('$name','$location','$email','$url','$comments')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}

} else{
//?>

printf("" <form method="post" action="<?php echo $PHP_SELF?>">

<table border=0>

<tr>
<td align="right">Name:</td>
<td><input type= "text" name= "name" size= "40"><br /></td>
</tr>

<tr>
<td align="right">Location:</td>
<td><input type= "text" name= "location" size= "40"><br /></td>
</tr>

<tr>
<td align="right">E-mail:</td>
<td><input type= "text" name= "email" size= "40"><br /></td>
</tr>

<tr>
<td align="right">URL:</td>
<td><input type= "text" name= "url" value= "http://" size= "40"><br /></td>
</tr>

<tr>
<td align="right" valign="top">Comments:</td>
<td><textarea wrap=virtual rows=5 cols=45 name="comments" ></textarea><br /></td>
</tr>

<tr>
<td>
<input type="Submit" name="submit" value="Submit"></td>
<td><input type=reset value="Reset form">
</td>
</tr>

</table>
</form>


//<?php
}
?>


</body>
</html>

miranda
04-16-2004, 10:24 PM
You forgot to put echo into the other fileds


<tr>
<td align="right">Name:</td>
<td><input type= "text" name= "name" value="<?php echo $name1; ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right">Location:</td>
<td><input type= "text" name= "location" value="<?php echo $location1; ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right">E-mail:</td>
<td><input type= "text" name= "email" value="<?php echo $email1; ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right">URL:</td>
<td><input type= "text" name= "url" value="<?php echo $url1; ?>" size= "40"><br /></td>
</tr>

<tr>
<td align="right" valign="top">Comments:</td>
<td><textarea wrap=virtual rows=5 cols=45 name="comments" value= "<?php echo $comments1; ?>" ></textarea><br /></td>
</tr>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum