/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=php]<?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>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@duff2481authorDec 08.2006 — 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:
[code=php]
<?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>



[/code]
Copy linkTweet thisAlerts:
@orreipDec 08.2006 — Change line 39 into this:

$seminar0 = (!isset($_POST["seminar[0]"])? NULL: $_POST["seminar[0]"]);
Copy linkTweet thisAlerts:
@duff2481authorDec 08.2006 — I'm getting an unexpected end. I have checked my tags, but maybe i missed something, does someone see something I dont?
[code=php]
<?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>

[/code]
×

Success!

Help @duff2481 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...