DeFActo Posted April 23, 2008 Share Posted April 23, 2008 Hello all, I've made code <?php if(isset($_POST["Submit"])) { check_form(); } else { show_form(); } function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function check_form() { global $HTTP_POST_VARS, $error, $print_again; $error['vardas'] = false; if($_POST["vardas"]=="") { $error['vardas'] = true; $print_again = true; } $error['pavarde'] = false; if($_POST["pavarde"]=="") { $error['pavarde'] = true; $print_again = true; } $error['adresas'] = false; if($_POST["adresas"]=="") { $error['adresas'] = true; $print_again = true; } $error['miestas'] = false; if($_POST["miestas"]=="") { $error['miestas'] = true; $print_again = true; } $error['pastas'] = false; if($_POST["pastas"]=="") { $error['pastas'] = true; $print_again = true; } if(!check_email_address($_POST['el_pastas'])) { $error['el_pastas'] = true; $print_again = true; } if($print_again) { show_form(); } else { header('Location: DB/control/insert.php'); } //echo "$message"; }?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <style type="text/css"> <!-- a: link { color:#330033; text-decoration:none; } .rightborder { border-right: 1px solid #666666; } .bottomborder { border-bottom: 1px solid #666666; } .dtopborder { border-top: double #660033; } .dtoprightborder { border-top: double #660033; border-right: double #660033; } .drightborder { border-right: double #660033; } .drightbottomborder { border-bottom: 1px solid #666666; border-right: double #660033; } .dbottomdright { border-bottom: double #660033; border-right: double #660033; } .dtopbottomborder { border-top: double #660033; border-bottom: 1px solid #666666; } .buttomdright { border-right: double #660033; border-bottom: 1px solid #666666; } .dleftbottomborder { border-bottom: 1px solid #666666; border-left: double #660033; } body { background-image: url(images/bg.png); background-repeat:no-repeat; margin-left: 0px; margin-top: 20px; } #apDiv1 { position:absolute; width:80px; height:60px; z-index:1; left: 43px; top: 62px; } #apDiv2 { position:absolute; width:242px; height:158px; z-index:2; left: 318px; top: 427px; } #apDiv3 { position:absolute; width:190px; height:255px; z-index:3; left: 305px; top: 136px; } --> </style> </head> <body> <? function error_bool($error, $field) { if($error[$field]) { print("<td style=color:red>"); } // else { // print("<td>"); //} } function error_text($error) { if($error) { echo '<font style="color:#FF0000" size="2px">Neteisingai užpildytų laukų pavadinimai pažymėti raudonai </font>'; } else { echo ""; } } function show_form() { global $HTTP_POST_VARS, $print_again, $error;} ?> <div id="apDiv1"><a href=""><img src="images/sbi.png" width="80" height="60" border="0" /></a></div> <div id="apDiv2"><img src="images/Katalogas/catalogue1.png" width="240" height="158" /></div> <div id="apDiv3"><img src="images/Katalogas/catalogue2.png" width="190" height="255" /></div> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td height="40px" bgcolor="#000000"><img src="images/virs_juost copy.jpg" /></td> </tr> </table> <table width="1024" cellpadding="0" cellspacing="0"> <tr> <td height="20px" colspan="3"></td> </tr> <tr> <td height="38" colspan="3"><p style="margin-left:350px"><font face="Forte" color="#330033" size="6pt"><a href="../index.html" style="text-decoration:none; color:#330033"></a></font><!--<font face="Times New Roman, Times, serif" color="#000000" size="5pt"><i><b> Alytus</b></i></font>--></p></td> </tr> <tr> <td height="15" colspan="3"></td> </tr> <tr> <td height="35px" width="280"><a href="kolekcijos.html"><img style="margin-left:40px" src="images/Kolekcijos/koleknorm.png" alt="" onMouseOver=" this.src='images/Kolekcijos/kolekonmouse.png' " onMouseOut=" this.src='images/Kolekcijos/koleknorm.png' " border="0px" /></a></td> <td width="532" rowspan="11" align="right" valign="top" class="dleftbottomborder"><p style="text-align:left; margin-left:265px; font-family:'Book Antiqua'; font-size:14px"><br /> </b><br /> <br /> <b><br /> <br /><br /> </b> <br /> <!--<font style="color:#FF0000" size="1px">Neteisingai užpildytų laukų pavadinimai bus pažymėti raudona spalva!</font>--></p> <form id="form1" name="form1" method="post" action="katalogas1.php" align="left"> <label "<?php error_bool($error, "vardas"); ?>">Vardas <input style="margin-top:45px" type="text" name="vardas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["vardas"];} ?>"> </label><br/> <label "<?php error_bool($error, "pavarde"); ?>">Pavardė <input style="margin-top:10px" type="text" name="pavarde" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["pavarde"];} ?>"> </label><br/> <label "<?php error_bool($error, "adresas"); ?>">Adresas <input style="margin-top:10px" type="text" name="adresas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["adresas"];} ?>"> </label> <br/> <label "<?php error_bool($error, "miestas"); ?>">Miestas <input style="margin-top:10px" type="text" name="miestas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["miestas"];} ?>"> </label><br/> <label "<?php error_bool($error, "pastas"); ?>">Pašto indeksas <input style="margin-top:10px" type="text" name="pastas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["pastas"];} ?>"> </label><br/> <label "<?php error_bool($error, "el_pastas"); ?>">El. paštas <input style="margin-top:10px" type="text" name="el_pastas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["el_pastas"];} ?>"> </label><br/><?php error_text($error); ?> <input style="margin-top:10px" name="Submit" type="submit" value="Patvirtinti" /> <input name="Valyti laukus" type="reset" value="Valyti laukus" /> </form> <p align="center" style="text-align:left; margin-left:25px; font-family:'Book Antiqua'; font-size:11px"><b>Privatumo patikinimas.</b> Mes, gerbdami Jūsų privatumą, patikiname Jus, kad informacija, gauta užpildžius aukščiau esančią formą, nebus pateikta tretiems asmenims.</td> <td width="200" rowspan="11" class="bottomborder"> </td> </tr> <tr> <td height="10" width="280"></td> </tr> <tr> <td height="35px" width="280"><img style="margin-left:40px" src="images/Katalogas/katalogasmirk.gif" border="0px" /></td> </tr> <tr> <td height="10" width="280"></td> </tr> <tr> <td height="35px" width="280"><a href="karjera.html"><img style="margin-left:40px" src="images/Karjera/karjeranorm.png" alt="" onMouseOver=" this.src='images/Karjera/karjeraonmouse.png' " onMouseOut=" this.src='images/Karjera/karjeranorm.png' " border="0px" /></a></td> </tr> <tr> <td height="10" width="280"></td> </tr> <tr> <td height="35px" width="280"><a href="apie_mus.html"><img style="margin-left:40px" src="images/Apiemus/apiemusnorm.png" alt="" onMouseOver=" this.src='images/Apiemus/apiemusonmouse.png' " onMouseOut=" this.src='images/Apiemus/apiemusnorm.png' " border="0px" /></a></td> </tr> <tr> <td height="10" width="280"></td> </tr> <tr> <td height="35px" width="280"><a href="kontaktai.html"><img style="margin-left:40px" src="images/Kontaktai/kontaktainorm.png" alt="" onMouseOver=" this.src='images/Kontaktai/kontaktaionmouse.png' " onMouseOut=" this.src='images/Kontaktai/kontaktainorm.png' " border="0px" /></a></td> </tr> <tr> <td height="10" width="280"></td> </tr> <tr> <td height="340" width="280" align="center" valign="bottom" class="dtopbottomborder"><img style="margin-bottom:10px" src="images/Katalogas/1catalogue.png" /></td> </tr> <tr> <td height="20" colspan="3" style="font-family:'Book Antiqua'; font-size:11px"><p style="text-align:center"></p></td> </tr> </table> </body> </html> but after submition if all data in fields are correct i get an empty fields in my database. Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/ Share on other sites More sharing options...
jaymc Posted April 23, 2008 Share Posted April 23, 2008 No one will look at that Paste your form code, and echo the $query so we can see what MYSQL is seeing Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-525133 Share on other sites More sharing options...
DeFActo Posted April 23, 2008 Author Share Posted April 23, 2008 <?php if(isset($_POST["Submit"])) { check_form(); } else { show_form(); } function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } function check_form() { global $HTTP_POST_VARS, $error, $print_again; $error['vardas'] = false; if($_POST["vardas"]=="") { $error['vardas'] = true; $print_again = true; } $error['pavarde'] = false; if($_POST["pavarde"]=="") { $error['pavarde'] = true; $print_again = true; } $error['adresas'] = false; if($_POST["adresas"]=="") { $error['adresas'] = true; $print_again = true; } $error['miestas'] = false; if($_POST["miestas"]=="") { $error['miestas'] = true; $print_again = true; } $error['pastas'] = false; if($_POST["pastas"]=="") { $error['pastas'] = true; $print_again = true; } if(!check_email_address($_POST['el_pastas'])) { $error['el_pastas'] = true; $print_again = true; } if($print_again) { show_form(); } else { header('Location: DB/control/insert.php'); } //echo "$message"; }?> <body> <? function error_bool($error, $field) { if($error[$field]) { print("<td style=color:red>"); } // else { // print("<td>"); //} } function error_text($error) { if($error) { echo '<font style="color:#FF0000" size="2px">Neteisingai užpildytų laukų pavadinimai pažymėti raudonai </font>'; } else { echo ""; } } function show_form() { global $HTTP_POST_VARS, $print_again, $error;} ?> <form id="form1" name="form1" method="post" action="katalogas1.php" align="left"> <label "<?php error_bool($error, "vardas"); ?>">Vardas <input style="margin-top:45px" type="text" name="vardas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["vardas"];} ?>"> </label><br/> <label "<?php error_bool($error, "pavarde"); ?>">Pavardė <input style="margin-top:10px" type="text" name="pavarde" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["pavarde"];} ?>"> </label><br/> <label "<?php error_bool($error, "adresas"); ?>">Adresas <input style="margin-top:10px" type="text" name="adresas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["adresas"];} ?>"> </label> <br/> <label "<?php error_bool($error, "miestas"); ?>">Miestas <input style="margin-top:10px" type="text" name="miestas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["miestas"];} ?>"> </label><br/> <label "<?php error_bool($error, "pastas"); ?>">Pašto indeksas <input style="margin-top:10px" type="text" name="pastas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["pastas"];} ?>"> </label><br/> <label "<?php error_bool($error, "el_pastas"); ?>">El. paštas <input style="margin-top:10px" type="text" name="el_pastas" id="textfield" value="<?php if(isset($_POST["Submit"])) { echo $_POST["el_pastas"];} ?>"> </label><br/><?php error_text($error); ?> <input style="margin-top:10px" name="Submit" type="submit" value="Patvirtinti" /> <input name="Valyti laukus" type="reset" value="Valyti laukus" /> </form> hope thats better Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-525142 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Share Posted April 23, 2008 i get an empty fields in my database. Where is the query in your code Just echo the $query out, after it been parsed not the actually code Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-525200 Share on other sites More sharing options...
DeFActo Posted April 23, 2008 Author Share Posted April 23, 2008 $query="INSERT INTO table (vardas, pavarde, adresas, miestas, pastas, el_pastas) VALUES ('$_POST[vardas]','$_POST[pavarde]','$_POST[adresas]','$_POST[miestas]','$_POST[pastas]','$_POST[el_pastas]')"; its in another file, named insert.php Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-525210 Share on other sites More sharing options...
jaymc Posted April 23, 2008 Share Posted April 23, 2008 Just echo the $query out, after it been parsed not the actual code Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-525221 Share on other sites More sharing options...
DeFActo Posted April 24, 2008 Author Share Posted April 24, 2008 Just echo the $query out, after it been parsed not the actual code i must be dumb, don't get it Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-526072 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Put this after $query="INSERT INTO table (vardas, pavarde, adresas, miestas, pastas, el_pastas) VALUES ('$_POST[vardas]','$_POST[pavarde]','$_POST[adresas]','$_POST[miestas]','$_POST[pastas]','$_POST[el_pastas]')";. echo $query; ... Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-526077 Share on other sites More sharing options...
DeFActo Posted April 24, 2008 Author Share Posted April 24, 2008 INSERT INTO klientai (vardas, pavarde, adresas, miestas, pastas, el_pastas) VALUES ('','','','','','') Warning: Cannot modify header information - headers already sent by (output started at /home/sbinternational/public_html/failai/DB/control/insert.php:9) in /home/sbinternational/public_html/failai/DB/control/insert.php on line 14 Everything was just fine before i have decided to make checking for empty inputs and wrong email address. Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-526085 Share on other sites More sharing options...
DeFActo Posted April 24, 2008 Author Share Posted April 24, 2008 i am loosing POST array from header('Location: DB/control/insert.php'); anybody could help me how to fix it? Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-526162 Share on other sites More sharing options...
DeFActo Posted April 24, 2008 Author Share Posted April 24, 2008 header('Location: DB/control/insert.php'); changed to include. Quote Link to comment https://forums.phpfreaks.com/topic/102557-solved-problems-with-form/#findComment-526191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.