Sorrow Posted November 21, 2006 Share Posted November 21, 2006 I want to take the info from page 1 send it on page 2 where the only thing that is done in the second page is saving the infos into my database the error is in the query:<?phpsession_start(); $_SESSION['Username'] = $_POST["Username"];$con = mysql_connect("bla_bla","bla_bla","bla_bla");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("jplegris_pirate", $con);mysql_query("INSERT INTO Usagers (Username) VALUES ($_SESSION['Username'];)");mysql_close($con);?> Quote Link to comment Share on other sites More sharing options...
marcus Posted November 21, 2006 Share Posted November 21, 2006 [code]<?phpsession_start();$_SESSION['Username'] = $_POST["Username"];$con = mysql_connect(host,dbuser,dbpass);$db = mysql_select_db(dbname,$con);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_query("INSERT INTO Usagers (Username) VALUES ($_SESSION['Username'])");mysql_close($con);?>[/code] Quote Link to comment Share on other sites More sharing options...
Sorrow Posted November 21, 2006 Author Share Posted November 21, 2006 I tryed the code you gave me but it still gives me this error:parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in Quote Link to comment Share on other sites More sharing options...
steelmanronald06 Posted November 21, 2006 Share Posted November 21, 2006 [code]<?phpsession_start();$_SESSION['Username'] = $_POST['Username'];$con = mysql_connect(host,dbuser,dbpass);$db = mysql_select_db(dbname,$con);if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_query("INSERT INTO Usagers (Username) VALUES ($_SESSION['Username'])");mysql_close($con);?>[/code] Quote Link to comment Share on other sites More sharing options...
marcus Posted November 21, 2006 Share Posted November 21, 2006 I had to re-edit my code, which is like the same as his. Quote Link to comment Share on other sites More sharing options...
Sorrow Posted November 21, 2006 Author Share Posted November 21, 2006 it still does the same thing the parsing error. do you have another way that i could do it without using session variables Quote Link to comment Share on other sites More sharing options...
marcus Posted November 21, 2006 Share Posted November 21, 2006 Did you update your fields? host,dbuser,dbpass and dbname? Quote Link to comment Share on other sites More sharing options...
Sorrow Posted November 21, 2006 Author Share Posted November 21, 2006 Yes it is done when i am trying to get the info without doing the query I can see the info with :echo $_SESSION['Username'];but it keeps giving me te error when im trying to execute the query Quote Link to comment Share on other sites More sharing options...
marcus Posted November 21, 2006 Share Posted November 21, 2006 Alright[code]<?phpsession_start();$un = $_POST[Username];$_SESSION['Username'] = $un;$con = mysql_connect(host,dbuser,dbpass);$db = mysql_select_db(dbname,$con);if (!$con) { die('Could not connect: ' . mysql_error()); }$sql = "INSERT INTO Usagers (`Username`) VALUES('$un')";$result = mysql_query($sql);mysql_close($con);?>[/code]if session username and post username are the same, why not just insert post username into the database? Quote Link to comment Share on other sites More sharing options...
Sorrow Posted November 21, 2006 Author Share Posted November 21, 2006 ty very much it is now working Quote Link to comment Share on other sites More sharing options...
marcus Posted November 21, 2006 Share Posted November 21, 2006 No problem. Quote Link to comment Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 i've also found this... mysql cannot directly enter $_SESSION variables... also, for some reason, arrays inside arrays... Quote Link to comment Share on other sites More sharing options...
DaviDJ Posted November 22, 2006 Share Posted November 22, 2006 you cannot use the apostrophes for the variable name between the [ and ] inside quote marks.so,<?phpecho "Hello $_POST['Username']"; // will produce an errorecho "Hello $_POST[Username]"; // will succeed// or better yetecho 'Hello ' . $_POST['Username'];?>so your original code should look like[code]<?phpsession_start();$_SESSION['Username'] = $_POST["Username"];$con = mysql_connect("bla_bla","bla_bla","bla_bla");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("jplegris_pirate", $con);mysql_query("INSERT INTO Usagers (Username) VALUES (" . $_SESSION['Username'] . ";");mysql_close($con);?>[/code] Quote Link to comment 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.