www.webdeveloper.com
Results 1 to 4 of 4

Thread: Sending sessions from form to Database:

  1. #1
    Join Date
    Sep 2006
    Posts
    69

    Sending sessions from form to Database:

    Okay, I'm trying to send these sessions from my forms to a database. I need to use object approach when sending to database. I thought I had everything I needed but i'm missing something -- Database name is conference table is registration

    I would like to have a button do the job when it is pressed to call the sending of info to database - not if that is possible if someone could help, much appreciated!
    CODE:
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['apache'] = $_POST['apache'];
    $_SESSION['docRea'] = $_POST['docRea'];
    $_SESSION['geek'] = $_POST['geek'];
    $_SESSION['javascript'] = $_POST['javascript'];
    $_SESSION['mysql'] = $_POST['mysql'];
    $_SESSION['php'] = $_POST['php'];
    $_SESSION['web'] = $_POST['web'];
    ?>
    <html>
    <head>
    <title> Registeration Page for Conference</title>
    <body>
    <form action = "m5donovanConfirmation.php" method = "post">


    <center>     

    <font color="#C11B17"><h1>You have input the following data, if you need to make any changes, please do so now before submitting!  Thanks</h1></font>
    <br />
    <h3><font color="#FF0000">Personal Information</font></h3>
    E-mail:<input type="text" name="email" value="<?php  print $_SESSION['email'];?>"><br />
    First Name:<input type="text" name="firstName" value="<?php print $_SESSION['firstName'];?>"> <br />
    Last Name<input type="text" name="email" value="<?php print $_SESSION['lastName'];?>"> <br />
    Address:<input type="text" name="email" value="<?php print $_SESSION['address'];?>"> <br />
    City:<input type="text" name="email" value="<?php print $_SESSION['city'];?>"> <br />
    State:<input type="text" name="email" value="<?php print $_SESSION['state'];?>"> <br />
    Zip:<input type="text" name="email" value="<?php print $_SESSION['zip'];?>"> <br />
    Phone:<input type="text" name="email" value="<?php print $_SESSION['phone'];?>"> <br />
    <h3><font color = "#254117 ">Company Information</font></h3>
    CO_Address:<input type="text" name="email" value="<?php print $_SESSION['co_address'];?>"> <br />
    CO_City:<input type="text" name="email" value="<?php print $_SESSION['co_city'];?>"> <br />
    CO_State:<input type="text" name="email" value="<?php print $_SESSION['co_state'];?>"> <br />
    CO_Zip:<input type="text" name="email" value="<?php print $_SESSION['co_zip'];?>"> <br />
    <h3><font color="#AF7817">Seminars you will be attending</font></h3>
    Apache_Seminar:<input type="text" name="email" value="<?php print $_SESSION['apache'];?>"> <br />
    DocREa Fanclub:<input type="text" name="email" value="<?php print $_SESSION['docrea'];?>"> <br />
    Geek Seminar:<input type="text" name="email" value="<?php print $_SESSION['geek'];?>"> <br />
    Javascript Seminar:<input type="text" name="email" value="<?php print $_SESSION['javascript'];?>"> <br />
    Mysql Seminar:<input type="text" name="email" value="<?php print $_SESSION['mysql'];?>"> <br />
    PHP Seminar:<input type="text" name="email" value="<?php print $_SESSION['php'];?>"> <br />

    </form>
    <?php
    $DBConnect 
    = @new mysqli("localhost""root"""); // attempting to log on
    if (mysqli_connect_errno())
        die (
    "<p>Unable to connect to the database server.)</p>"
            
    "<p>Error code " mysqli_connect_errno ()
            . 
    ": " mysqli_connect_errnor()) . "</p>";
    $DBName "conference";
    @
    $DBConnect ->select_db($DBName)
        or die(
    "<p>Unable to select the database.</p>"
        
    "<p>Error code " mysqli_errno($DBConnect)
        . 
    ": " mysqli_error($DBConnect)) . "</p>";

    $TableName "registeration";
    // gathers data to send to correct database and table
    $email $_SESSION['email'];
    $password $_SESSION['password'];
    $date $_SESSION['date'];
    $firstName $_SESSION['firstName'];
    $lastName $_SESSION['lastName'];
    $address $_SESSION['address'];
    $city $_SESSION['city'];
    $state $_SESSION['state'];
    $zip $_SESSION['zip'];
    $phone $_SESSION['phone'];
    $company $_SESSION['company'];
    $co_address $_SESSION['co_address'];
    $co_city $_SESSION['co_city'];
    $co_state $_SESSION['co_state'];
    $co_zip $_SESSION['co_zip'];
    $co_phone $_SESSION['co_phone'];
    $apache_seminar $_SESSION['apache'];
    $docrea_fanclub $_SESSION['docRea'];
    $geek_seminar $_SESSION['geek'];
    $javascript_seminar $_SESSION['javascript'];
    $php_seminar $_SESSION['php'];
    $web_services_seminar $_SESSION['web'];

    $SQLstring "INSTERT INTO $TableName VALUES('$email', '$password', '$date', '$firstName', '$lastName', '$address', '$city', '$state', '$zip', '$phone', '$company', '$co_address', '$co_city', '$co_state', '$co_zip','$co_phone', '$apache_seminar','$docrea_fanclub','$geek_seminar','$javascript_seminar','$php_seminar,'$web_services_seminar')";

    $QueryResult = @mysqli_query($DBConnect$SQLstring)
        or die(
    "<p>Unable to execute the query.</p>"
        
    "<p>Error code " mysqli_errno($DBConnect)
        . 
    ": " mysqli_error($DBConnect)) . "</p>";

    $DBConnect->close(); // closes the database
        

    ?>
    </body>
    </html>

  2. #2
    Join Date
    Sep 2006
    Posts
    69
    Okay, I have changed it just a tad, but i'm getting an error message with either a ")" or a "," in my code on line 39. Not sure where I should close the paranthesis(sp)

    Here is the code:
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['apache'] = $_POST['apache'];
    $_SESSION['docRea'] = $_POST['docRea'];
    $_SESSION['geek'] = $_POST['geek'];
    $_SESSION['javascript'] = $_POST['javascript'];
    $_SESSION['mysql'] = $_POST['mysql'];
    $_SESSION['php'] = $_POST['php'];
    $_SESSION['web'] = $_POST['web'];
    ?>
    <html>
    <head>
    <title> Registeration Page for Conference</title>
    <body>
    <form action = "m5donovanConfirmation.php" method = "post">


    <center>     

    <font color="#C11B17"><h1>You have input the following data, if you need to make any changes, please do so now before submitting!  Thanks</h1></font>
    <br />
    <h3><font color="#FF0000">Personal Information</font></h3>
    E-mail:<input type="text" name="email" value="<?php  print $_SESSION['email'];?>"><br />
    First Name:<input type="text" name="firstName" value="<?php print $_SESSION['firstName'];?>"> <br />
    Last Name<input type="text" name="email" value="<?php print $_SESSION['lastName'];?>"> <br />
    Address:<input type="text" name="email" value="<?php print $_SESSION['address'];?>"> <br />
    City:<input type="text" name="email" value="<?php print $_SESSION['city'];?>"> <br />
    State:<input type="text" name="email" value="<?php print $_SESSION['state'];?>"> <br />
    Zip:<input type="text" name="email" value="<?php print $_SESSION['zip'];?>"> <br />
    Phone:<input type="text" name="email" value="<?php print $_SESSION['phone'];?>"> <br />
    <h3><font color = "#254117 ">Company Information</font></h3>
    CO_Address:<input type="text" name="email" value="<?php print $_SESSION['co_address'];?>"> <br />
    CO_City:<input type="text" name="email" value="<?php print $_SESSION['co_city'];?>"> <br />
    CO_State:<input type="text" name="email" value="<?php print $_SESSION['co_state'];?>"> <br />
    CO_Zip:<input type="text" name="email" value="<?php print $_SESSION['co_zip'];?>"> <br />

    <h3><font color="#AF7817">Seminars you will be attending</font></h3>
    <?php
    $seminar0 
    = !isset($_POST["seminar[0]"NULL$_POST["seminar[0]"]);
    $seminar1 = !isset($_POST["seminar[1]"NULL$_POST["seminar[1]"]);
    $seminar2 = !isset($_POST["seminar[2]"NULL$_POST["seminar[2]"]);
    $seminar3 = !isset($_POST["seminar[3]"NULL$_POST["seminar[3]"]);
    $seminar4 = !isset($_POST["seminar[4]"NULL$_POST["seminar[4]"]);
    $seminar5 = !isset($_POST["seminar[5]"NULL$_POST["seminar[5]"]);
    ?>
    Apache Seminar<input type="checkbox" name="seminar0" <?php if($seminar0 =="on"){print " checked";?>><br />
    DocRea Fanclub<input type="checkbox" name="seminar1" <?php if($seminar1 =="on"){print " checked";?>><br />
    Geek Seminar<input type="checkbox" name="seminar2" <?php if($seminar2 =="on"){print " checked";?><br />
    Javascript Seminar<input type="checkbox" name="seminar3" <?php if($seminar3 =="on"){print " checked";?><br />
    Mysql Seminar<input type="checkbox" name="seminar4" <?php if($seminar4 =="on"){print " checked";?><br />
    PHP Seminar<input type="checkbox" name="seminar5" <?php if($seminar5 =="on"){print " checked";?>


    </form>
    <?php
    $DBConnect 
    = @new mysqli("localhost""root"""); // attempting to log on
    if (mysqli_connect_errno())
        die (
    "<p>Unable to connect to the database server.)</p>"
            
    "<p>Error code " mysqli_connect_errno ()
            . 
    ": " mysqli_connect_errnor()) . "</p>";
    $DBName "conference";
    @
    $DBConnect ->select_db($DBName)
        or die(
    "<p>Unable to select the database.</p>"
        
    "<p>Error code " mysqli_errno($DBConnect)
        . 
    ": " mysqli_error($DBConnect)) . "</p>";

    $TableName "registeration";
    // gathers data to send to correct database and table
    $email $_SESSION['email'];
    $password $_SESSION['password'];
    $date $_SESSION['date'];
    $firstName $_SESSION['firstName'];
    $lastName $_SESSION['lastName'];
    $address $_SESSION['address'];
    $city $_SESSION['city'];
    $state $_SESSION['state'];
    $zip $_SESSION['zip'];
    $phone $_SESSION['phone'];
    $company $_SESSION['company'];
    $co_address $_SESSION['co_address'];
    $co_city $_SESSION['co_city'];
    $co_state $_SESSION['co_state'];
    $co_zip $_SESSION['co_zip'];
    $co_phone $_SESSION['co_phone'];
    $apache_seminar $_SESSION['apache'];
    $docrea_fanclub $_SESSION['docRea'];
    $geek_seminar $_SESSION['geek'];
    $javascript_seminar $_SESSION['javascript'];
    $php_seminar $_SESSION['php'];
    $web_services_seminar $_SESSION['web'];

    $SQLstring "INSTERT INTO $TableName VALUES('$email', '$password', '$date', '$firstName', '$lastName', '$address', '$city', '$state', '$zip', '$phone', '$company', '$co_address', '$co_city', '$co_state', '$co_zip','$co_phone', '$apache_seminar','$docrea_fanclub','$geek_seminar','$javascript_seminar','$php_seminar,'$web_services_seminar')";

    $QueryResult = @mysqli_query($DBConnect$SQLstring)
        or die(
    "<p>Unable to execute the query.</p>"
        
    "<p>Error code " mysqli_errno($DBConnect)
        . 
    ": " mysqli_error($DBConnect)) . "</p>";

    $DBConnect->close(); // closes the database
        

    ?>
    </body>
    </html>

  3. #3
    Join Date
    Feb 2006
    Posts
    54
    Change line 39 into this:
    $seminar0 = (!isset($_POST["seminar[0]"])? NULL: $_POST["seminar[0]"]);

  4. #4
    Join Date
    Sep 2006
    Posts
    69
    I'm getting an unexpected end. I have checked my tags, but maybe i missed something, does someone see something I dont?
    PHP Code:
    <?php 
    session_start
    (); 
    $_SESSION['apache'] = $_POST['apache']; 
    $_SESSION['docRea'] = $_POST['docRea']; 
    $_SESSION['geek'] = $_POST['geek']; 
    $_SESSION['javascript'] = $_POST['javascript']; 
    $_SESSION['mysql'] = $_POST['mysql']; 
    $_SESSION['php'] = $_POST['php']; 
    $_SESSION['web'] = $_POST['web']; 
    ?> 
    <html> 
    <head> 
    <title> Registeration Page for Conference</title> 
    <body> 
    <form action = "m5donovanConfirmation.php" method = "post"> 


    <center>      

    <font color="#C11B17"><h1>You have input the following data, if you need to make any changes, please do so now before submitting!  Thanks</h1></font> 
    <br /> 
    <h3><font color="#FF0000">Personal Information</font></h3> 
    E-mail:<input type="text" name="email" value="<?php print $_SESSION['email'];?>"><br /> 
    First Name:<input type="text" name="firstName" value="<?php print $_SESSION['firstName'];?>"> <br /> 
    Last Name<input type="text" name="email" value="<?php print $_SESSION['lastName'];?>"> <br /> 
    Address:<input type="text" name="email" value="<?php print $_SESSION['address'];?>"> <br /> 
    City:<input type="text" name="email" value="<?php print $_SESSION['city'];?>"> <br /> 
    State:<input type="text" name="email" value="<?php print $_SESSION['state'];?>"> <br /> 
    Zip:<input type="text" name="email" value="<?php print $_SESSION['zip'];?>"> <br /> 
    Phone:<input type="text" name="email" value="<?php print $_SESSION['phone'];?>"> <br /> 
    <h3><font color = "#254117 ">Company Information</font></h3> 
    CO_Address:<input type="text" name="email" value="<?php print $_SESSION['co_address'];?>"> <br /> 
    CO_City:<input type="text" name="email" value="<?php print $_SESSION['co_city'];?>"> <br /> 
    CO_State:<input type="text" name="email" value="<?php print $_SESSION['co_state'];?>"> <br /> 
    CO_Zip:<input type="text" name="email" value="<?php print $_SESSION['co_zip'];?>"> <br /> 

    <h3><font color="#AF7817">Seminars you will be attending</font></h3> 
    <?php 
    $seminar0 
    = (!isset($_POST["seminar[0]"])? NULL$_POST["seminar[0]"]);
    $seminar1 = (!isset($_POST["seminar[1]"])? NULL$_POST["seminar[1]"]); 
    $seminar2 = (!isset($_POST["seminar[2]"])? NULL$_POST["seminar[2]"]); 
    $seminar3 = (!isset($_POST["seminar[3]"])? NULL$_POST["seminar[3]"]); 
    $seminar4 = (!isset($_POST["seminar[4]"])? NULL$_POST["seminar[4]"]); 
    $seminar5 = (!isset($_POST["seminar[5]"])? NULL$_POST["seminar[5]"]); 
    ?> 
    Apache Seminar<input type="checkbox" name="seminar0" <?php if($seminar0 =="on"){print " checked";?>><br /> 
    DocRea Fanclub<input type="checkbox" name="seminar1" <?php if($seminar1 =="on"){print " checked";?>><br /> 
    Geek Seminar<input type="checkbox" name="seminar2" <?php if($seminar2 =="on"){print " checked";?><br /> 
    Javascript Seminar<input type="checkbox" name="seminar3" <?php if($seminar3 =="on"){print " checked";?><br /> 
    Mysql Seminar<input type="checkbox" name="seminar4" <?php if($seminar4 =="on"){print " checked";?><br /> 
    PHP Seminar<input type="checkbox" name="seminar5" <?php if($seminar5 =="on"){print " checked";?> 
    </center>

    </form> 
    <?php 
    $DBConnect 
    = @new mysqli("localhost""root"""); // attempting to log on 
    if (mysqli_connect_errno()) 
        die (
    "<p>Unable to connect to the database server.)</p>" 
            
    "<p>Error code " mysqli_connect_errno () 
            . 
    ": " mysqli_connect_errnor()) . "</p>"
    $DBName "conference"
    @
    $DBConnect ->select_db($DBName
        or die(
    "<p>Unable to select the database.</p>" 
        
    "<p>Error code " mysqli_errno($DBConnect
        . 
    ": " mysqli_error($DBConnect)) . "</p>"

    $TableName "registeration"
    // gathers data to send to correct database and table 
    $email $_SESSION['email']; 
    $password $_SESSION['password']; 
    $date $_SESSION['date']; 
    $firstName $_SESSION['firstName']; 
    $lastName $_SESSION['lastName']; 
    $address $_SESSION['address']; 
    $city $_SESSION['city']; 
    $state $_SESSION['state']; 
    $zip $_SESSION['zip']; 
    $phone $_SESSION['phone']; 
    $company $_SESSION['company']; 
    $co_address $_SESSION['co_address']; 
    $co_city $_SESSION['co_city']; 
    $co_state $_SESSION['co_state']; 
    $co_zip $_SESSION['co_zip']; 
    $co_phone $_SESSION['co_phone']; 
    $apache_seminar $_SESSION['apache']; 
    $docrea_fanclub $_SESSION['docRea']; 
    $geek_seminar $_SESSION['geek']; 
    $javascript_seminar $_SESSION['javascript']; 
    $php_seminar $_SESSION['php']; 
    $web_services_seminar $_SESSION['web']; 

    $SQLstring "INSTERT INTO $TableName VALUES('$email', '$password', '$date', '$firstName', '$lastName', '$address', '$city', '$state', '$zip', '$phone', '$company', '$co_address', '$co_city', '$co_state', '$co_zip','$co_phone', '$apache_seminar','$docrea_fanclub','$geek_seminar','$javascript_seminar','$php_seminar,'$web_servic  es_seminar')"

    $QueryResult = @mysqli_query($DBConnect$SQLstring
        or die(
    "<p>Unable to execute the query.</p>" 
        
    "<p>Error code " mysqli_errno($DBConnect
        . 
    ": " mysqli_error($DBConnect)) . "</p>"

    $DBConnect->close(); // closes the database 
         

    ?> 
    </body> 
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles