Jump to content

Recommended Posts

Hello

 

I have a registration form, after filling it out, the user should review the info he entered in the page review~registration.php, if the info is correct, he should press on confirm~registration.php so the code inserts his data into the DB.

 

in the review~registration page i have this code:

<?php
$fname=$_POST['fname'];
$_session['fname']=$fname;

$lname=$_POST['lname'];
$_session['lname']=$lname;
?>

if I echo the $_session['fname'] it outputs a correct value.

 

in confirm~registration.php, i have this code:

<?php
echo $_session['fname'];
?>

 

it doesn't output anything! where's the problem?

I need to use the session variables to insert them into the DB.

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/124284-solved-session-problem/
Share on other sites

Not sure if it'll make a difference but it is actually $_SESSION not $_session

 

Okay well ensure that it is at the top of review~registration.php and confirm~registration.php

 

You can also try placing:

ini_set("error_reporting", "1");
error_reporting(E_ALL);

 

At the top of your pages as well.

Thank you very much

 

the problem is the small letter session !!!

 

but the two lines that you asked me to add to show errors gve me this:

 

Parse error: syntax error, unexpected T_STRING in /home/dcompany/public_html/review~registration.php on line 2

 

Anyway it is working now.

Thank you

Hi again

 

kindly what is the correct syntax to insert the session variables now into the DB?

 

<?php

$query="
INSERT INTO `members` (
`ID` ,
`fname` ,
`lname` ,
`email` ,
`phone` ,
`country` ,
`shipping` ,
`user` ,
`pass` ,
`date`) VALUES
( NULL , $_SESSION['fname'], $_SESSION['lname'], $_SESSION['email'], $_SESSION['phone'], $_SESSION['country'], $_SESSION['shipping'], $_SESSION['user'], $_SESSION['password'], '$date')";
?>

 

This one is Not working.

You either need to "break out" of the string or wrap variables in curly brackets.

 

The break out method:

 

$query="
INSERT INTO `members` (
`ID` ,
`fname` ,
`lname` ,
`email` ,
`phone` ,
`country` ,
`shipping` ,
`user` ,
`pass` ,
`date`) VALUES
( NULL , ".$_SESSION['fname'].", ".$_SESSION['lname'].", ".$_SESSION['email'].", ".$_SESSION['phone'].", ".$_SESSION['country'].", ".$_SESSION['shipping'].", ".$_SESSION['user'].", ".$_SESSION['password'].", '$date')";
?>

 

Curly brace method:

 

$query="
INSERT INTO `members` (
`ID` ,
`fname` ,
`lname` ,
`email` ,
`phone` ,
`country` ,
`shipping` ,
`user` ,
`pass` ,
`date`) VALUES
( NULL , {$_SESSION['fname']}, {$_SESSION['lname']}, {$_SESSION['email']}, {$_SESSION['phone']}, {$_SESSION['country']}, {$_SESSION['shipping']}, {$_SESSION['user']}, {$_SESSION['password']}, '$date')";

 

Either method should work.

Thanks for your help.

 

Now I don't have any syntax errors or any other errors appearing, but the row was not added to the table!

 

this is all my code

]
<?php
include('CMS/operations.inc.php');

$date = date("y-m-d");
$query="
INSERT INTO `members` (
`ID` ,
`fname` ,
`lname` ,
`email` ,
`phone` ,
`country` ,
`shipping` ,
`user` ,
`pass` ,
`date`) VALUES
( NULL , ".$_SESSION['fname'].", ".$_SESSION['lname'].", ".$_SESSION['email'].", ".$_SESSION['phone'].", ".$_SESSION['country'].", ".$_SESSION['shipping'].", ".$_SESSION['user'].", ".$_SESSION['password'].", '$date')";
$query_result = mysql_query ($query, $dbh);
?>

You may have a blank field in your query. To find out if there was a MySQL error change this line:

 

$query_result = mysql_query ($query, $dbh);

 

To this:

 

$query_result = mysql_query ($query, $dbh) or die(mysql_error());

 

That will display to you an error that may have been encountered during the execution of the query.

 

Also, what is your 'date' field type. If it is DATETIME then you can use MySQL's NOW() function.

 

This:

'$date'

 

Can be:

now()

very usefull line:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com, 0096170610920, Lebanon, fsef, saadoo, 123456, 08-09-15)' at line 12

 

it seems the email is the problem, no?

do i have to do this for all variables?

 

which syntax is correct:

 

mysql_real_escape_string (".$_SESSION['phone'].")

 

mysql_real_escape_string (.$_SESSION['phone'].)

 

mysql_real_escape_string ('.$_SESSION['phone'].')

 

'mysql_real_escape_string (".$_SESSION['phone'].")'

You need to put all strings inside single quotes in your query:

<?php
include('CMS/operations.inc.php');

$date = date("y-m-d");
$query="
INSERT INTO `members` (
`ID` ,
`fname` ,
`lname` ,
`email` ,
`phone` ,
`country` ,
`shipping` ,
`user` ,
`pass` ,
`date`) VALUES
( NULL , '".$_SESSION['fname'].'", "'.$_SESSION['lname'].'", "'.$_SESSION['email'].'", '".$_SESSION['phone']."', '".$_SESSION['country'].'", "'.$_SESSION['shipping'].'", "'.$_SESSION['user']."', '".$_SESSION['password']."', '$date')";
$query_result = mysql_query ($query, $dbh) or die("Problem with the query: $query<br>" . mysql_error());
?>

 

Ken

Not sure if it'll make a difference but it is actually $_SESSION not $_session

 

Okay well ensure that it is at the top of review~registration.php and confirm~registration.php

 

You can also try placing:

ini_set("error_reporting", "1");
error_reporting(E_ALL);

 

At the top of your pages as well.

 

Just to let you know, it should be ini_set('display_errors', 1); not ini_set('error_reporting', 1);.

There's an error is the following query, can't find it :(

 

<?php
$query="
INSERT INTO `members` (
`ID` ,
`fname` ,
`lname` ,
`email` ,
`phone` ,
`country` ,
`shipping` ,
`user` ,
`pass` ,
`date`) VALUES
( NULL , '".$_SESSION['fname'].'", "'.$_SESSION['lname'].'", "'.$_SESSION['email'].'", '".$_SESSION['phone']."', '".$_SESSION['country'].'", "'.$_SESSION['shipping'].'", "'.$_SESSION['user']."', '".$_SESSION['password']."', '$date)";
$query_result = mysql_query ($query, $dbh) or die("Problem with the query: $query<br>" . mysql_error());
?>
?>

Parse error: syntax error, unexpected '"' in /home/dcompany/public_html/confirm~registration.php on line 31

 

Please help

You have the ' and " backwards in the first 3 $_SESSION calls.

 

'".$_SESSION['fname'].'", "'.$_SESSION['lname'].'", "'.$_SESSION['email'].'"

 

You seem to have gotten a bit confused with that part.

 

It should be:

 

'".$_SESSION['fname']."', '".$_SESSION['lname']."', '".$_SESSION['email']."'

ProjectFear you are very kind, sorry for bothering you today

 

i don't have any syntax errors now, but I got this:

 

Problem with the query: INSERT INTO `members` ( `ID` , `fname` , `lname` , `email` , `phone` , `country` , `shipping` , `user` , `pass` , `date`, `blk`) VALUES ( NULL , 'Mohamad', 'Daouk', 'mdaouk79@gmail.com', '0096170610920', 'Lebanon", "fvd", "saadoo', '123456', '08-09-15', 'N')

Column count doesn't match value count at row 1

 

Note that i just made sure that i have 11 coulums in my table, and their names are written in the query correctly. What do i have to do to find where's this problem came from?!

 

Thank You

I probable screwed up the order of the double & single quotes. It should be something like:

<?php
$x = "values ('" . $val . "', '" . $val2 . "', '" . $val3 . "')";
?>

I usually put everything I need into a temporary array and then explode the array. Something like this:

<?php
$flds = array('fname','lname','email','phone','country','shipping','user','pass','blk');
$qtmp = array();
foreach ($flds as $fld) {
   switch ($fld) {
      case 'pass':
         $qtmp[] = "`password` = '" . mysql_real_escape_string($_SESSION[$fld]) . "'";
         break;
      case 'date':
         $qtmp[] = "`date` = '" . NOW() . "'";
         break;
      default:
         $qtmp[] = "`" . $fld . "` = '" . mysql_real_escape_string($_SESSION[$fld]) . "'";
   }
}
$q = 'insert into `members` set ' . implode(', ',$qtmp);
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>

Using this alternative version of the INSERT query, you don't have to worry about counting the number of columns.

 

Ken

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.