ballouta Posted September 15, 2008 Share Posted September 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/ Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 You need session_start() on all pages that will use the session variables. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641791 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 i already have it on the most top of the page: <?php session_start() ?> Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641793 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641796 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641800 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 Provide more code for review~registration.php if there is more, because this error would need fixing. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641801 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641804 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641811 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641820 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 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() Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641823 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641827 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 You should use mysql_real_escape_string() on ANY user submitted data that will be entered into a database. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641829 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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'].")' Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641833 Share on other sites More sharing options...
kenrbnsn Posted September 15, 2008 Share Posted September 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641834 Share on other sites More sharing options...
DarkWater Posted September 15, 2008 Share Posted September 15, 2008 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);. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641837 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 Thanks DW, I think I've screwed that up a few times. Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641841 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641862 Share on other sites More sharing options...
JasonLewis Posted September 15, 2008 Share Posted September 15, 2008 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']."' Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641865 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641869 Share on other sites More sharing options...
kenrbnsn Posted September 15, 2008 Share Posted September 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641882 Share on other sites More sharing options...
ballouta Posted September 15, 2008 Author Share Posted September 15, 2008 kenrbnsn your code is really great and nothing to worry about. I just fixed this: $qtmp[] = "`password` = into $qtmp[] = "`pass` = thanks for you all Quote Link to comment https://forums.phpfreaks.com/topic/124284-solved-session-problem/#findComment-641886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.