fareedreg Posted December 21, 2009 Share Posted December 21, 2009 I am posting my three php form .. through which i am submitting my data to sql server... first is submit.php in which i am accepting data from user... second is validate.php in that one i am validating data entered by user and in third one i am making a connection with database and firing insert query.. but I would like to know IS THERE IS ANY WAY THROUGH WHICH I CAN VALIDATE MY DATA IN same file submit.php...coz if there is any validation error occured user has to entered all data again. because submit.php post data for validation to validate.php and if validate.php generate any error all data must be retype... Or any other way available...thanks file codes below // submit.php <html><style type="text/css"> <!-- body { background-color: #FFCCCC; } .style11 {color: #FF0000} --> </style> <body> <table width="993" height="172" border="0"> <tr> <td><img src="images/chimei1.jpg" width="478" height="188" /><img src="images/chimei.jpg" width="503" height="188" /></td> </tr> </table> <form action="validate.php", method="post"> <table width="982" height="667" border="1"> <tr> <td width="791" height="661" align="left" valign="top"><p> </p> <h1 align="center"><em><strong>Submit Monitor Warranty</strong></em></h1> <p align="center"><img src="images/line1.gif" width="411" height="3"></p> <p align="center"> </p> <table width="456" height="337" border="1" align="center"> <tr> <td width="137">Customer Name <span class="style11">*</span></td> <td width="303"><input name="txtname" type="text" size="50" maxlength="50"/></td> </tr> <tr> <td height="38">Address <span class="style11">*</span></td> <td><input name="txtadd" type="text" value="" size="50" maxlength="200"></td> </tr> <tr> <td>Phone <span class="style11">*</span></td> <td><input name="txtphone" type="text" size="30" maxlength="30"/></td> </tr> <tr> <td>Email <span class="style11">*</span></td> <td><input name="txtemail" type="text" size="30" maxlength="20"/></td> </tr> <tr> <td>Model <span class="style11">*</span></td> <td><input name="txtmodel" type="text" size="10" maxlength="10"/></td> </tr> <tr> <td>Serial Number <span class="style11">*</span></td> <td><input name="txtsrlno" type="text" size="20" maxlength="15"/></td> </tr> <tr> <td>Dealer Name <span class="style11">*</span></td> <td><input name="txtpurfrom" type="text" size="50" maxlength="50"/></td> </tr> <tr> <td>Purchasing Date <span class="style11">*</span></td> <td><input name="txtdate" type="date" dd-mm-yy=""/> dd-mm-yy(format) </td> </tr> <tr> <td>Invoice No <span class="style11">*</span></td> <td><input name="txtinvoiceno" type="text" size="20" maxlength="20"/></td> </tr> </table> <p> </p> <div align="center"> <table width="264" border="0" align="center"> <tr> <td width="127"><div align="center"> <input type="submit" name="submit" value="Submit"\> </div></td> <td width="127"><div align="left"> <input type="reset" name="clear" id="clear" value="Clear"> </div></td> </tr> </table> </div></td> </tr> </table> <p align="center"> </p> <h1 align="center"> </h1> <p> </p> <p> </p> <p> </p> </body> </html> // validate.php <?php $i=0; $p=0; $name = $_POST["txtname"]; $add = $_POST["txtadd"]; $phone = $_POST["txtphone"]; $email = $_POST["txtemail"]; $model = $_POST["txtmodel"]; $srlno = $_POST["txtsrlno"]; $dealer = $_POST["txtpurfrom"]; $date = $_POST["txtdate"]; $invoice =$_POST["txtinvoiceno"]; If (empty($name)) { $errors[] = 'Cusomer Name not found *'; $i++; } If (empty($add)) { $errors[] = 'Address is Empty *'; $i++; } If (empty($phone)) { $errors[] = 'Phone no is essential *'; $i++; } If (empty($email)) { $errors[] = 'Email cannot be empty *'; $i++; } If (empty($model)) { $errors[] = 'Model required *'; $i++; } If (empty($srlno)) { $errors[] = 'Serial Number of Monitor is not entered *'; $i++; } If (empty($dealer)) { $errors[] = 'Dealer/Retailer name not found *'; $i++; } If (empty($date)) { $errors[] = 'Please enter purchasing date *'; $i++; } If (empty($invoice)) { $errors[] = 'Invoice number is must *'; $i++; } if (count($errors) == 0) { include ('warranty.php'); exec(warranty.php); // Process form } else { echo "<b><u> <FONT size=20> <font color=\"red\"> Errors found in records <br/> <br/> </b> </u>"; echo "<font color=\"black\">"; echo "<FONT size=5>"; while($p < $i) { echo "$errors[$p] <br /><br />"; $p++; } } /*echo $errors[0];*/ ?> // subcomplaint.php <?php $link = mysql_connect("localhost", "root","redaa34") or die("Could not connect : " . mysql_error()); $Db = "personal"; $Tb = "comp"; mysql_select_db($Db, $link); $name = $_POST["txtcustname"]; $phone = $_POST["txtphone"]; $mobile = $_POST["txtmobile"]; $email = $_POST["txtemail"]; $status = $_POST["txtstatus"]; $add = $_POST["txtaddress"]; $city = $_POST["txtcity"]; $model = $_POST["txtmodel"]; $srlno = $_POST["txtsrlno"]; $problem = $_POST["txtproblem"]; $today=date("d,m,y"); $query = "INSERT INTO $Tb (conper,conphone,conmobile,conemail,status,address,city,model,srlno,problem,subdate) value('$name','$phone','$mobile','$email','$status','$add','$city','$model','$srlno','$problem','$today')"; if(!mysql_query($query, $link)) die ("Mysql error ....<p>".mysql_error()); echo "Information Successfully added Thanks for your support to Cee Vision Technologies. We will contact you very soon" ?> Link to comment https://forums.phpfreaks.com/topic/185918-form-validation-again/ Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 Yes there is a way. Condense all 3 files into one file. I wont code it for you, but here's what you should do: Take the original form file and put the validation code into it towards the top. Enclose it in: if (isset($_POST['txtname'])) { } Now if your form is validated, after that, put another if "if ($valid==1) { insert sql }" Now if it isn't valid, the data will still be present. One way of doing this is: if (isset($_POST['universalfieldname'])) { foreach ($_POST as $key=>$value) { $$key=htmlspecialchars($value, ENT_QUOTES); } } <input type="text" name="txtname" value="$txtname"> Link to comment https://forums.phpfreaks.com/topic/185918-form-validation-again/#findComment-981743 Share on other sites More sharing options...
fareedreg Posted December 21, 2009 Author Share Posted December 21, 2009 Mate can you do it for me.. thanks in advance Yes there is a way. Condense all 3 files into one file. I wont code it for you, but here's what you should do: Take the original form file and put the validation code into it towards the top. Enclose it in: if (isset($_POST['txtname'])) { } Now if your form is validated, after that, put another if "if ($valid==1) { insert sql }" Now if it isn't valid, the data will still be present. One way of doing this is: if (isset($_POST['universalfieldname'])) { foreach ($_POST as $key=>$value) { $$key=htmlspecialchars($value, ENT_QUOTES); } } <input type="text" name="txtname" value="$txtname"> Link to comment https://forums.phpfreaks.com/topic/185918-form-validation-again/#findComment-981762 Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 To quote myself... I wont code it for you, but here's what you should do Link to comment https://forums.phpfreaks.com/topic/185918-form-validation-again/#findComment-981766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.