Greeting,
I hope this is the right place for this. If not please guide me.
I am having problem with my "Form". Code is below. I want to generate an
error message if the required fields are not filled. If they are filled
then I want to add them to the database and display the form again to
make another entry. Database part is working fine. But when it exist
with an error for blank entry, it wipe out all the values the user has
entered, how can I save user input in case user does not have to enter
all the values again.
Thank you for help.
<?php
include "db.php";
echo "Title is " . $_POST['title'];
//logincheck();
session_start();
echo "You are logged in $user";
if (isset($message))
{
echo "<font color=\"red\">{$message} </font><br>";
echo "You are logged in $user";
?>
<html>
<table border=0 width=80% height=100% align=center border=0
cellspacing=0 cellpadding=0
STYLE="color: <? echo($fontcol); ?>;" bgcolor=<? echo($BOXCOLOR); ?>>
<tr width=100% background="./images/bg.jpg">
<td width=100% background="./images/bg.jpg" align="center">
<div style="border: 2px groove #888888; border-left: 0px; border-right:
0px;"><br>
<br><br></div>
</td></tr>
<tr width=100% >
<td width=100% align="center">
<div align="center">
<form name=sds action="<?php echo $_SERVER['PHP_SELF']; ?>"
METHOD="POST" onfiltered="return check()">
<table cellpadding=4 cellspacing=0 border=0>
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>Title: *
</i></font></td><td><input type="text" name="title" size=40
value="<?=$_POST['title']?>" ></td></tr>
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>Location :
</i></font></td><td><input type="text" name="location" size=40 ></td></tr>
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>City: *
</i></font></td><td><input type="text" name="City" size=15></td></tr>
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>Email: *
</i></font></td><td><input type="text" name="Email" size=40 value="<?
echo($user); ?>"></td></tr>
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>Phone: *
</i></font></td><td><input type="text" name="Phone" size=40></td></tr>
<tr><td><font color=<? echo($FONTCOLOR); ?>><i>Main Keywords for this
search: * </i></font></td><td><input type="text" name="Keywords"
size=60></td></tr>
<td></td>
<tr><td colspan=2><font color=<? echo($FONTCOLOR);?> ><b>Article
Details: * </b></font><br>
<textarea name="Details" rows=13 cols=55 wrap=physical></textarea>
</td></tr>
<tr><td colspan=2 align=center><input type="submit" value="NEXT"></td></tr>
</table>
</form>
</div>
</td>
</tr>
</table>
</html>
<?php
}else
{
if (empty($title) || empty($Email) || empty($Phone) || empty($Details)
|| empty($Keywords) || empty($City))
{
$message = "Please fill all the required fields.";
// Now, redirect the browser to the current page
session_start();
header("Location: form.php?message=" . urlencode($message));
}
else
{
// Connect to the MySQL DBMS - credentials are in the file db.php
if (!($connection = @ mysql_pconnect($hostName, $username,
$password)))
showerror();
// Use the User database
if (!mysql_select_db($databaseName, $connection))
showerror();
// Create a query to find The Company ID
$query = "SELECT ID
FROM table
WHERE email = \"$user\"";
// Run the query through the connection
if (!($result = @ mysql_query($query, $connection)))
showerror();
// Were there any matching rows?
if (mysql_num_rows($result) == 0)
{
// No. So insert the new username and password into the table
$message = "The user account -<b>$user</b>- does not have ID.";
// Now, redirect the browser to the current page
header("Location: form.php?message=" . urlencode($message));
exit;
}
$row = @ mysql_fetch_array($result);
$ID = (rand()%9999);
$CID = $row["CompID"];
$jquery = "INSERT INTO table
(Title,Email,Phone,Details,Keywords,Location,City,)
Values('$title','$Email','$Phone','$Details','$Keywords','$location','$City')";
if (!($result = @ mysql_query($query, $connection)))
showerror();
$message = "Your Article has been posted. Fill in the form to
post more Articles";
// Now, redirect the browser to the current page
header("Location: form.php?message=" . urlencode($message));
exit;
}
}
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php