469,270 Members | 1,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Need help with scripting to store data on MySQL

mideastgirl
I have recently been working on a website for an honors association, and have a lot of difficulty but have found help from those on this site. I would like to see if I can get some more help on a different issue than what I was initially having.
I am working on storing data collected from a form on my website. I would like the information to be stored into MySQL once entered by users. I have googled this question and have tried multiple suggestions and have progressed slightly. The problem that I am having is that the page after I press the submit button (actually called Add Member) comes up blank. I would like the page to either read "Thank you, your information has been added" or "Error-incomplete information provided, please fill out the form" or something along those lines.

So my problem is getting the information to store to MySQL and then getting the filled out form page to move onto the next page.

Please see: http://mideasthonors.org/addmember.php to view the form.

This is the scripting I have for the form information to be added to MySQL:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include ("admintasks-dbcon.php");
  3. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  4. mysql_select_db($dbname);
  5.  
  6. $query = 'SELECT * FROM $add_member';
  7. $result = mysql_query($query);
  8.  
  9. if($result) 
  10.  {
  11.      while($row = mysql_fetch_array($result))
  12.      {
  13.          $name = $row['$yourfield'];
  14.          echo 'Name: '.$name;
  15.  
  16.          mysql_select_db("mideasthonors");
  17.  
  18.          $sql="INSERT INTO $add_member (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address) 
  19.          VALUES {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']})";
  20.  
  21.          if (!mysql_query($sql,$con))         
  22.          {
  23.              die('Error: ' . mysql_error());
  24.          }
  25.  
  26.         echo 'Thank You! Your information has been entered into the database!'; 
  27.      }
  28.  } 
  29. ?>
  30.  
This is the error page I have set up:
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.  
  4. <head>
  5. <meta http-equiv="Content-Language" content="en-us" />
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>Error</title>
  8. <style type="text/css">
  9. .style1 {
  10.     font-family: Arial, Helvetica, sans-serif;
  11.     font-size: medium;
  12. }
  13.  
  14. .style29 {
  15.     font-family: Arial, Helvetica, sans-serif;
  16. }
  17. h2 {
  18.     font-family: Verdana, Arial, Helvetica, sans-serif;
  19.     font-size: 17px;
  20.     font-weight: bold;
  21.     color: #2F77F1;
  22.     line-height: 20px;
  23. }
  24. .style30 {
  25.     font-family: geneva, arial;
  26.     font-size: 10pt;
  27. }
  28.  
  29. .style31 {
  30.     font-family: Verdana, Arial, Helvetica, sans-serif;
  31.     font-size: 12px;
  32.     line-height: 11pt;
  33.     margin: 3px 0;
  34.     padding-bottom: 9px;
  35. }
  36. </style>
  37. </head>
  38.  
  39. <body>
  40.  
  41. <p class="style1"><strong>Error: All fields have not been filled in, or information is inaccurate. Please complete form.</strong></p>
  42. <form method="post" action="addmember.php" style="width: 169px">
  43. *
  44.  
  45.     <table>
  46.  
  47.         <tr>
  48.             <td colspan=2><h2 class="style29">Institution Information</h2></td>
  49.         </tr>
  50.  
  51.         <tr>
  52.             <td class='style30'><p class="style31"><label for='name'>Name*</label></p></td>
  53.             <td class="style30"><input type='text' name='name' size=45 maxlength=100 /></td>
  54.         </tr>
  55.  
  56.         <tr>
  57.             <td class='style30'><p class="style31"><label for='address_1'>Address*</label></p></td>
  58.             <td class="style30"><input type='text' name='address_1' size=45 maxlength=100 /></td>
  59.         </tr>
  60.  
  61.         <tr>
  62.             <td class="style30">&nbsp;</td>
  63.             <td class="style30"><input type='text' name='address_2' size=45 maxlength=100 /></td>
  64.         </tr>
  65.  
  66.         <tr>
  67.             <td class='style30'><p class="style31"><label for='city'>City*</label></p></td>
  68.             <td class="style30"><input type='text' name='city' size=45 maxlength=50 /></td>
  69.         </tr>
  70.  
  71.         <tr>
  72.             <td class='style30'><p class="style31"><label for='state'>State*</label>
  73.             <td class="style30">
  74.                 <select name='state'>
  75.                 <?php
  76.                 $states = array("Illinois", "Indiana", "Kentucky", "Michigan", "Ohio", "Pennsylvania", "Tennessee", "West Viriginia");
  77.                 foreach($states as $a => $value){
  78.                     echo "<option name='$value'>$value</option>";
  79.                 }
  80.                 ?>
  81.                 </select>
  82.             </td>
  83.         </tr>
  84.  
  85.         <tr>
  86.             <td class='style30'><p class="style31"><label for='zip'>ZIP Code*</label></p></td>
  87.             <td class="style30"><input type='text' name='zip' size=10 maxlength=10 /></td>
  88.         </tr>
  89.  
  90.         <tr>
  91.             <td class='style30'><p class="style31"><label for='website'>Website*</label></p></td>
  92.             <td class="style30"><input type='text' name='website' value='http://www.' size=45 maxlength=100 /></td>
  93.         </tr>
  94.  
  95.         <tr>
  96.             <td colspan=2><h2 class="style29">Contact Information</h2></td>
  97.         </tr>
  98.  
  99.         <tr>
  100.             <td class='style30'><p class="style31"><label for='contact_name'>Contact Name*</label></p></td>
  101.             <td class="style30"><input type='text' name='contact_name' size=45 maxlength=100 /></td>
  102.         </tr>
  103.  
  104.         <tr>
  105.             <td class='style30'><p class="style31"><label for='contact_position'>Position</label></p></td>
  106.             <td class="style30"><input type='text' name='contact_position' size=45 maxlength=100 /></td>
  107.         </tr>
  108.  
  109.         <tr>
  110.             <td class='style30'><p class="style31"><label for='contact_phone'>Phone Number*</label></p></td>
  111.             <td class="style30"><input type='text' name='contact_phone' size=14 maxlength=14 /></td>
  112.         </tr>
  113.  
  114.         <tr>
  115.             <td class='style30'><p class="style31"><label for='contact_email'>Email Address*</label></p></td>
  116.             <td class="style30"><input type='text' name='contact_email' size=45 maxlength=100 /></td>
  117.         </tr>
  118.  
  119.         <tr>
  120.             <td class="style30">&nbsp;</td>
  121.             <td class="style30"><input type='submit' name ="Add Member" value='Add Member' /></td>
  122.         </tr>
  123.  
  124.     </table>
  125.  
  126.  
If anyone could help me out I would really appreciate it!
Jul 22 '09
70 4648
Everything is still the same that is on the page that you gave me except the error: error_reporting(E_ALL); at the top. Its just that they need to enter their information from mideasthonors.org/addmember.php instead of addmembererror.php. Does that make sense??? I mean the same form is on both pages, just at the top it states that information was not filled in accurately.
Jul 28 '09 #51
anfetienne
424 256MB
yes it makes sense and as i said you need to change the names within the $_POST so they match the addmember.php form. they need to look like these

Expand|Select|Wrap|Line Numbers
  1. $_POST['name']
  2. $_POST['address_1']
  3. $_POST['address_2']
  4. $_POST['city']
  5. $_POST['state']
  6. $_POST['zip']
  7. $_POST['website']
  8. $_POST['contact_name']
  9. $_POST['contact_position']
  10. $_POST['contact_phone']
  11. $_POST['contact_email']
  12.  
and the form on the error page should be the same as the other form then

Expand|Select|Wrap|Line Numbers
  1.  <form method="post" action="addmember.php" style="width: 169px">
  2.  *  
  3.      <table>
  4.  
  5.          <tr>
  6.              <td colspan=2><h2 class="style29">Institution Information</h2></td>
  7.          </tr>
  8.  
  9.          <tr>
  10.              <td class='style30'><p class="style31"><label for='name'>Institution*</label></p></td>
  11.              <td class="style30"><input type="text" name="name" size=45 maxlength=100 value="" /></td>
  12.          </tr>
  13.  
  14.          <tr>
  15.              <td class='style30'><p class="style31"><label for='address_1'>Address*</label></p></td>
  16.              <td class="style30"><input type="text" name="address_1" size=45 maxlength=100 value="" /></td>
  17.          </tr>
  18.  
  19.          <tr>
  20.              <td class="style30">&nbsp;</td>
  21.              <td class="style30"><input type="text" name="address_2" size=45 maxlength=100 value="" /></td>
  22.          </tr>
  23.  
  24.          <tr>
  25.              <td class='style30'><p class="style31"><label for='city'>City*</label></p></td>
  26.              <td class="style30"><input type="text" name="city" size=45 maxlength=50 value="" /></td>
  27.          </tr>
  28.  
  29.          <tr>
  30.              <td class='style30'><p class="style31"><label for='state'>State*</label>
  31.              <td class="style30">
  32.                  <select name='state'>
  33.                  <?php
  34.                  $states = array("Illinois", "Indiana", "Kentucky", "Michigan", "Ohio", "Pennsylvania", "Tennessee", "West Viriginia");
  35.                  foreach($states as $a => $value){
  36.                      echo "<option name=".$value ." value=".$value .">$value</option>";
  37.                  }
  38.                  ?>
  39.                  </select>
  40.              </td>
  41.          </tr>
  42.  
  43.          <tr>
  44.              <td class='style30'><p class="style31"><label for='zip'>ZIP Code*</label></p></td>
  45.              <td class="style30"><input type="text" name="zip" size=10 maxlength=10 value="" /></td>
  46.          </tr>
  47.  
  48.          <tr>
  49.              <td class='style30'><p class="style31"><label for='website'>Website*</label></p></td>
  50.              <td class="style30"><input type="text" name="website" value="http://www." size=45 maxlength=100 value="" /></td>
  51.          </tr>
  52.  
  53.          <tr>
  54.              <td colspan=2><h2 class="style29">Contact Information</h2></td>
  55.          </tr>
  56.  
  57.          <tr>
  58.              <td class='style30'><p class="style31"><label for='contact_name'>Contact Name*</label></p></td>
  59.              <td class="style30"><input type="text" name="contact_name" size=45 maxlength=100 value="" /></td>
  60.          </tr>
  61.  
  62.          <tr>
  63.              <td class='style30'><p class="style31"><label for='contact_position'>Position</label></p></td>
  64.              <td class="style30"><input type="text" name="contact_position" size=45 maxlength=100 value="" /></td>
  65.          </tr>
  66.  
  67.          <tr>
  68.              <td class='style30'><p class="style31"><label for='contact_phone'>Phone Number*</label></p></td>
  69.              <td class="style30"><input type="text" name="contact_phone" size=14 maxlength=14 value="" /></td>
  70.          </tr>
  71.  
  72.          <tr>
  73.              <td class='style30'><p class="style31"><label for='contact_email'>Email Address*</label></p></td>
  74.              <td class="style30"><input type="text" name="contact_email" size=45 maxlength=100 value="" /></td>
  75.          </tr>
  76.  
  77.          <tr>
  78.              <td class="style30">&nbsp;</td>
  79.              <td class="style30"><input type="submit" name ="Add Member" value="Add Member" /></td>
  80.          </tr>
  81.  
  82.     </table>
  83.     </form>
  84.  
Jul 28 '09 #52
OK! So I changed the posts to match what I have on the form...and still no luck!
I am not sure if the for instance this would be part of the problem "phone_number" what is the underscored line for??? And do I need to do anything for the member ID number since it is a hidden number that should be assigned randomly???

Here is what I have for the addmember_db.php:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include ("admintasks-dbcon.php");
  3. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  4. mysql_select_db($dbname);  
  5. $query = "SELECT * FROM add_member WHERE memberID = '{memberID}'";
  6. $result = mysql_query( $sql ) or die( mysql_error );
  7.  
  8. if ( mysql_num_rows( $res ) > 0 )
  9.  
  10. $query="
  11. SELECT add_member SET
  12.             name = $_POST ['name']; 
  13.             address 1 = $_POST ['address_1']; 
  14.             address 2 = $_POST ['address_2'];
  15.             City= $_POST ['city']; 
  16.             State = $_POST ['state']; 
  17.             Zip Code = $_POST ['zip'];
  18.             Website = $_POST ['website'];
  19.             Contact Name = $_POST ['contact_name'];
  20.             Position = $_POST ['position'];
  21.             Phone Number = $_POST ['phone_number'];
  22.             Email Address = $_POST ['email_address'];)
  23.  
  24. WHERE memberID ='{$memberID}'";
  25. }
  26. else{
  27.  
  28. $query="
  29.  
  30. INSERT INTO add_member (
  31.  
  32.             'Member ID',    
  33.             'Name',
  34.             'Address 1',
  35.             'Address 2',
  36.             'City', 
  37.             'State', 
  38.             'Zip Code', 
  39.             'Website', 
  40.             'Contact Name', 
  41.             'Position', 
  42.             'Phone Number', 
  43.             'Email Address')
  44.  
  45. VALUES 
  46.  
  47.             '{$_POST['memberID']}',
  48.             '{$_POST['name']}',
  49.             '{$_POST['address_1']}',
  50.             '{$_POST['address_2']}',
  51.             '{$_POST['city']}',
  52.             '{$_POST['state']}',
  53.             '{$_POST['zip']}',
  54.             '{$_POST['website']}',
  55.             '{$_POST['contact_name']}',
  56.             '{$_POST['position']}',
  57.             '{$_POST['phone_number']}',
  58.             '{$_POST['email_address']}')";
  59.  
  60. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  61.  
  62. if ( mysql_num_rows( $result ) > 0 ) 
  63. echo mysql_affected_rows()." row inserted into the database effectively."; 
  64.  
  65. mysql_close(); 
  66. }
  67.  
  68. session_start();
  69. $_SESSION["Name"] = $_POST['name'];
  70. header("location:thankyouforbecomingamember.php");
  71. ?>
  72.  
and the result of filling in the form and clicking the add member button is: "mysql_error"
Jul 29 '09 #53
anfetienne
424 256MB
that whole piece of coding is incorrect.....you have gone back to your original model instead of using what i fixed for you and just changing the names in the $_POST vars.......
Jul 29 '09 #54
OK I see what you are saying. I redid the coding and I am getting a header error now!

Expand|Select|Wrap|Line Numbers
  1. <?
  2. include ("admintasks-dbcon.php");
  3.  
  4.  
  5. $memberID = $_POST['memberID'];
  6. $institutionName = $_POST['institutionName'];
  7. $address1 = $_POST['address_1']; 
  8. $address2 = $_POST['address_2'];
  9. $city = $_POST['city'];
  10. $state = $_POST['state'];
  11. $zipCode = $_POST['zipCode'];
  12. $website = $_POST['website'];
  13. $contactName = $_POST['contactName'];
  14. $position = $_POST['position'];
  15. $phoneNumber = $_POST['phone'];
  16. $email = $_POST['email'];
  17.  
  18. // OPEN CONNECTION ---> 
  19. mysql_connect($hostname,$username,$password);
  20. @mysql_select_db($dbname) or die( "Unable to select database");
  21.  
  22.  
  23.  $sql = "SELECT * FROM addMember WHERE email = '{$email}'";
  24.  $res = mysql_query( $sql ) or die( mysql_error );
  25.  
  26.  if ( mysql_num_rows( $res ) > 0 )
  27.  { 
  28.  
  29. session_start();
  30. $_SESSION["contactName"] = $contactName;
  31. header("location:alreadyMember.php");
  32.  
  33.  }
  34.  else{
  35.  
  36.  $query="INSERT addMember (
  37.  
  38.              memberID,    
  39.              institution,
  40.              address1,
  41.              address2,
  42.              city, 
  43.              state, 
  44.              zip, 
  45.              website, 
  46.              contactName, 
  47.              position, 
  48.              phoneNumber, 
  49.              email)
  50.  
  51.  VALUES (    '".$memberID."',
  52.              '".$institution."',
  53.              '".$address1."',
  54.              '".$address2."',
  55.              '".$city."',
  56.              '".$state."',
  57.              '".$zipCode."',
  58.              '".$website."',
  59.              '".$contactName."',
  60.              '".$position."',
  61.              '".$phoneNumber."',
  62.              '".$email."')";
  63.  
  64. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  65.  
  66. session_start();
  67. $_SESSION["contactName"] = $contactName;
  68. header("location:thankyouforbecomingamember.php");
  69. }
  70.  
  71. mysql_close();
  72. // CLOSE CONNECTION --->
  73. ?>
  74.  
This is the error I am getting:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 31
__________________________________________________ ____________
I know this is frustrating, but I really do appreciate all your help. I am just confused on what the issues are. Like I initially said I am still very new to php and have come up with what I originally had on my own, so I am sorry if I do not understand everything to a "T"...I was a PSCI major for my BA and am now a Public Admin. major for my masters, php is NOT my thing. But I have to make this website work for my graduate assistantship, so once again I apologize for not understanding everything you guys are laying out for me. It may be very easy for you to understand but is quite difficult for me. I do not want to copy and paste what you gave me, I would like to figure it out on my own, but at the same time I feel like I am in a realm that I do not understand when I get responses from each of you....at any rate thank you all for your help.
Jul 30 '09 #55
Dormilich
8,651 Expert Mod 8TB
there seems an output to be sent. I suspect the UTF-8 BOM (Byte Order Mark). you need to open the file in an editor, which can show you hidden characters. it should be right at the beginning of the first line.

once the session error is fixed, the header error should disappear.
Jul 30 '09 #56
I opened the file in Notepad++ and there was nothing before <? so I am not sure what else I am looking for. I have attached the file in notepad.
Attached Files
File Type: txt addmember.txt (1.7 KB, 256 views)
Jul 30 '09 #57
Dormilich
8,651 Expert Mod 8TB
what happens if you use this text file? (I have no other explanaition than the already given...)
Jul 30 '09 #58
I get the header error. I changed the variables in the _POST and added the dollar signs prior to each variable so they are identified. That is exactly what the other person informed me to do!
Jul 30 '09 #59
anfetienne
424 256MB
i informed you to change the names in the post not to add dollar signs

$_POST['change_this']
Jul 30 '09 #60
Dear mideastgirl the above bytes.zip file works very nicely which is given by Mr. anfetienne so follow him.

I have down load this above bytes.zip & copy to all byte on htdocs folder & create database which name is bytes. emport the table from above. & Change here with

mysql_connect($hostname,$username,$password);
@mysql_select_db($dbname) or die( "Unable to select database");

Replace with

mysql_connect("localhost","root"," ");
@mysql_select_db(''addMember) or die( "Unable to select database");

Then after test it. It work nicely.

Thank You
Jul 31 '09 #61
anfetienne
424 256MB
hi, the sample i gave is a complete working model with no errors....thank you luckysanj for testing it.

mideastgirl please note that he changed the sql connection to suit him but you don't have to as i used what you had in your previous code.

all that you needed to change on my code was the $_POST['changeMeHere'] to match the names you have in your table....you didn't have to change anything else, or add dollar signs because it was all written for you.
Jul 31 '09 #62
I went back through and just copied and pasted the files, which I HATE doing but I am apparently too unintelligent to do otherwise. I am still getting these warnings:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/addmember_db.php:1) in /home/content/m/i/d/mideasthonors/html/addmember_db.php on line 31

Here is the coding, which I am sure you already have since it is exactly what you gave me/ except without the error "error_reporting(E_ALL);" on it since it is not for the error page
Expand|Select|Wrap|Line Numbers
  1. <? 
  2. include ("admintasks-dbcon.php");
  3.  
  4.  
  5. $memberID = $_POST['memberID'];
  6. $institution = $_POST['institution'];
  7. $address1 = $_POST['address_1']; 
  8. $address2 = $_POST['address_2'];
  9. $city = $_POST['city'];
  10. $state = $_POST['state'];
  11. $zipCode = $_POST['zip'];
  12. $website = $_POST['website'];
  13. $contactName = $_POST['contactName'];
  14. $position = $_POST['position'];
  15. $phoneNumber = $_POST['phone'];
  16. $email = $_POST['email'];
  17.  
  18. // OPEN CONNECTION ---> 
  19. mysql_connect($hostname,$username,$password);
  20. @mysql_select_db($dbname) or die( "Unable to select database");
  21.  
  22.  
  23.  $sql = "SELECT * FROM addMember WHERE email = '{$email}'";
  24.  $res = mysql_query( $sql ) or die( mysql_error );
  25.  
  26.  if ( mysql_num_rows( $res ) > 0 )
  27.  { 
  28.  
  29. session_start();
  30. $_SESSION["contactName"] = $contactName;
  31. header("location:alreadyMember.php");
  32.  
  33.  }
  34.  else{
  35.  
  36.  $query="INSERT addMember (
  37.  
  38.              memberID,    
  39.              institution,
  40.              address1,
  41.              address2,
  42.              city, 
  43.              state, 
  44.              zip, 
  45.              website, 
  46.              contactName, 
  47.              position, 
  48.              phoneNumber, 
  49.              email)
  50.  
  51.  VALUES (    '".$memberID."',
  52.              '".$institution."',
  53.              '".$address1."',
  54.              '".$address2."',
  55.              '".$city."',
  56.              '".$state."',
  57.              '".$zipCode."',
  58.              '".$website."',
  59.              '".$contactName."',
  60.              '".$position."',
  61.              '".$phoneNumber."',
  62.              '".$email."')";
  63.  
  64. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  65.  
  66. session_start();
  67. $_SESSION["contactName"] = $contactName;
  68. header("location:thankyouforbecomingamember.php");
  69. }
  70.  
  71. mysql_close();
  72. // CLOSE CONNECTION --->
  73. ?>
  74.  
The other files were literally copy and pasted with no changes made.
Aug 3 '09 #63
anfetienne
424 256MB
as i said before you are getting those warnings because the form you have uses different field names to what is in the $_POST vars on the php code. some of the $_POST vars aren't being filled with the data from the form, so it leaves them with no values and not set. now because the session looks for the value within the set var it gives you an error because there isn't any values within the var.......

thats why i have been stating for you to either change the names within the $_POST to match what you have on your forms or change all field names in your forms to match what you have in your $_POST vars

change the name of these below to match your form field names.

Expand|Select|Wrap|Line Numbers
  1.  $memberID = $_POST['memberID'];
  2.  $institution = $_POST['institution'];
  3.  $address1 = $_POST['address_1']; 
  4.  $address2 = $_POST['address_2'];
  5.  $city = $_POST['city'];
  6.  $state = $_POST['state'];
  7.  $zipCode = $_POST['zip'];
  8.  $website = $_POST['website'];
  9.  $contactName = $_POST['contactName'];
  10.  $position = $_POST['position'];
  11.  $phoneNumber = $_POST['phone'];
  12.  $email = $_POST['email'];
  13.  
Aug 3 '09 #64
The form= the table in mysql? or the form= what is on the website on http://mideasthonors.org/addmember.php?????
Aug 4 '09 #65
OOOOOKKKKK! So I have redone the scripting, ALL of it! And I think I did it...but now I am getting an unexpected end!!!!

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <? 
  2. // OPEN CONNECTION ---> 
  3. include ("admintasks-dbcon.php");
  4. mysql_connect($hostname,$username,$password);
  5. mysql_select_db($dbname) or die( "Unable to select database");
  6. $sql = "SELECT * FROM addMember WHERE email = '{$email}'";
  7. $res = mysql_query( $sql ) or die( mysql_error );
  8.  
  9. function protect ($VALUE){
  10. $VALUE = mysql_real_escape_string ($VALUE);
  11. $VALUE = stripslashes (VALUE);
  12. }
  13. $institution_name = $_POST['institution_name'];
  14. $address_1 = $_POST['address_1']; 
  15. $address_2 = $_POST['address_2'];
  16. $city = $_POST['city'];
  17. $state = $_POST['state'];
  18. $zip_code = $_POST['zip_code'];
  19. $website = $_POST['website'];
  20. $contact_name = $_POST['contact_name'];
  21. $position = $_POST['position'];
  22. $phone_number = $_POST['phone_number'];
  23. $email = $_POST['email'];
  24. protect ($institution_name);
  25. protect ($address_1);
  26. protect ($address_2);
  27. protect ($city);
  28. protect ($state);
  29. protect ($zip_code);
  30. protect ($website);
  31. protect ($contact_name);
  32. protect ($position);
  33. protect ($phone_number);
  34. protect ($email);
  35.  
  36.     if(Isset($institution_name) && Isset($address_1) && Isset($address_2) 
  37.     && Isset($city) && Isset($state) && Isset($zip_code) && Isset($website) && Isset($contact_name)
  38.     && Isset($position) && Isset($phone_number) && Isset($email)){
  39.  
  40.  
  41. $sql = "SELECT * FROM addMember WHERE institution_name = '$institution_name'";
  42. $res = mysql_query( $sql ) or die( mysql_error());
  43. if ( mysql_num_rows( $res ) > 0 ){
  44. echo "This instituion is already a member!";
  45. }else{
  46. $sql = "SELECT * FROM addMember WHERE email= '$email'";
  47. $res = mysql_query( $sql ) or die( mysql_error());
  48. if ( mysql_num_rows( $res ) > 0 ){
  49. }else{
  50. $sql = "INSERT INTO addMember(
  51. institution_name, 
  52. address_1, 
  53. address_2, 
  54. city, state,
  55. zip_code, 
  56. website, 
  57. contact_name, 
  58. position, 
  59. phone_number, 
  60. email
  61. )
  62. VALUES (
  63. '$instituion_name',
  64. '$address_1',
  65. '$address_2',
  66. '$city',
  67. '$state',
  68. '$zip_code',
  69. '$website',
  70. '$contact_name',
  71. '$position',
  72. '$phone_number',
  73. '$email'
  74. );";
  75. $res = mysql_query ($sql) or die(mysql_error());
  76.  
  77.  
  78.  
  79. session_start();
  80. $_SESSION["contactName"] = $contactName;
  81. header("location:alreadyMember.php");
  82.  
  83.  
  84.  
  85.  
  86. session_start();
  87. $_SESSION["contactName"] = $contactName;
  88. header("location:thankyouforbecomingamember.php");
  89. }
  90.  
  91. mysql_close();
  92. // CLOSE CONNECTION --->
  93. ?>
  94.  
Here is my table:
CREATE TABLE `addMember` (
`id` int(6) NOT NULL auto_increment,
`memberID` int(12) NOT NULL default '0',
`institution_name` varchar(45) NOT NULL default '',
`address_1` varchar(45) NOT NULL default '',
`address_2` varchar(45) NOT NULL default '',
`city` varchar(45) NOT NULL default '',
`state` char(2) NOT NULL default '',
`zip_code` int(10) NOT NULL default '0',
`website` text NOT NULL,
`contact_name` varchar(45) NOT NULL default '',
`position` varchar(25) NOT NULL default '',
`phone_number` int(12) NOT NULL default '0',
`email` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `addMember`
--

INSERT INTO `addMember` VALUES(1, 0, '', '', '', '', 'Il', 0, 'http://www.', '', '', 0, '');
Aug 4 '09 #66
Markus
6,050 Expert 4TB
You have neglected to complete one of your conditional statements, and I can see why - you format your code terribly, or should I say you don't format your code at all. Formatting maintains the readability of code, and thus the prevention and debugging of errors is greatly helped.

See for yourself:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. // OPEN CONNECTION --->
  3. include ("admintasks-dbcon.php");
  4. mysql_connect($hostname, $username, $password);
  5. mysql_select_db($dbname) or die("Unable to select database");
  6. $sql = "SELECT * FROM addMember WHERE email = '{$email}'";
  7. $res = mysql_query($sql) or die(mysql_error);
  8.  
  9. function protect($VALUE) {
  10.     $VALUE = mysql_real_escape_string($VALUE);
  11.     $VALUE = stripslashes(VALUE);
  12. }
  13. $institution_name = $_POST['institution_name'];
  14. $address_1 = $_POST['address_1'];
  15. $address_2 = $_POST['address_2'];
  16. $city = $_POST['city'];
  17. $state = $_POST['state'];
  18. $zip_code = $_POST['zip_code'];
  19. $website = $_POST['website'];
  20. $contact_name = $_POST['contact_name'];
  21. $position = $_POST['position'];
  22. $phone_number = $_POST['phone_number'];
  23. $email = $_POST['email'];
  24. protect($institution_name);
  25. protect($address_1);
  26. protect($address_2);
  27. protect($city);
  28. protect($state);
  29. protect($zip_code);
  30. protect($website);
  31. protect($contact_name);
  32. protect($position);
  33. protect($phone_number);
  34. protect($email);
  35.  
  36. if (Isset($institution_name) && Isset($address_1) && Isset($address_2) && Isset($city) && Isset($state) && Isset($zip_code) && Isset($website) && Isset($contact_name) && Isset($position) && Isset($phone_number) && Isset($email)) {
  37.  
  38.  
  39.     $sql = "SELECT * FROM addMember WHERE institution_name = '$institution_name'";
  40.     $res = mysql_query($sql) or die(mysql_error());
  41.     if (mysql_num_rows($res) > 0) {
  42.         echo "This instituion is already a member!";
  43.     } else {
  44.         $sql = "SELECT * FROM addMember WHERE email= '$email'";
  45.         $res = mysql_query($sql) or die(mysql_error());
  46.         if (mysql_num_rows($res) > 0) {
  47.         } else {
  48.             $sql = "INSERT INTO addMember(
  49. institution_name, 
  50. address_1, 
  51. address_2, 
  52. city, state,
  53. zip_code, 
  54. website, 
  55. contact_name, 
  56. position, 
  57. phone_number, 
  58. email
  59. )
  60. VALUES (
  61. '$instituion_name',
  62. '$address_1',
  63. '$address_2',
  64. '$city',
  65. '$state',
  66. '$zip_code',
  67. '$website',
  68. '$contact_name',
  69. '$position',
  70. '$phone_number',
  71. '$email'
  72. );";
  73.             $res = mysql_query($sql) or die(mysql_error());
  74.  
  75.  
  76.             session_start();
  77.             $_SESSION["contactName"] = $contactName;
  78.             header("location:alreadyMember.php");
  79.  
  80.  
  81.             session_start();
  82.             $_SESSION["contactName"] = $contactName;
  83.             header("location:thankyouforbecomingamember.php");
  84.         }
  85.  
  86.     // Just by the level of indentation, you can tell the closing '}'
  87.     // should be around this point.
  88.  
  89.         mysql_close();
  90.         // CLOSE CONNECTION --->
  91.  
  92. ?>
  93.  
Aug 4 '09 #67
my scripting looks nothing like what you posted, how the heck did it come out like that?!
Aug 5 '09 #68
Markus
6,050 Expert 4TB
@mideastgirl
I formatted it in my IDE (Aptana Studio with PHP plugin).

Formatting your code is a big part of writing it - it increases readability and thus maintainence is much easier.
Aug 5 '09 #69
Gotcha! I added the extra } because you were right I was missing some. However now instead of the unexpected $end I am just getting a blank page:( It is not going on to the next page that says thank you for becoming a member?!

Any ideas on that?
Aug 5 '09 #70
Markus
6,050 Expert 4TB
Nothing jumps out at me - try some debugging.

When you're using conditional statements, it's always beneficial, in terms of debugging, to know which conditionals fail, and which don't. You can then determine where your script has been, and where it ended.

Try the following and see if you get any output (we're looking for either 'not going to thank you', or 'going to thank you'). From there, we can narrow down the causes of your problem.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. // OPEN CONNECTION --->
  4. include ("admintasks-dbcon.php");
  5. mysql_connect($hostname, $username, $password);
  6. mysql_select_db($dbname) or die("Unable to select database");
  7. $sql = "SELECT * FROM addMember WHERE email = '{$email}'";
  8. $res = mysql_query($sql) or die(mysql_error);
  9.  
  10. function protect($VALUE) {
  11.     $VALUE = mysql_real_escape_string($VALUE);
  12.     $VALUE = stripslashes(VALUE);
  13. }
  14. $institution_name = $_POST['institution_name'];
  15. $address_1 = $_POST['address_1'];
  16. $address_2 = $_POST['address_2'];
  17. $city = $_POST['city'];
  18. $state = $_POST['state'];
  19. $zip_code = $_POST['zip_code'];
  20. $website = $_POST['website'];
  21. $contact_name = $_POST['contact_name'];
  22. $position = $_POST['position'];
  23. $phone_number = $_POST['phone_number'];
  24. $email = $_POST['email'];
  25. protect($institution_name);
  26. protect($address_1);
  27. protect($address_2);
  28. protect($city);
  29. protect($state);
  30. protect($zip_code);
  31. protect($website);
  32. protect($contact_name);
  33. protect($position);
  34. protect($phone_number);
  35. protect($email);
  36.  
  37. if (Isset($institution_name) && Isset($address_1) && Isset($address_2) && Isset($city) && Isset($state) && Isset($zip_code) && Isset($website) && Isset($contact_name) && Isset($position) && Isset($phone_number) && Isset($email)) {
  38.  
  39.  
  40.     $sql = "SELECT * FROM addMember WHERE institution_name = '$institution_name'";
  41.     $res = mysql_query($sql) or die(mysql_error());
  42.     if (mysql_num_rows($res) > 0) {
  43.         echo "This instituion is already a member!";
  44.     } else {
  45.         $sql = "SELECT * FROM addMember WHERE email= '$email'";
  46.         $res = mysql_query($sql) or die(mysql_error());
  47.         if (mysql_num_rows($res) > 0) {
  48.             echo "not going to thank you - institution name already exists';
  49.         } else {
  50.             echo 'going to thank you - institution name doesn\'t exist';
  51.             $sql = "INSERT INTO addMember(
  52. institution_name, 
  53. address_1, 
  54. address_2, 
  55. city, state,
  56. zip_code, 
  57. website, 
  58. contact_name, 
  59. position, 
  60. phone_number, 
  61. email
  62. )
  63. VALUES (
  64. '$instituion_name',
  65. '$address_1',
  66. '$address_2',
  67. '$city',
  68. '$state',
  69. '$zip_code',
  70. '$website',
  71. '$contact_name',
  72. '$position',
  73. '$phone_number',
  74. '$email'
  75. );";
  76.             $res = mysql_query($sql) or die(mysql_error());
  77.  
  78.  
  79.             session_start();
  80.             $_SESSION["contactName"] = $contactName;
  81.             header("location:alreadyMember.php");
  82.  
  83.  
  84.             session_start();
  85.             $_SESSION["contactName"] = $contactName;
  86.             header("location:thankyouforbecomingamember.php");
  87.         }
  88.  
  89.     // Just by the level of indentation, you can tell the closing '}'
  90.     // should be around this point.
  91.  
  92.         mysql_close();
  93.         // CLOSE CONNECTION --->
  94.  
  95. ?>
Aug 5 '09 #71

Post your reply

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

Similar topics

4 posts views Thread by danaf | last post: by
7 posts views Thread by John Paul | last post: by
9 posts views Thread by Paul | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.