473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Form submission code is not executing in proper order

190 100+
hi ,

A strange error is coming , when i run a php file , all the php and java script executes before submit only which actually should execute after clicking on submit button and performing some checks.what to do ?
Dec 31 '08 #1
5 1992
Hi, please explain your problem a little more.
Dec 31 '08 #2
Shalini Bhalla
190 100+
I have written a file , in which i am creating a form to create new user .On submit i am checking for duplicate username in database and if username already existing i come back to form and if does't exist then accepting user name create a new user.

But the problem is that as soon as i acces url what ever php i have written is getting executed before displaying form objects . And because the form are empty fist time , there is no data fir queries , mysqo_numrows() is throwing warning before only.

how to rectify it ?
Dec 31 '08 #3
Atli
5,058 Expert 4TB
Hi.

We would need to see the part of the code that is causing the problem to be able to say anything for sure.

But I will say this.
PHP is a server side language. IT will ALWAYS be executed before the HTML reaches the browser. You can not execute PHP code using JavaScript events or any other client-side coding. (Except AJAX, but that is an entire different thing.)
Dec 31 '08 #4
Shalini Bhalla
190 100+
here "user doesnot exist shoud appear on if i ma getting action=dup but its getting executed before only.....


Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. <script language="javascript">
  7. function IsEmail(strEmail)
  8. {
  9.     var status = false;
  10.     var strEmailAddress = new String(strEmail);    
  11.     var strEmailPattern = (/^([a-z0-9_\.\-])+\@(([a-z0-9_\.\-])+\.)+([a-z0-9]{2,4})+$/i);
  12.     if (strEmailAddress.search(strEmailPattern)==0)
  13.     {
  14.         status = true;
  15.     }
  16.     return status;
  17. }
  18.  
  19. function validate()
  20. {
  21. if(!(IsEmail(document.form1.email.value)))
  22. {
  23. alert("Please enter an exact email address.\n" );
  24.         return false;
  25. }
  26. else if(document.form1.username.value == '')
  27.     {
  28.         alert('Username can not be blank');
  29.         return false;
  30. }
  31. else if(document.form1.pass.value == '')
  32.     {
  33.     alert('Passward can not be blank');
  34.     return false;
  35.     }
  36. else if(document.form1.membership.value == '')
  37.     {
  38.     alert('Passward can not be blank');
  39.     return false;
  40.     }
  41.  
  42. else if(document.form1.email.value == '')
  43.     {
  44.     alert('E-mail ID can not be blank');
  45.     return false;
  46.     }
  47. else if(document.form1.tele.value == '')
  48.     {
  49.     alert('Teleno ID can not be blank');
  50.     return false;
  51.     }
  52. else
  53. {
  54. document.form1.method = 'GET';
  55. document.form1.action = 'c_user.php?action=add';
  56. document.form1.submit(); 
  57. }
  58. }
  59. </script>
  60. </head>
  61.  
  62. <body>
  63. <form id="form1" name="form1" method="GET" action="c_user.php" enctype="multipart/form-data">
  64.   <table width="48%" border="0" cellspacing="5" cellpadding="5">
  65.    <? if($_REQUEST["action"] == "dup");{ ?> 
  66.    <tr>
  67.       <td width="100%" colspan="3">Username already exist</td>
  68.  
  69.     </tr><? }?>
  70.     <tr>
  71.       <td width="34%">Username</td>
  72.       <td width="10%"><span class="style2">*</span></td>
  73.       <td colspan="2"><label>
  74.         <input type="text" name="username"  />
  75.       </label></td>
  76.     </tr>
  77.     <tr>
  78.       <td>Passward</td>
  79.       <td><span class="style2">*</span></td>
  80.       <td colspan="2"><input type="passward" name="pass" /></td>
  81.     </tr>
  82.     <tr>
  83.       <td>First Name </td>
  84.       <td>&nbsp;</td>
  85.       <td colspan="2"><input type="text" name="fname" /></td>
  86.     </tr>
  87.     <tr>
  88.       <td>Last Name </td>
  89.       <td>&nbsp;</td>
  90.       <td colspan="2"><input type="text" name="lname" /></td>
  91.     </tr>
  92.     <tr>
  93.       <td>Tele No </td>
  94.       <td><span class="style2">*</span></td>
  95.       <td colspan="2"><input type="text" name="tele" /></td>
  96.     </tr>
  97.     <tr>
  98.       <td>Address</td>
  99.       <td>&nbsp;</td>
  100.       <td colspan="2"><input type="text" name="add" /></td>
  101.     </tr>
  102.     <td>Country</td>
  103.       <td>&nbsp;</td>
  104.       <td width="25%"><label>
  105.         <select name="country" id="country">
  106.           <option value="India">India</option>
  107.           <option value="Other">Other</option>
  108.         </select>
  109.       </label></td>
  110.       <td width="31%"><label>
  111.         <input name="Ocountry" type="text" id="Ocountry" />
  112.       </label></td>
  113.     <tr>
  114.       <td>City</td>
  115.       <td>&nbsp;</td>
  116.       <td colspan="2"><input type="text" name="city" /></td>
  117.     </tr>
  118.     <tr>    </tr>
  119.     <tr>
  120.       <td>Occupation</td>
  121.       <td>&nbsp;</td>
  122.       <td colspan="2"><input name="occu" type="text" id="occu" /></td>
  123.     </tr>
  124.     <tr>
  125.       <td>Company</td>
  126.       <td>&nbsp;</td>
  127.       <td colspan="2"><input type="text" name="company" /></td>
  128.     </tr>
  129.     <tr>
  130.       <td>Membership Plan </td>
  131.       <td><span class="style2">*</span></td>
  132.       <td colspan="2"><label>
  133.         <select name="membership" id="membership">
  134.           <option value="Free" selected="selected">Free</option>
  135.           <option value="ProI">Pro Indvidual</option>
  136.           <option value="ProA">Pro Agent</option>
  137.           <option value="ProS">Super Pro</option>
  138.         </select>
  139.       </label></td>
  140.     </tr>
  141.     <tr>
  142.       <td>Email</td>
  143.       <td><span class="style2">*</span></td>
  144.       <td colspan="2"><input name="email" type="text" id="email" /></td>
  145.     </tr>
  146.  
  147.     <tr>
  148.       <td>&nbsp;</td>
  149.       <td>&nbsp;</td>
  150.       <td colspan="2"><label>
  151.         <div align="right">
  152.           <input type="button" name="Submit" value="Submit" onclick="validate();" />
  153.         </div>
  154.       </label></td>
  155.     </tr>
  156.   </table>
  157.  
  158. </form>
  159. </body>
  160. </html>
  161.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("conn.php");
  3. if($_REQUEST["action"] == "add"); 
  4. {
  5. $username = $_GET["username"];
  6. $passward = $_REQUEST["pass"];
  7. $fname = $_REQUEST["fname"];
  8. $lname = $_REQUEST["lname"];
  9. $teleno = $_REQUEST["tele"];
  10. $email = $_REQUEST["email"];
  11. $company = $_REQUEST["company"];
  12. $add = $_REQUEST["add"];
  13. $country = $_REQUEST["add"];
  14. $city = $_REQUEST["add"];
  15. $occu = $_REQUEST["occu"];
  16. $membership = $_REQUEST["membership"];
  17. $q = "select u_name from my_user where u_name ='".$username."'";
  18.  
  19. if(!mysql_query($q))
  20. {
  21. die("error".mysql_error());
  22. }
  23. $r = mysql_query($q);
  24. $rows = mysql_numrows($r);
  25. if($rows <= 0)
  26. {
  27. $query = "insert into my_user values('','$username' , '$passward', '$fname' , '$lname' , '$tele' ,'$add','$city','$country','$occu','$company','$membership',CURDATE(),'$email')";
  28. if(!mysql_query($query))
  29. {
  30.  
  31. die("error".mysql_error());
  32. }
  33. $to = $email;
  34. $subject = "Your Registration At  Classifieds Guide India";
  35. $message = "Dear ".$fname;
  36. $message .= "\n\tThankyou For Registring In Classifieds .You will shortly receive a confirmation call to get to know about payment details at your give telephone number :".$tele.".Plese be ready with details.\n\t\tThankyou\nClassifieds .";
  37. $from = "xyz@yahoo.com";
  38. $headers = "From: $from";
  39. mail($to,$subject,$message,$headers);
  40. header("Location:create_user.php");
  41. }
  42. if($rows > 0 )
  43. {
  44.  
  45. header("Location:create_user.php?action=dup");
  46. }
  47. }
  48. ?>
  49.  
Jan 9 '09 #5
Atli
5,058 Expert 4TB
Line #65 of the first code. There is an extra semi-colon after the if statement, before the code block, which means the code block will always get executed regardless of how the if statement was executed.

You should also consider changing the form method to POST.
Sending all that data on the GET protocol is just not sanitary :)
Jan 9 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: ratlhead | last post by:
Hey all, I'm attempting to do some form processing on a server that has register_globals off, however, I've run into a confusing situation and need some help. Basically, the form is a...
7
by: Shannon | last post by:
Hi everyone, I am trying to post some data to a form using the XMLHTTP object, and have run into a problem trying to find the proper location of the receiving page. The form points to a...
6
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web...
19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0...
10
by: Steve Benson | last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and got the job of adapting existing code. In the page below, everything works until I added the function checkIt() to...
2
by: adawson | last post by:
Hi, I need to execute some code when form submission is stopped before the page is returned from the server. For example, a user clicks a button to submit the form, realizes they've made a...
2
by: rpjd | last post by:
I am trying to submit entries in a form to a database. I am using " within my submission form and $_POST I am getting the connection to the database but I my script is not executing,...
8
Megalog
by: Megalog | last post by:
Hey guys.. my turn to ask a question: I'm having a weird issue with a form I've reworked. This form has a combo box, which when used is changing the recordsource of a subform. This subform has...
2
by: dancerman | last post by:
I want a simple as possible regex to check the format of my form submission URL string, I don't care whether is an actual real working URL, just that it be in proper URL format and, IF POSSIBLE add...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.