Is this is the way to write a form which insert data into a mysql DB ? Please note where I am keeping the mysql code.
The problem with this code is that whenever I am issues a refresh, a row is inserted into the DB with previous field values! Even when the form field is empty.
Pls help.
<html> <SCRIPT LANGUAGE="JavaScript1.2"> function verifyIt(form) { var sName = form.first_name.value, sEMID = form.e_mail.value; if ( sName == "" ) { ...... return false; } <? $sFName = $_POST['first_name']; $sLName = $_POST['last_name']; $sEMail = $_POST['e_mail']; $sComments = $_POST['comments']; mysql_connect( "localhost", "usr", "pwd" ) or die( "Failure" ); mysql_select_db( "sessions" ); $query = "INSERT INTO users( fname, lname, email, comments ) VALUES ( '$sFName', '$sLName', '$sEMail', '$sComments' )"; $result = mysql_query( $query ) or die ( "Unable to insert user.." ); mysql_close( "sessions" ); ?> return true; } </SCRIPT>
<form method="post" name="form" action="<? echo $editFormAction; ?>" onsubmit="return verifyIt(this);">
<table width="80%" border="0" cellspacing="1" cellpadding="0">
.....
.....
</table>
</form>
</body>
</html>
Thank you
Sudheer
_________________________________________________________________
The heat is on! Catch the latest action. http://server1.msn.co.in/sp03/formula2003/ Speed along with F1!
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php