Need help with scripting to store data on MySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mideastgirl
    New Member
    • Jun 2009
    • 65

    Need help with scripting to store data on MySQL

    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:
    [code=php]
    <?php
    include ("admintasks-dbcon.php");
    mysql_connect($ hostname,$usern ame, $password) OR DIE ('Unable to connect to database! Please try again later.');
    mysql_select_db ($dbname);

    $query = 'SELECT * FROM $add_member';
    $result = mysql_query($qu ery);

    if($result)
    {
    while($row = mysql_fetch_arr ay($result))
    {
    $name = $row['$yourfield'];
    echo 'Name: '.$name;

    mysql_select_db ("mideasthonors ");

    $sql="INSERT INTO $add_member (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)
    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']})";

    if (!mysql_query($ sql,$con))
    {
    die('Error: ' . mysql_error());
    }

    echo 'Thank You! Your information has been entered into the database!';
    }
    }
    ?>
    [/code]

    This is the error page I have set up:
    [code=php]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Language" content="en-us" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Error</title>
    <style type="text/css">
    .style1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: medium;
    }

    .style29 {
    font-family: Arial, Helvetica, sans-serif;
    }
    h2 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 17px;
    font-weight: bold;
    color: #2F77F1;
    line-height: 20px;
    }
    .style30 {
    font-family: geneva, arial;
    font-size: 10pt;
    }

    .style31 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
    line-height: 11pt;
    margin: 3px 0;
    padding-bottom: 9px;
    }
    </style>
    </head>

    <body>

    <p class="style1"> <strong>Error : All fields have not been filled in, or information is inaccurate. Please complete form.</strong></p>
    <form method="post" action="addmemb er.php" style="width: 169px">
    *

    <table>

    <tr>
    <td colspan=2><h2 class="style29" >Institution Information</h2></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='name'>Name *</label></p></td>
    <td class="style30" ><input type='text' name='name' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='address_1' >Address*</label></p></td>
    <td class="style30" ><input type='text' name='address_1 ' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td class="style30" >&nbsp;</td>
    <td class="style30" ><input type='text' name='address_2 ' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='city'>City *</label></p></td>
    <td class="style30" ><input type='text' name='city' size=45 maxlength=50 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='state'>Sta te*</label>
    <td class="style30" >
    <select name='state'>
    <?php
    $states = array("Illinois ", "Indiana", "Kentucky", "Michigan", "Ohio", "Pennsylvan ia", "Tennessee" , "West Viriginia");
    foreach($states as $a => $value){
    echo "<option name='$value'>$ value</option>";
    }
    ?>
    </select>
    </td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='zip'>ZIP Code*</label></p></td>
    <td class="style30" ><input type='text' name='zip' size=10 maxlength=10 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='website'>W ebsite*</label></p></td>
    <td class="style30" ><input type='text' name='website' value='http://www.' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td colspan=2><h2 class="style29" >Contact Information</h2></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='contact_na me'>Contact Name*</label></p></td>
    <td class="style30" ><input type='text' name='contact_n ame' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='contact_po sition'>Positio n</label></p></td>
    <td class="style30" ><input type='text' name='contact_p osition' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='contact_ph one'>Phone Number*</label></p></td>
    <td class="style30" ><input type='text' name='contact_p hone' size=14 maxlength=14 /></td>
    </tr>

    <tr>
    <td class='style30' ><p class="style31" ><label for='contact_em ail'>Email Address*</label></p></td>
    <td class="style30" ><input type='text' name='contact_e mail' size=45 maxlength=100 /></td>
    </tr>

    <tr>
    <td class="style30" >&nbsp;</td>
    <td class="style30" ><input type='submit' name ="Add Member" value='Add Member' /></td>
    </tr>

    </table>

    [/code]

    If anyone could help me out I would really appreciate it!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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
    Code:
    header('Location: _url_comes_here_');
    exit;
    note: there must not be any output before that.

    Comment

    • mideastgirl
      New Member
      • Jun 2009
      • 65

      #3
      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.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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.

        Comment

        • anfetienne
          Contributor
          • Feb 2009
          • 424

          #5
          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
          Code:
          <form id="form1" name="form1" method="POST" action="save.php">
                  <tr>
                  <td>  
            <input type="hidden" name="rtrnURL" id="rtrnURL" value='<?php print $rtrnURL;?>'/>      
            <input type="hidden" name="tempID" id="tempID" value='<?php print $random_digit;?>'/> 
            <input type="hidden" name="htmlcss" id="htmlcss" value='<?php print $htmlcss;?>'/>      
            <input type="hidden" name="header" id="header" value='<?php print $header;?>'/>
            <input type="hidden" name="nav" id="nav" value='<?php print $nav;?>'/>      
            <input type="hidden" name="titleWrap01" id="titleWrap01" value='<?php print $titleWrap01;?>'/> 
            <input type="hidden" name="titleWrap02" id="titleWrap02" value='<?php print $titleWrap02;?>'/>      
            <input type="hidden" name="subheadWrap01" id="subheadWrap01" value='<?php print $subheadWrap01;?>'/>
            <input type="hidden" name="subheadWrap02" id="subheadWrap02" value='<?php print $subheadWrap02;?>'/>      
            <input type="hidden" name="flashWrap01" id="flashWrap01" value='<?php print $flashWrap01;?>'/> 
            <input type="hidden" name="flashWrap02" id="flashWrap02" value='<?php print $flashWrap02;?>'/>      
            <input type="hidden" name="flash01" id="flash01" value='var so = new SWFObject("<?php print $flashURL;?>", "gallery", "518", "536", "8", "#FFFFFF");'/>
            <input type="hidden" name="flashVar" id="flashVar" value='<?php print $flashVar;?>'/>      
            <input type="hidden" name="flash02" id="flash02" value='<?php print $flash02;?>'/> 
            <input type="hidden" name="flashWrap03" id="flashWrap03" value='<?php print $flashWrap03;?>'/>
            <input type="hidden" name="descriptionWrap01" id="descriptionWrap01" value='<?php print $descriptionWrap01;?>'/>
            <input type="hidden" name="descriptionWrap02" id="descriptionWrap02" value='<?php print $descriptionWrap02;?>'/>      
            <input type="hidden" name="generalWrap01" id="generalWrap01" value='<?php print $generalWrap01;?>'/> 
            <input type="hidden" name="generalWrap02" id="generalWrap02" value='<?php print $generalWrap02;?>'/>      
            <input type="hidden" name="aboutWrap01" id="aboutWrap01" value='<?php print $aboutWrap01;?>'/>
            <input type="hidden" name="aboutWrap02" id="aboutWrap02" value='<?php print $aboutWrap02;?>'/>      
            <input type="hidden" name="paymentWrap01" id="paymentWrap01" value='<?php print $paymentWrap01;?>'/> 
            <input type="hidden" name="paymentWrap02" id="paymentWrap02" value='<?php print $paymentWrap02;?>'/>
            <input type="hidden" name="termsWrap01" id="termsWrap01" value='<?php print $termsWrap01;?>'/>      
            <input type="hidden" name="termsWrap02" id="termsWrap02" value='<?php print $termsWrap02;?>'/>
            <input type="hidden" name="footer" id="footer" value='<?php print $footer;?>'/> 
            </td>
                </tr>
          
              <table width="700" border="0" align="center" cellpadding="2" cellspacing="2">
                <tr>
                    <p>
                    <center><input name="Submit2" type="submit" value="Save Template" />
                      <br />
                    </center>
                    </p>
                </tr>
                <tr>
                  <td>Title</td>
                  <td><input name="title"  type="text" value="<? print $row['title'];?>" size="75" maxlength="60" /></td>
                </tr>
                <tr>
                  <td>Subtitle</td>
                  <td><input name="subheading"  type="text" value="<? print $row['subheading'];?>" size="75" /></td>
                </tr>
                <tr>
                  <td>Description</td>
          			<script type="text/javascript">
          							tinyMCE.init({
          								mode : "exact"
          								,elements : "id_description"
          								,theme : "advanced"
          								,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
          								,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
          								,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
          								,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"
          								,theme_advanced_toolbar_location : "top"
          								,theme_advanced_toolbar_align : "left"
          								,theme_advanced_statusbar_location : "bottom"
          								,theme_advanced_resizing : true
          								,theme_advanced_resize_horizontal : false
          								,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"
          							});
          						</script>
                  <td><textarea name="description" cols="75" id="id_description" style="width:450px; height:350px;"><? echo $row['description'];?></textarea></td>
                </tr>
                <tr>
                  <td>General Information</td>
          			<script type="text/javascript">
          							tinyMCE.init({
          								mode : "exact"
          								,elements : "id_general"
          								,theme : "advanced"
          								,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
          								,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
          								,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
          								,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"
          								,theme_advanced_toolbar_location : "top"
          								,theme_advanced_toolbar_align : "left"
          								,theme_advanced_statusbar_location : "bottom"
          								,theme_advanced_resizing : true
          								,theme_advanced_resize_horizontal : false
          								,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"
          							});
          						</script>
                  <td><textarea style="width:450px; height:350px;" id="id_general" name="general"><? echo $row['general'];?></textarea></td>
                </tr>
                <tr>
                  <td>Terms &amp; Conditions</td>
          			<script type="text/javascript">
          							tinyMCE.init({
          								mode : "exact"
          								,elements : "id_terms"
          								,theme : "advanced"
          								,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
          								,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
          								,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
          								,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"
          								,theme_advanced_toolbar_location : "top"
          								,theme_advanced_toolbar_align : "left"
          								,theme_advanced_statusbar_location : "bottom"
          								,theme_advanced_resizing : true
          								,theme_advanced_resize_horizontal : false
          								,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"
          							});
          
          						</script>
                  <td><textarea style="width:450px; height:350px;" id="id_terms" name="terms"><? echo $row['terms'];?></textarea></td>
                </tr>
                <tr>
                  <td>About Us</td>
                  <script type="text/javascript">
          							tinyMCE.init({
          								mode : "exact"
          								,elements : "id_about"
          								,theme : "advanced"
          								,theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,formatselect,fontselect,fontsizeselect"
          								,theme_advanced_buttons2 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,|,image,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,code,fullscreen"
          								,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,"
          								,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"
          								,theme_advanced_toolbar_location : "top"
          								,theme_advanced_toolbar_align : "left"
          								,theme_advanced_statusbar_location : "bottom"
          								,theme_advanced_resizing : true
          								,theme_advanced_resize_horizontal : false
          								,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"
          							});
          						</script>
                  <td><textarea style="width:450px; height:350px;" id="id_about" name="about"><? echo $row['about'];?></textarea></td>
                </tr>
                <tr>
                  <td>Payment Methods</td>
                  <td><table width="192" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="134">&nbsp;</td>
                        <td width="58">&nbsp;</td>
                      </tr>
                      <tr>
                        <td>PayPal </td>
                        <td><input type="checkbox" name="payment01" id="payment01" value="<img src=http://theauctionwinners.com/resources/temp/paypal.gif>"/></td>
                      </tr>
                      <tr>
                        <td>Personal Cheques </td>
                        <td><input type="checkbox" name="payment02" id="payment02" value="<img src=http://theauctionwinners.com/resources/temp/cheque.gif>"/></td>
                      </tr>
                    </table></td>
                </tr>
                <tr>
                  <td colspan="2"><div align="center">
                    <p>
                  <center>  <input name="Submit" type="submit" value="Save Template" />
                    </form>
          DATABASE PAGE
          Code:
          <?php
          $username="username";
          $password="password";
          $database="database";
          
          $rtrnURL = $_POST['rtrnURL'];
          $tempID = $_POST['tempID'];
          $htmlcss = $_POST['htmlcss'];
          $header = $_POST['header'];
          $nav = $_POST['nav'];
          $titleWrap01 = $_POST['titleWrap01'];
          $title = $_POST['title'];
          $titleWrap02 = $_POST['titleWrap02'];
          $subheadWrap01 = $_POST['subheadWrap01'];
          $subheading = $_POST['subheading'];
          $subheadWrap02 = $_POST['subheadWrap02'];
          $flashWrap01 = $_POST['flashWrap01'];
          $flashWrap02 = $_POST['flashWrap02'];
          $flash01 = $_POST['flash01'];
          $flashVar = $_POST['flashVar'];
          $flash02 = $_POST['flash02'];
          $flashWrap03 = $_POST['flashWrap03'];
          $descriptionWrap01 = $_POST['descriptionWrap01'];
          $description = $_POST['description'];
          $descriptionWrap02 = $_POST['descriptionWrap02'];
          $generalWrap01 = $_POST['generalWrap01'];
          $general = $_POST['general'];
          $generalWrap02 = $_POST['generalWrap02'];
          $aboutWrap01 = $_POST['aboutWrap01'];
          $about = $_POST['about'];
          $aboutWrap02 = $_POST['aboutWrap02'];
          $paymentWrap01 = $_POST['paymentWrap01'];
          $payment01 = $_POST['payment01'];
          $payment02 = $_POST['payment02'];
          $paymentWrap02 = $_POST['paymentWrap02'];
          $termsWrap01 = $_POST['termsWrap01'];
          $terms = $_POST['terms'];
          $termsWrap02 = $_POST['termsWrap02'];
          $footer = $_POST['footer'];
          
          // OPEN CONNECTION ---> 
          $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
          
          mysql_select_db("$database") or die("Unable to select database!");
          
          // Select column 1 from table name where column name = $your_var.
          $sql = "SELECT * FROM savedTemps WHERE tempID = '{$tempID}'";
          // If mysql_query returns false, we'll die with the error.
          $res = mysql_query( $sql ) or die( mysql_error );
           
          // If a there is a match
          if ( mysql_num_rows( $res ) > 0 )
          {
          
          $query="
          
          UPDATE savedTemps SET 
          
          		    htmlcss='{$htmlcss}', 
                      header='{$header}', 
                      nav='{$nav}', 
                      titleWrap01='{$titleWrap01}', 
                      title='{$title}',
          			titleWrap02='{$titleWrap02}',
                      subheadWrap01='{$subheadWrap01}', 
                      subheading='{$subheading}',
          			subheadWrap02='{$subheadWrap02}', 
                      flashWrap01='{$flashWrap01}', 	
                      flashWrap02='{$flashWrap02}', 
                      flash01='{$flash01}', 
                      flashVar='{$flashVar}',
                      flash02='{$flash02}', 
                      flashWrap03='{$flashWrap03}',
          			descriptionWrap01='{$descriptionWrap01}',
                      description='{$description}', 
                      descriptionWrap02='{$descriptionWrap02}',
          			generalWrap01='{$generalWrap01}', 
                      general='{$general}', 
                      generalWrap02='{$generalWrap02}', 
          			aboutWrap01='{$aboutWrap01}',
                      about='{$about}', 
                      aboutWrap02='{$aboutWrap02}',
          			paymentWrap01='{$paymentWrap01}', 
                      payment01='{$payment01}', 
                      payment02='{$payment02}', 
                      paymentWrap02='{$paymentWrap02}',
                      termsWrap01='{$termsWrap01}', 
                      terms='{$terms}', 
                      termsWrap02='{$termsWrap02}',
          			footer='{$footer}'
          
          			WHERE tempID='{$tempID}'";
          }
          else
          {
          //  EXECUTE QUERY ---> 
          $query="INSERT savedTemps (
          
          		    tempID, 
          		    htmlcss, 
                      header, 
                      nav, 
                      titleWrap01, 
                      title,
          			titleWrap02,
                      subheadWrap01, 
                      subheading,
          			subheadWrap02, 
                      flashWrap01, 	
                      flashWrap02, 
                      flash01, 
                      flashVar,
                      flash02, 
                      flashWrap03,
          			descriptionWrap01,
                      description, 
                      descriptionWrap02,
          			generalWrap01, 
                      general, 
                      generalWrap02, 
          			aboutWrap01,
                      about, 
                      aboutWrap02,
          			paymentWrap01, 
                      payment01, 
                      payment02, 
                      paymentWrap02,
                      termsWrap01, 
                      terms, 
                      termsWrap02,
          			footer)
          
                  VALUES(	
          		    '".$tempID."', 
          		    '".$htmlcss."', 
                      '".$header."', 
                      '".$nav."', 
                      '".$titleWrap01."', 
                      '".$title."',
          			'".$titleWrap02."',
                      '".$subheadWrap01."', 
                      '".$subheading."',
          			'".$subheadWrap02."', 
                      '".$flashWrap01."', 	
                      '".$flashWrap02."', 
                      '".$flash01."', 
                      '".$flashVar."', 
                      '".$flash02."', 
                      '".$flashWrap03."',
          			'".$descriptionWrap01."',
                      '".$description."', 
                      '".$descriptionWrap02."',
          			'".$generalWrap01."', 
                      '".$general."', 
                      '".$generalWrap02."', 
          			'".$aboutWrap01."',
                      '".$about."', 
                      '".$aboutWrap02."',
          			'".$paymentWrap01."', 
                      '".$payment01."', 
                      '".$payment02."', 
                      '".$paymentWrap02."',
                      '".$termsWrap01."', 
                      '".$terms."', 
                      '".$termsWrap02."',
          			'".$footer."')";
          }
          
          			
          //////-----> 
          $result=mysql_query($query) or die("Error in query:".mysql_error()); 
          //if ($result) 
              //echo mysql_affected_rows()." row inserted into the database effectively."; 
          
          //  CLOSE CONNECTION ---> 
          mysql_close($connection); 
          
          /////////////////////////////////////////////////////////////////////////////////// 
          
          ?>

          Comment

          • mideastgirl
            New Member
            • Jun 2009
            • 65

            #6
            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???

            [code=php]
            <?php
            include ("admintasks-dbcon.php");
            mysql_connect($ hostname,$usern ame, $password) OR DIE ('Unable to connect to database! Please try again later.');
            mysql_select_db ($dbname);

            $query = "SELECT * FROM $add_member";
            $result = mysql_query( $sql ) or die( mysql_error );
            if ( mysql_num_rows( $res ) > 0 )
            {
            $query="
            UPDATE $add_member
            {
            else{
            INSERT INTO $add_member
            }
            (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)
            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']})";

            $result=mysql_q uery($query) or die("Error in query:".mysql_e rror());
            if ($result)
            echo mysql_affected_ rows()." row inserted into the database effectively.";

            mysql_close($co nnection);
            }
            ?>
            [/code]

            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???

            Comment

            • anfetienne
              Contributor
              • Feb 2009
              • 424

              #7
              ok....well for starters you haven't set anything to the UPDATE i.e.

              Code:
              UPDATE savedTemps SET 
              
              htmlcss='{$htmlcss}', 
              header='{$header}', 
              nav='{$nav}', 
              titleWrap01='{$titleWrap01}', 
              title='{$title}',
              titleWrap02='{$titleWrap02}',
              subheadWrap01='{$subheadWrap01}', 
              subheading='{$subheading}',
              subheadWrap02='{$subheadWrap02}', 
              flashWrap01='{$flashWrap01}', 	
              flashWrap02='{$flashWrap02}', 
              flash01='{$flash01}', 
              flashVar='{$flashVar}',
              flash02='{$flash02}', 
              flashWrap03='{$flashWrap03}',
              descriptionWrap01='{$descriptionWrap01}',
              description='{$description}', 
              descriptionWrap02='{$descriptionWrap02}',
              generalWrap01='{$generalWrap01}', 
              general='{$general}', 
              generalWrap02='{$generalWrap02}', 
              aboutWrap01='{$aboutWrap01}',
              about='{$about}', 
              aboutWrap02='{$aboutWrap02}',
              paymentWrap01='{$paymentWrap01}', 
              payment01='{$payment01}', 
              payment02='{$payment02}', 
              paymentWrap02='{$paymentWrap02}',
              termsWrap01='{$termsWrap01}', 
              terms='{$terms}', 
              termsWrap02='{$termsWrap02}',
              footer='{$footer}'
              
              WHERE tempID='{$tempID}'";
              and you have sql coding in the wrong place.....bare with me a sec

              Comment

              • anfetienne
                Contributor
                • Feb 2009
                • 424

                #8
                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
                Code:
                <?php
                $memberID=rand(0000000,9999999);
                ?>
                
                <input type="hidden" name="memberID" id="memberID" value="<?php print $memberID;?>" />
                FULL CODE
                Code:
                <?php
                include ("admintasks-dbcon.php");
                mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
                mysql_select_db($dbname);
                 
                $query = "SELECT * FROM $add_member WHERE memberID = '{$memberID}'";
                $result = mysql_query( $sql ) or die( mysql_error );
                
                if ( mysql_num_rows( $res ) > 0 )
                { 
                //and here you had no data specified or fields specified
                
                $query="
                UPDATE $add_member SET
                	        name = '{$_POST['name']}', 
                            address 1 = '{$_POST['address 1']}', 
                            address 2 = '{$_POST['address 2']}',
                            City='{$_POST['city']}', 
                            State = '{$_POST['state']}', 
                            Zip Code = '{$_POST['zip code']}',
                			Website = '{$_POST['website']}'
                			Contact Name = '{$_POST['contact name']}',
                			Position = '{$_POST['position']}',
                			Phone Number = '{$_POST['phone number']}',
                			Email Address = '{$_POST['email address']}')
                
                			WHERE memberID ='{$memberID}'";
                {
                else{
                //in this section you had the following...your sql wasn't inside the loop and also there was no $query=""
                
                # INSERT INTO $add_member
                # }
                # (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address) 
                # 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']})";
                #  
                $query="
                
                INSERT INTO $add_member (
                			
                			Member ID,	
                			Name,
                			Address 1,
                			Address 2,
                			City, 
                			State, 
                			Zip Code, 
                			Website, 
                			Contact Name, 
                			Position, 
                			Phone Number, 
                			Email Address)
                			 
                VALUES 
                
                			{$_POST['memberID']},
                			{$_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']})";
                 
                $result=mysql_query($query) or die("Error in query:".mysql_error()); 
                
                if ( mysql_num_rows( $result ) > 0 ) 
                echo mysql_affected_rows()." row inserted into the database effectively."; 
                 
                mysql_close(); 
                }
                
                session_start();
                $_SESSION["Name"] = $_POST['name'];
                header("location:thankYou.php");
                ?>
                Last edited by anfetienne; Jul 23 '09, 04:52 PM. Reason: updated coding

                Comment

                • anfetienne
                  Contributor
                  • Feb 2009
                  • 424

                  #9
                  and on your following page if you wanted to say

                  "Thank You (Member's Name),"

                  use this code to include it in

                  Code:
                  <?
                  session_start();
                  $Name = $_SESSION["Name"];
                  ?>
                  
                  //example
                  "Thank You <?php print $Name;?>, for registering!"

                  Comment

                  • anfetienne
                    Contributor
                    • Feb 2009
                    • 424

                    #10
                    also 1 question.....

                    in your config file is $add_member = add_member???

                    Comment

                    • mideastgirl
                      New Member
                      • Jun 2009
                      • 65

                      #11
                      I am not sure what you mean by config, file unless you mean the file that connects to mysql and in that case no it is just add_member for the table name.

                      Is that what you are asking?

                      I have not tried your scripting yet, but I will and thank you. I will let you know if that is successful.

                      Comment

                      • anfetienne
                        Contributor
                        • Feb 2009
                        • 424

                        #12
                        yeah....if thats the case you need to take the dollar sign off your sql code so its

                        INSERT INTO add_member and SELECT * FROM add_member

                        Comment

                        • mideastgirl
                          New Member
                          • Jun 2009
                          • 65

                          #13
                          Well thank you for all that help! I have made the changes you suggested and am now getting this error:

                          Parse error: syntax error, unexpected T_ELSE in /home/content/m/i/d/mideasthonors/html/addmember_db.ph p on line 27

                          Here is the code I am using:

                          [code=php]
                          <?php
                          include ("admintasks-dbcon.php");
                          mysql_connect($ hostname,$usern ame, $password) OR DIE ('Unable to connect to database! Please try again later.');
                          mysql_select_db ($dbname);
                          $query = "SELECT * FROM add_member WHERE memberID = '{$memberID}'";
                          $result = mysql_query( $sql ) or die( mysql_error );

                          if ( mysql_num_rows( $res ) > 0 )
                          {

                          $query="
                          UPDATE add_member SET
                          name = '{$_POST['name']}',
                          address 1 = '{$_POST['address 1']}',
                          address 2 = '{$_POST['address 2']}',
                          City='{$_POST['city']}',
                          State = '{$_POST['state']}',
                          Zip Code = '{$_POST['zip code']}',
                          Website = '{$_POST['website']}'
                          Contact Name = '{$_POST['contact name']}',
                          Position = '{$_POST['position']}',
                          Phone Number = '{$_POST['phone number']}',
                          Email Address = '{$_POST['email address']}')

                          WHERE memberID ='{$memberID}'" ;
                          {
                          else{

                          $query="

                          INSERT INTO add_member (

                          Member ID,
                          Name,
                          Address 1,
                          Address 2,
                          City,
                          State,
                          Zip Code,
                          Website,
                          Contact Name,
                          Position,
                          Phone Number,
                          Email Address)

                          VALUES

                          {$_POST['memberID']},
                          {$_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']})";

                          $result=mysql_q uery($query) or die("Error in query:".mysql_e rror());

                          if ( mysql_num_rows( $result ) > 0 )
                          echo mysql_affected_ rows()." row inserted into the database effectively.";

                          mysql_close();
                          }

                          session_start() ;
                          $_SESSION["Name"] = $_POST['name'];
                          header("locatio n:thankyouforbe comingamember.p hp");
                          ?>
                          [/code]

                          Comment

                          • anfetienne
                            Contributor
                            • Feb 2009
                            • 424

                            #14
                            on line 26 you haven't closed the previous loop

                            change { to } and it should work

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              those errors are easily fixed if you keep an eye on your syntax (and a good editor helps a lot here, because it can show you which parentheses/brackets belong together)

                              Comment

                              Working...