walshybiker Posted May 26, 2010 Share Posted May 26, 2010 Hi I'm new to this and am struggling with an assignment. I want to populate a database (in phymyadmin) called event. When a link is clicked it then moves to this page where I want it to populate a field called eventa with the username. It just sends a 0 to all fields. The php code is below: <?php //This checks that the user is registered and has entered the correct details session_start(); // check if logged in or not? if (!isset($_SESSION['username']) ||$_SESSION['username']=$username) { // not logged in, move to login page header('Location: login.php'); } else { $con=mysql_connect("localhost", "20154162", "lynne"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db ("two0154162") or die (mysql_error()); $_POST[$_SESSION['username']=$username; //insert fields into databse $query = "INSERT INTO event(eventa) VALUES ('"$_SESSION ["username"]'")"; mysql_query($query) or die('Error, insert query failed'.mysql_error()); //after login it returns to events page // header('location:events.html'); // exit; mysql_close ($con); } //echo ("got here"); ?> Thanks Walshybiker Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/ Share on other sites More sharing options...
kalivos Posted May 26, 2010 Share Posted May 26, 2010 I'm surprised you don't get an error message $_POST[$_SESSION['username']=$username; Also, are you trying to compare or set the value here? (Do you need two equal signs?) if (!isset($_SESSION['username']) ||$_SESSION['username']=$username) { Edit: Don't know how I missed it, but your query is wrong as well. $query = "INSERT INTO event(eventa) VALUES ('"$_SESSION ["username"]'")"; It should be $query = "INSERT INTO event(eventa) VALUES ('".$_SESSION ['username']."')"; Hope that helps, -Kalivos Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063456 Share on other sites More sharing options...
walshybiker Posted May 26, 2010 Author Share Posted May 26, 2010 Still struggling - I have checked all other coding in linked pages. Last night I was getting a 0 in the field. Now I get a HTTP500 internal server error! I seem to keep going round in circles. Any more suggestions??? Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063502 Share on other sites More sharing options...
trq Posted May 26, 2010 Share Posted May 26, 2010 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063505 Share on other sites More sharing options...
walshybiker Posted May 26, 2010 Author Share Posted May 26, 2010 Code attached :'( [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063507 Share on other sites More sharing options...
walshybiker Posted May 26, 2010 Author Share Posted May 26, 2010 <?php //This checks that the user is registered and has entered the correct details session_start(); // check if logged in or not? if (!isset($_SESSION['username']) ||$_SESSION['username']==$username) { // not logged in, move to login page header('Location: login.php'); } else { $con=mysql_connect("localhost", "20154162", "lynne"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db ("two0154162") or die (mysql_error()); $_POST[$_SESSION['username']=true; //insert fields into databse $query = "INSERT INTO event(eventa) VALUES ('"$_SESSION ["username"]"')"; mysql_query($query) or die('Error, insert query failed'.mysql_error()); //after login it returns to events page // header('location:events.html'); // exit; mysql_close ($con); } echo ("got here"); ?> Edit: We have tags for posting code within. Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063510 Share on other sites More sharing options...
trq Posted May 26, 2010 Share Posted May 26, 2010 You need to turn error reporting on on your server, your code is riddled with syntax errors. Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063513 Share on other sites More sharing options...
walshybiker Posted May 26, 2010 Author Share Posted May 26, 2010 Don't have error reporting - Its a college server (work is for an Assignment) :-\ Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063521 Share on other sites More sharing options...
Alex Posted May 26, 2010 Share Posted May 26, 2010 Put this at the top of the script: error_reporting(E_ALL | E_STRICT); Quote Link to comment https://forums.phpfreaks.com/topic/202933-inputs-a-0-instead-of-username-in-field/#findComment-1063522 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.