Pop-up popping too quickly
Posted: Tue Oct 21, 2008 6:18 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I am trying to create a shoutbox application from ground up. Might seem a small project but I just in the practice phase right now. Anyways I am facing this problem.. First lemme show you the code:
The problem is that whenever I open this page it shows that javascript error on starting. It is only meant when somebody clicks on submit button and the forms are empty. Could anybody suggest me how to avoid this window to pop when I open the page...
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I am trying to create a shoutbox application from ground up. Might seem a small project but I just in the practice phase right now. Anyways I am facing this problem.. First lemme show you the code:
Code: Select all
<html>
<body>
<form id="form1" name="form1" method="post" action="">
<label>Name
<input type="text" name="name" />
</label>
<p>
<label>Last Name
<input type="text" name="lastname" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
<?php
$host="localhost";
$user="root";
$pass="";
$db="my_db";
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$con = mysql_connect($host,$user,$pass);
if (!$con)
{
die('couldnt connect'.mysql_error());
}
mysql_select_db ($db,$con);
$lengthError="
<script type=\"text/javascript\">
alert(\"Please fill out the form properly. First Name And Last Name should be more than 2 characters\")
</script>
";
if (strlen($name)<2 or strlen($lastname)<2)
{
echo $lengthError;
}
else
{
$que="INSERT INTO persons (FirstName, LastName)
VALUES('$name','$lastname')";
mysql_query($que,$con);
}
$printQuery=mysql_query("SELECT * FROM persons");
while ($row=mysql_fetch_array($printQuery))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
mysql_close($con);
?>
</body>
</html>
The problem is that whenever I open this page it shows that javascript error on starting. It is only meant when somebody clicks on submit button and the forms are empty. Could anybody suggest me how to avoid this window to pop when I open the page...
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: