473,554 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with scripting to store data on MySQL

mideastgirl
65 New Member
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 #1
70 5319
Dormilich
8,658 Recognized Expert Moderator Expert
the script seems somewhat strange...
  • is $add_member really the MySQL field name? (single quotes ain't parsed)
  • same goes for $row['$yourfield'].
  • why do you need to insert the form values for every already existing member?
  • you need protection against SQL injection (at least use mysql_real_esca pe_string($_POS T[$key])!)
you can forward to another page by
Expand|Select|Wrap|Line Numbers
  1. header('Location: _url_comes_here_');
  2. exit;
note: there must not be any output before that.
Jul 22 '09 #2
mideastgirl
65 New Member
No add_member is the table name. I thought that was supposed to go there. Also, the table is not for existing members it is for new members.

Maybe I am confused about what needs to go where.

Thanks.
Jul 22 '09 #3
Atli
5,058 Recognized Expert Expert
Hi.

The problem there is just with the basic syntax.

First, as Dormilich pointed out, while variables are parse within double-quoted strings, they are not parsed within single-quoted strings.
(See PHP: Strings - Manual)

Which means your query on line #6 is literally being sent as:
SELECT * FROM $add_member, whereas you probably meant for it to insert the value of $add_member.
If you want that to happen, you need to use double-quotes, rather than single-quotes.

And second:
The if statement on line #9, which checks the result of the SQL query, does not provide any code in case the check fails. Which means that every time the query fails, you are shown a blank page.
You should add an else clause, and print an error message or something, just so you don't get a useless blank page.
Jul 22 '09 #4
anfetienne
424 Contributor
the 1st sql query is relevant if you want to check for duplicate entries. but i dont see why you have a while loop in the when you can check if using

if ( mysql_num_rows( $res ) > 0 )
{
UPDATE table
}

else{
INSERT INTO table
}

look at this example that i have of a form and the php to add it to sql (please excuse the length of the form there is alot of javascript for tinyMCE included in my form)

FORM CODE
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="POST" action="save.php">
  2.         <tr>
  3.         <td>  
  4.   <input type="hidden" name="rtrnURL" id="rtrnURL" value='<?php print $rtrnURL;?>'/>      
  5.   <input type="hidden" name="tempID" id="tempID" value='<?php print $random_digit;?>'/> 
  6.   <input type="hidden" name="htmlcss" id="htmlcss" value='<?php print $htmlcss;?>'/>      
  7.   <input type="hidden" name="header" id="header" value='<?php print $header;?>'/>
  8.   <input type="hidden" name="nav" id="nav" value='<?php print $nav;?>'/>      
  9.   <input type="hidden" name="titleWrap01" id="titleWrap01" value='<?php print $titleWrap01;?>'/> 
  10.   <input type="hidden" name="titleWrap02" id="titleWrap02" value='<?php print $titleWrap02;?>'/>      
  11.   <input type="hidden" name="subheadWrap01" id="subheadWrap01" value='<?php print $subheadWrap01;?>'/>
  12.   <input type="hidden" name="subheadWrap02" id="subheadWrap02" value='<?php print $subheadWrap02;?>'/>      
  13.   <input type="hidden" name="flashWrap01" id="flashWrap01" value='<?php print $flashWrap01;?>'/> 
  14.   <input type="hidden" name="flashWrap02" id="flashWrap02" value='<?php print $flashWrap02;?>'/>      
  15.   <input type="hidden" name="flash01" id="flash01" value='var so = new SWFObject("<?php print $flashURL;?>", "gallery", "518", "536", "8", "#FFFFFF");'/>
  16.   <input type="hidden" name="flashVar" id="flashVar" value='<?php print $flashVar;?>'/>      
  17.   <input type="hidden" name="flash02" id="flash02" value='<?php print $flash02;?>'/> 
  18.   <input type="hidden" name="flashWrap03" id="flashWrap03" value='<?php print $flashWrap03;?>'/>
  19.   <input type="hidden" name="descriptionWrap01" id="descriptionWrap01" value='<?php print $descriptionWrap01;?>'/>
  20.   <input type="hidden" name="descriptionWrap02" id="descriptionWrap02" value='<?php print $descriptionWrap02;?>'/>      
  21.   <input type="hidden" name="generalWrap01" id="generalWrap01" value='<?php print $generalWrap01;?>'/> 
  22.   <input type="hidden" name="generalWrap02" id="generalWrap02" value='<?php print $generalWrap02;?>'/>      
  23.   <input type="hidden" name="aboutWrap01" id="aboutWrap01" value='<?php print $aboutWrap01;?>'/>
  24.   <input type="hidden" name="aboutWrap02" id="aboutWrap02" value='<?php print $aboutWrap02;?>'/>      
  25.   <input type="hidden" name="paymentWrap01" id="paymentWrap01" value='<?php print $paymentWrap01;?>'/> 
  26.   <input type="hidden" name="paymentWrap02" id="paymentWrap02" value='<?php print $paymentWrap02;?>'/>
  27.   <input type="hidden" name="termsWrap01" id="termsWrap01" value='<?php print $termsWrap01;?>'/>      
  28.   <input type="hidden" name="termsWrap02" id="termsWrap02" value='<?php print $termsWrap02;?>'/>
  29.   <input type="hidden" name="footer" id="footer" value='<?php print $footer;?>'/> 
  30.   </td>
  31.       </tr>
  32.  
  33.     <table width="700" border="0" align="center" cellpadding="2" cellspacing="2">
  34.       <tr>
  35.           <p>
  36.           <center><input name="Submit2" type="submit" value="Save Template" />
  37.             <br />
  38.           </center>
  39.           </p>
  40.       </tr>
  41.       <tr>
  42.         <td>Title</td>
  43.         <td><input name="title"  type="text" value="<? print $row['title'];?>" size="75" maxlength="60" /></td>
  44.       </tr>
  45.       <tr>
  46.         <td>Subtitle</td>
  47.         <td><input name="subheading"  type="text" value="<? print $row['subheading'];?>" size="75" /></td>
  48.       </tr>
  49.       <tr>
  50.         <td>Description</td>
  51.             <script type="text/javascript">
  52.                             tinyMCE.init({
  53.                                 mode : "exact"
  54.                                 ,elements : "id_description"
  55.                                 ,theme : "advanced"
  56.                                 ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
  57.                                 ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
  58.                                 ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
  59.                                 ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
  60.                                 ,theme_advanced_toolbar_location : "top"
  61.                                 ,theme_advanced_toolbar_align : "left"
  62.                                 ,theme_advanced_statusbar_location : "bottom"
  63.                                 ,theme_advanced_resizing : true
  64.                                 ,theme_advanced_resize_horizontal : false
  65.                                 ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
  66.                             });
  67.                         </script>
  68.         <td><textarea name="description" cols="75" id="id_description" style="width:450px; height:350px;"><? echo $row['description'];?></textarea></td>
  69.       </tr>
  70.       <tr>
  71.         <td>General Information</td>
  72.             <script type="text/javascript">
  73.                             tinyMCE.init({
  74.                                 mode : "exact"
  75.                                 ,elements : "id_general"
  76.                                 ,theme : "advanced"
  77.                                 ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
  78.                                 ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
  79.                                 ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
  80.                                 ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
  81.                                 ,theme_advanced_toolbar_location : "top"
  82.                                 ,theme_advanced_toolbar_align : "left"
  83.                                 ,theme_advanced_statusbar_location : "bottom"
  84.                                 ,theme_advanced_resizing : true
  85.                                 ,theme_advanced_resize_horizontal : false
  86.                                 ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
  87.                             });
  88.                         </script>
  89.         <td><textarea style="width:450px; height:350px;" id="id_general" name="general"><? echo $row['general'];?></textarea></td>
  90.       </tr>
  91.       <tr>
  92.         <td>Terms &amp; Conditions</td>
  93.             <script type="text/javascript">
  94.                             tinyMCE.init({
  95.                                 mode : "exact"
  96.                                 ,elements : "id_terms"
  97.                                 ,theme : "advanced"
  98.                                 ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
  99.                                 ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
  100.                                 ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
  101.                                 ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
  102.                                 ,theme_advanced_toolbar_location : "top"
  103.                                 ,theme_advanced_toolbar_align : "left"
  104.                                 ,theme_advanced_statusbar_location : "bottom"
  105.                                 ,theme_advanced_resizing : true
  106.                                 ,theme_advanced_resize_horizontal : false
  107.                                 ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
  108.                             });
  109.  
  110.                         </script>
  111.         <td><textarea style="width:450px; height:350px;" id="id_terms" name="terms"><? echo $row['terms'];?></textarea></td>
  112.       </tr>
  113.       <tr>
  114.         <td>About Us</td>
  115.         <script type="text/javascript">
  116.                             tinyMCE.init({
  117.                                 mode : "exact"
  118.                                 ,elements : "id_about"
  119.                                 ,theme : "advanced"
  120.                                 ,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
  121.                                 ,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
  122.                                 ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
  123.                                 ,theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,|,forecolor,backcolor"
  124.                                 ,theme_advanced_toolbar_location : "top"
  125.                                 ,theme_advanced_toolbar_align : "left"
  126.                                 ,theme_advanced_statusbar_location : "bottom"
  127.                                 ,theme_advanced_resizing : true
  128.                                 ,theme_advanced_resize_horizontal : false
  129.                                 ,plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups"
  130.                             });
  131.                         </script>
  132.         <td><textarea style="width:450px; height:350px;" id="id_about" name="about"><? echo $row['about'];?></textarea></td>
  133.       </tr>
  134.       <tr>
  135.         <td>Payment Methods</td>
  136.         <td><table width="192" border="0" cellspacing="0" cellpadding="0">
  137.             <tr>
  138.               <td width="134">&nbsp;</td>
  139.               <td width="58">&nbsp;</td>
  140.             </tr>
  141.             <tr>
  142.               <td>PayPal </td>
  143.               <td><input type="checkbox" name="payment01" id="payment01" value="<img src=http://theauctionwinners.com/resources/temp/paypal.gif>"/></td>
  144.             </tr>
  145.             <tr>
  146.               <td>Personal Cheques </td>
  147.               <td><input type="checkbox" name="payment02" id="payment02" value="<img src=http://theauctionwinners.com/resources/temp/cheque.gif>"/></td>
  148.             </tr>
  149.           </table></td>
  150.       </tr>
  151.       <tr>
  152.         <td colspan="2"><div align="center">
  153.           <p>
  154.         <center>  <input name="Submit" type="submit" value="Save Template" />
  155.           </form>
  156.  
DATABASE PAGE
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $username="username";
  3. $password="password";
  4. $database="database";
  5.  
  6. $rtrnURL = $_POST['rtrnURL'];
  7. $tempID = $_POST['tempID'];
  8. $htmlcss = $_POST['htmlcss'];
  9. $header = $_POST['header'];
  10. $nav = $_POST['nav'];
  11. $titleWrap01 = $_POST['titleWrap01'];
  12. $title = $_POST['title'];
  13. $titleWrap02 = $_POST['titleWrap02'];
  14. $subheadWrap01 = $_POST['subheadWrap01'];
  15. $subheading = $_POST['subheading'];
  16. $subheadWrap02 = $_POST['subheadWrap02'];
  17. $flashWrap01 = $_POST['flashWrap01'];
  18. $flashWrap02 = $_POST['flashWrap02'];
  19. $flash01 = $_POST['flash01'];
  20. $flashVar = $_POST['flashVar'];
  21. $flash02 = $_POST['flash02'];
  22. $flashWrap03 = $_POST['flashWrap03'];
  23. $descriptionWrap01 = $_POST['descriptionWrap01'];
  24. $description = $_POST['description'];
  25. $descriptionWrap02 = $_POST['descriptionWrap02'];
  26. $generalWrap01 = $_POST['generalWrap01'];
  27. $general = $_POST['general'];
  28. $generalWrap02 = $_POST['generalWrap02'];
  29. $aboutWrap01 = $_POST['aboutWrap01'];
  30. $about = $_POST['about'];
  31. $aboutWrap02 = $_POST['aboutWrap02'];
  32. $paymentWrap01 = $_POST['paymentWrap01'];
  33. $payment01 = $_POST['payment01'];
  34. $payment02 = $_POST['payment02'];
  35. $paymentWrap02 = $_POST['paymentWrap02'];
  36. $termsWrap01 = $_POST['termsWrap01'];
  37. $terms = $_POST['terms'];
  38. $termsWrap02 = $_POST['termsWrap02'];
  39. $footer = $_POST['footer'];
  40.  
  41. // OPEN CONNECTION ---> 
  42. $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
  43.  
  44. mysql_select_db("$database") or die("Unable to select database!");
  45.  
  46. // Select column 1 from table name where column name = $your_var.
  47. $sql = "SELECT * FROM savedTemps WHERE tempID = '{$tempID}'";
  48. // If mysql_query returns false, we'll die with the error.
  49. $res = mysql_query( $sql ) or die( mysql_error );
  50.  
  51. // If a there is a match
  52. if ( mysql_num_rows( $res ) > 0 )
  53. {
  54.  
  55. $query="
  56.  
  57. UPDATE savedTemps SET 
  58.  
  59.             htmlcss='{$htmlcss}', 
  60.             header='{$header}', 
  61.             nav='{$nav}', 
  62.             titleWrap01='{$titleWrap01}', 
  63.             title='{$title}',
  64.             titleWrap02='{$titleWrap02}',
  65.             subheadWrap01='{$subheadWrap01}', 
  66.             subheading='{$subheading}',
  67.             subheadWrap02='{$subheadWrap02}', 
  68.             flashWrap01='{$flashWrap01}',     
  69.             flashWrap02='{$flashWrap02}', 
  70.             flash01='{$flash01}', 
  71.             flashVar='{$flashVar}',
  72.             flash02='{$flash02}', 
  73.             flashWrap03='{$flashWrap03}',
  74.             descriptionWrap01='{$descriptionWrap01}',
  75.             description='{$description}', 
  76.             descriptionWrap02='{$descriptionWrap02}',
  77.             generalWrap01='{$generalWrap01}', 
  78.             general='{$general}', 
  79.             generalWrap02='{$generalWrap02}', 
  80.             aboutWrap01='{$aboutWrap01}',
  81.             about='{$about}', 
  82.             aboutWrap02='{$aboutWrap02}',
  83.             paymentWrap01='{$paymentWrap01}', 
  84.             payment01='{$payment01}', 
  85.             payment02='{$payment02}', 
  86.             paymentWrap02='{$paymentWrap02}',
  87.             termsWrap01='{$termsWrap01}', 
  88.             terms='{$terms}', 
  89.             termsWrap02='{$termsWrap02}',
  90.             footer='{$footer}'
  91.  
  92.             WHERE tempID='{$tempID}'";
  93. }
  94. else
  95. {
  96. //  EXECUTE QUERY ---> 
  97. $query="INSERT savedTemps (
  98.  
  99.             tempID, 
  100.             htmlcss, 
  101.             header, 
  102.             nav, 
  103.             titleWrap01, 
  104.             title,
  105.             titleWrap02,
  106.             subheadWrap01, 
  107.             subheading,
  108.             subheadWrap02, 
  109.             flashWrap01,     
  110.             flashWrap02, 
  111.             flash01, 
  112.             flashVar,
  113.             flash02, 
  114.             flashWrap03,
  115.             descriptionWrap01,
  116.             description, 
  117.             descriptionWrap02,
  118.             generalWrap01, 
  119.             general, 
  120.             generalWrap02, 
  121.             aboutWrap01,
  122.             about, 
  123.             aboutWrap02,
  124.             paymentWrap01, 
  125.             payment01, 
  126.             payment02, 
  127.             paymentWrap02,
  128.             termsWrap01, 
  129.             terms, 
  130.             termsWrap02,
  131.             footer)
  132.  
  133.         VALUES(    
  134.             '".$tempID."', 
  135.             '".$htmlcss."', 
  136.             '".$header."', 
  137.             '".$nav."', 
  138.             '".$titleWrap01."', 
  139.             '".$title."',
  140.             '".$titleWrap02."',
  141.             '".$subheadWrap01."', 
  142.             '".$subheading."',
  143.             '".$subheadWrap02."', 
  144.             '".$flashWrap01."',     
  145.             '".$flashWrap02."', 
  146.             '".$flash01."', 
  147.             '".$flashVar."', 
  148.             '".$flash02."', 
  149.             '".$flashWrap03."',
  150.             '".$descriptionWrap01."',
  151.             '".$description."', 
  152.             '".$descriptionWrap02."',
  153.             '".$generalWrap01."', 
  154.             '".$general."', 
  155.             '".$generalWrap02."', 
  156.             '".$aboutWrap01."',
  157.             '".$about."', 
  158.             '".$aboutWrap02."',
  159.             '".$paymentWrap01."', 
  160.             '".$payment01."', 
  161.             '".$payment02."', 
  162.             '".$paymentWrap02."',
  163.             '".$termsWrap01."', 
  164.             '".$terms."', 
  165.             '".$termsWrap02."',
  166.             '".$footer."')";
  167. }
  168.  
  169.  
  170. //////-----> 
  171. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  172. //if ($result) 
  173.     //echo mysql_affected_rows()." row inserted into the database effectively."; 
  174.  
  175. //  CLOSE CONNECTION ---> 
  176. mysql_close($connection); 
  177.  
  178. /////////////////////////////////////////////////////////////////////////////////// 
  179.  
  180. ?>
  181.  
Jul 22 '09 #5
mideastgirl
65 New Member
Thank you both for your help!

I think I was able to progress! But there still seems to be a glitch somewhere, because I keep getting the mysql error message now???

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( $sql ) or die( mysql_error );
  8. if ( mysql_num_rows( $res ) > 0 )
  9. $query="
  10. UPDATE $add_member
  11. {
  12. else{
  13. INSERT INTO $add_member
  14. }
  15. (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address) 
  16. 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']})";
  17.  
  18. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  19. if ($result) 
  20. echo mysql_affected_rows()." row inserted into the database effectively."; 
  21.  
  22. mysql_close($connection); 
  23. }
  24. ?>
  25.  
I also need the page to go onto a thank you page or an error page if all of the information has not been entered. I know that I would use header("Locatio n: page name");

but where would I put this???
Jul 23 '09 #6
anfetienne
424 Contributor
ok....well for starters you haven't set anything to the UPDATE i.e.

Expand|Select|Wrap|Line Numbers
  1. UPDATE savedTemps SET 
  2.  
  3. htmlcss='{$htmlcss}', 
  4. header='{$header}', 
  5. nav='{$nav}', 
  6. titleWrap01='{$titleWrap01}', 
  7. title='{$title}',
  8. titleWrap02='{$titleWrap02}',
  9. subheadWrap01='{$subheadWrap01}', 
  10. subheading='{$subheading}',
  11. subheadWrap02='{$subheadWrap02}', 
  12. flashWrap01='{$flashWrap01}',     
  13. flashWrap02='{$flashWrap02}', 
  14. flash01='{$flash01}', 
  15. flashVar='{$flashVar}',
  16. flash02='{$flash02}', 
  17. flashWrap03='{$flashWrap03}',
  18. descriptionWrap01='{$descriptionWrap01}',
  19. description='{$description}', 
  20. descriptionWrap02='{$descriptionWrap02}',
  21. generalWrap01='{$generalWrap01}', 
  22. general='{$general}', 
  23. generalWrap02='{$generalWrap02}', 
  24. aboutWrap01='{$aboutWrap01}',
  25. about='{$about}', 
  26. aboutWrap02='{$aboutWrap02}',
  27. paymentWrap01='{$paymentWrap01}', 
  28. payment01='{$payment01}', 
  29. payment02='{$payment02}', 
  30. paymentWrap02='{$paymentWrap02}',
  31. termsWrap01='{$termsWrap01}', 
  32. terms='{$terms}', 
  33. termsWrap02='{$termsWrap02}',
  34. footer='{$footer}'
  35.  
  36. WHERE tempID='{$tempID}'";
  37.  
and you have sql coding in the wrong place.....bare with me a sec
Jul 23 '09 #7
anfetienne
424 Contributor
try this....i've seperated it all so you can see clearer what i've done.

also maybe you should think about giving people a member ID it would be easier to update table fields using it since it's the only item that doesn't and maybe won't change....or a username???

a random digit is good for memberID, put it on the page where the form is and include it in a hidden field in your form like this:

MEMBER ID
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $memberID=rand(0000000,9999999);
  3. ?>
  4.  
  5. <input type="hidden" name="memberID" id="memberID" value="<?php print $memberID;?>" /> 
  6.  
FULL CODE
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 WHERE memberID = '{$memberID}'";
  7. $result = mysql_query( $sql ) or die( mysql_error );
  8.  
  9. if ( mysql_num_rows( $res ) > 0 )
  10. //and here you had no data specified or fields specified
  11.  
  12. $query="
  13. UPDATE $add_member SET
  14.             name = '{$_POST['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 Address = '{$_POST['email address']}')
  25.  
  26.             WHERE memberID ='{$memberID}'";
  27. {
  28. else{
  29. //in this section you had the following...your sql wasn't inside the loop and also there was no $query=""
  30.  
  31. # INSERT INTO $add_member
  32. # }
  33. # (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address) 
  34. # 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']})";
  35. #  
  36. $query="
  37.  
  38. INSERT INTO $add_member (
  39.  
  40.             Member ID,    
  41.             Name,
  42.             Address 1,
  43.             Address 2,
  44.             City, 
  45.             State, 
  46.             Zip Code, 
  47.             Website, 
  48.             Contact Name, 
  49.             Position, 
  50.             Phone Number, 
  51.             Email Address)
  52.  
  53. VALUES 
  54.  
  55.             {$_POST['memberID']},
  56.             {$_POST['name']},
  57.             {$_POST['address 1']},
  58.             {$_POST['address 2']},
  59.             {$_POST['city']},
  60.             {$_POST['state']},
  61.             {$_POST['zip code']},
  62.             {$_POST['website']},
  63.             {$_POST['contact name']},
  64.             {$_POST['position']},
  65.             {$_POST['phone number']},
  66.             {$_POST['email address']})";
  67.  
  68. $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  69.  
  70. if ( mysql_num_rows( $result ) > 0 ) 
  71. echo mysql_affected_rows()." row inserted into the database effectively."; 
  72.  
  73. mysql_close(); 
  74. }
  75.  
  76. session_start();
  77. $_SESSION["Name"] = $_POST['name'];
  78. header("location:thankYou.php");
  79. ?>
  80.  
Jul 23 '09 #8
anfetienne
424 Contributor
and on your following page if you wanted to say

"Thank You (Member's Name),"

use this code to include it in

Expand|Select|Wrap|Line Numbers
  1. <?
  2. session_start();
  3. $Name = $_SESSION["Name"];
  4. ?>
  5.  
  6. //example
  7. "Thank You <?php print $Name;?>, for registering!"
  8.  
Jul 23 '09 #9
anfetienne
424 Contributor
also 1 question.....

in your config file is $add_member = add_member???
Jul 23 '09 #10

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

Similar topics

4
3000
by: danaf | last post by:
Dear all, (1)Is it possible to host PHP-based Web Portal + MySQL Database (e.g. PHPNuke) on MS Windows System? If yes which server software I need? (2)Compare PHP over JSP/ASP/CGI in performance/memory usage/others...which one is the best for a web portal targetted around few thousand concurrent users? Any article have detail comparisions...
12
7698
by: jacob nikom | last post by:
Hi, I would like to store XML files in MySQL. What is the best solution: 1. Convert it to string and store it as CLOB/text 2. Serialize it and store as byte array 3. Flatten it out and create one column per element, each column is VARCHAR Does MySQL has anything special for XML data? Is there any software which helps to store XML data...
6
5725
by: news | last post by:
I need some concise, easy to grok examples of what .Net (preferably C#.Net) has over just using old ASP or PHP with JavaScript. See, I'm a PHP guy, and while I started server-side scripting with ASP, I hate it. But last year I had the opportunity to work with a company that was developing sites in VB.Net. And I was wowed! The stuff they...
7
2036
by: John Paul | last post by:
I'm thinking of building an e-commerce site in php. Anyone got any advice in building one? What is the best way to implement a payment system? Are any legal issues involved? Thanks,
9
1597
by: Paul | last post by:
I have a process that I want to speed up. It first was written in Microsoft Access then converted to VB.NET. I would like to hear some suggestions on how to speed it up. The process is to match names using a Soundex function. It reads through a table of about 20,000 records and matches it with a table of about 9,000 records. That is all...
3
5604
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we want to give them the opportunity to run these modules from home as well, we are trying to get the USERNAME/COMPUTERNAME as well, so the students, when...
0
2434
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in the whole. I really need MySQL wizz to give me a hand (and maybe refer me to books to get me to the wizz level myself). First off, english is a...
20
4237
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black...
4
16916
by: hott5hotj | last post by:
I am trying to create an authentication using flash and AS3 as the underlying code using PHP as the server side scripting and mySQL to store the passwords. As I am a newbie I decided to start practicing using AS2 and tried to make the whole thing work. I could not get the flash interface to connect to the PHP to validate the database. I know that...
0
7521
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8042
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5155
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3560
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
841
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.