Session Variable Info To Database
I have a 2 page form. The first page page of the form POSTS to the 2nd page which, after being filled out, should send all the information (from pages 1 and 2) to the database. I have created a session variable and have placed it at the top of the 2nd page. For brevity´s sake I have placed only one of the variables in this example:
<?php session_start(); $_SESSION["sessanimals"] = $_POST["animals"]; ?>
After filling out the remaining variables on page 2, I want all the information (the info from page 1 brought over in the session variable and the info from page 2) sent to the database. I tried creating an INSERT RECORD on page 2 but only the variables on page 2 are subsequently sent upon submission. How do I get all the info into my database??
Here are a list of my questions:
1. Is there any way of creating one session variable for all my page 1 form variables (I have 20+ variables)? 2. is there a way to denote ALL the variables in = $_POST[]; or do they have to be listed separately? 3. How do I post all the data from page 1 and 2 into my database at once?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Query User Info From A Session Variable
When a user logs in, a session variable is passed. The variable is the users ID. If the variable is passed successfully, they are logged in and I want to query the users information based on the session variable. Code:
Recall Database Info
Hi, I want to create a page where users can put in certain information like you normialy would in a form but when they click submit another page will load that will look like the original form the signed up with and everything they filed in that time will be there and they can make changes to that and then click submit and the changes are made to databse automaticialy.
How To Send Info To Database
im wondering how to submit info into a database. i know the code goes something lie $sql = "UPDATE <tablename> set $var = "var" but i know that is wrong and i want to put it in form so on submit it posts it in the database.
Info Deleted Itself From Database?
I got some info (news system) in a SQL database but after some days it deletes by itself it happened to me once but i thought i didnt remembered that i deleted it but today it happened again...it deleted by itself! lol I have other tables in the same database so its a table problem... How can i fix this? Did i miss something at the table configuration?
Get And Insert Info Into Database
I have one table (form) that has multiple fields. Here are few fields we need to know: ID, NAME, CITY, STATE, PROFESSION, x, y, z (x, y, z means more than 50 fields that give me more information about each name). The ID and NAME are unique and they don't change (each name has it's own ID). A NAME and its ID can be in any CITY, STATE or PROFESSION but this is fixed. That means if ID# 123 for Mr JOHN is Austin, TX, that will stay in Austin, TX for ever. I have more than 5000 NAME and it's ID, 9 professions, all US States and all Cities in my database. Here is what I need to do: I want to have a form on my site that my visitor finds his name first and then enters more information about him/her that will complete my database fields of x,y,z. What I'm thinking to do is to create a drop down list that the visitor first selects the profession. Based on the profession the second list shows the states that has that profession. Then by selecting the state, all the available cities will show up in the third list, and by selecting the city all the names related to that profession in that city, state will show up and he can select the name from the forth list. Then he enters other required information about him that will be send and saved in the database. Here is what I have done and I know to do so far: I have created the database with all the information in one table. I also know how to send data to database to be saved. But my problem at this point is how to create this list selection that narrows the search to find the right person.
Retrieving Info From A Database
I would like the code below to fetch and display in an html table the Ad_Id, Date, and Type_Job fields from the 1st 10 rows of a table called employment. I'd like the results to be sorted first by date and then by the Ad_Id #. I have replaced my username and password with "user" and "password". Currently, the script returns the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Also, the script is ignoring the css info that I have supplied. Code:
Session Info And Pull Down Lists
i have a html pull down list (<SELECT etc etc <OPTION VALUE .....) and i have the particular value the user last chose it to be in a $_SESSION['value']. How do i set the selected item of the list to this one? I can just add it in as the selected item of the list but then it appears twice.
Storing Session Info In MySQL
I've written a login system which uses session variables to store details about the user. The site isn't holding sensitive data, so this isn't a problem. What I'd like to do though, is store each login in mySQL and use it to automatically log the user back in next time around. Also want to use the logged in information for statistical information, such as how many registered users are logged in, and how many guests are going around on the site. I know vBulletin uses a system similar to this, by storing the session ID in a database and using it from there. Can anyone explain roughly how this would work for logging in the first time, and relogging in next time?
Populating A Form Wth Database Info
I've coded a piece of code which populates a form with data read from the database: $connection=mysql_connec ("localhost", "f2821842", "f2821842"); $result=mysql_select_db("QUERIES"); $query=mysql_query("Select * from Emp_Details where emp_num = '$employnum'"); while($row=mysql_fetch_array($query)) {$empname=$row['emp_name'];} <form name="webregform" action="webadmin2.php" method="post"> <input name="requiredname" type="text" size="30" value="<?php echo "$empname"; ?>"> </form> When I echo the $requiredname, I get spaces and no data, and I know that $empname is not a space-it does read a value in a database. 1. How can I get $requiredname to print a value?
Ordering Info Returned From Database
I have a PHP page on my site which pulls back info from my MySQL database and displays it in a table under appropriate headings. Is there code that I could add to these headings so that a) the same page could be redisplayed with the information sorted by the third column instead of the first b) information in the columns could be displayed in reverse order (maybe Z to A or highest figure to lowest figure)
Insert Form Info Into Database
i am trying to enter info from a form into a mysql database. when i submit the form, a new row is created, but the information isn't contained in it? any thoughts? PHP Code:
Filling Form With Database Info
I have a table with 5 fields for a tour business activity list : (1) id -table key (2) name (3)description (4)picture -text link not binary(5) country. I would like to create a form that takes all the activitys an puts it neatly down on site in checkboxes so user can select activtys.this will be linked to form mail.i would like the activitys to be seperated by the country they r in?
Update Database Info Using Forms
i have a page uses select and cases. i already have setup and working, auth/login to the page, create a new row in the table. i am now trying to have the user alter the information that the just put into the table. this is the code where i have setup to modify the info, $id is passed over. this puts the correct information into the form field. when i hit submit, the information, $name, $content, $id are not passed over. echo-ing results blank. PHP Code:
Hiding Database Connection Info
In a php script, I have to connect to a remote mysql database. I'm a bit worried that some user might be bale to retrieve the source of the page and see the user name and password to connect to the db. Is this resonable? What's the best way to avoid it?
Obtaining Info From Database Table
How do you obtain fields from a table and assign each field to a variable to be used as needed. An example: Say i had: table name : user Field 1 : User name Field 2: Password then i wanted: $username = field 1 $password = field 2.
User Info Not Posting To Database
I am trying to figure out why my script isn't updating the information of the user names stored in the database. Can anyone give me the solution? Below is the script: Code:
How To Obscure Database Info In PHP Pages
I'm moving from Cold Fusion to PHP and I have a question that none of the books I have answers adequately: In Cold Fusion, database connection parameters like the table, username and password are configured on the server. Since they are at the backend, nothing is exposed on the page except the queries themselves. In PHP, from what I see, the database info is on the page. Is this not a security risk? How can one be sure that this info is not on the page sent to the user?
Using SESSION Info To List Recent Visitors?
I would like to add a recent visitor feature to my web page. Am wondering about the best way to do this, and am curious if anyone has any tips. Is there a feature with SESSIONS to see who is currently connected? Or do I just need to timestamp everyone and query that information? edit... And I just noticed that little check mark at the bottem left of the post window that says someone is offline or online. How the heck is that being done?
Validating Form Info Before Inserting It Into Database
I have been trying to create a PHP application where you can add customer contacts to a MySQL database. Now, my problem began when I created a form where the user can add in a customer's name and info to the database. In an effort to alert the user that they may be adding a customer that is already setup in the database, knowing that some of the customers may have the same names, e.g. there is more than one Bobby Ray Brown, I decided to add a script that queries the "customers" table in the database and searches for all results that match the input from the user. Code:
Entering/checking Info Into Mysql Database
I have set up a client database where one can view, add, edit and delete entries. I ran into a problem setting up the add page. On this page i have set up forms to add info into the DB, and it works fine, but i dont want duplicate clients. Is there a way to set it up so that when you submit the form with the info it checks for duplicates and if there is one returns "sorry this record exists?"
Retrieve An Image In Folder From Info Out Of Database
i am having problems displaying an image once i have uploaded it. i upload it to a folder and store its name in a database. below is the code to display the image. I have figured out the the code is not grabbing the name from the database but i can not figure out why. can anyone help? //Retrieves data from MySQL $data = mysql_query("SELECT IMAGE_NAME FROM item") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { //Outputs the image and other data Echo "<img src=http://www.abcxyz.com/pics/".$info['photo'] ."<br>"; }
Sends SMTP Mail From Database Info
I've got this script that I want to use to send SMTP mail from a form that allows the user to select recipients from a dropdown list that is created using database info and send a message. Two of the selections in the dropdown list are groups. My script works fine when the user selects only one recipient. I run into trouble when the user selects one of the two groups. The message ends up getting sent numerous times to the people in the group. I received the message 9 times. I think the script is looping more times than it should. Does this make sense so far? Here's the script that receives the form data and connects to the DB to get the recipient email addresses and then sends the message: Code:
Retrieving Database Info Based On User
I'm still quite new to php and mysql but I have been unable to figure this out. I'm attempting to display a specific row and column from a mysql database based on the user. $result = mysql_query("SELECT fbleague FROM users WHERE username = $_SESSION[username]"); fbleague is the column users is the table username is the primary key column $_SESSION[username] is the username variable Then later I try to display it with echo "You are in league $result "; I know $_SESSION[username] is set correctly because I can display that with no problems.
Uploading Info From A Text File Into A MySQL Database
what would the PHP and SQL code be to say basically: make a new row and put this in the field, what comes after each comma goes in a new field, and each new line should be a new row. I have a huge text file that i don't have a way to upload directly into a MySQL database because my webhost isn't allowing it for some reason.
Upload & Query MySQL Info Database With Image Files
I want a database I can enter information and upload a photo from a web form. Then I want to query that database for the text info with its related photo and display it (formatted) in a browser (html). Summary: 1. upload photo's and text information to database with my add article form. 2. Query the database and page the results with the text and related photo. It comes in three parts: 1. add_article.php [Text / Photo Upload Form] 2. insert_article.php [Inserts into database] 3. articles.php [View Output] Here is what I have this far:
Loop Through Array And Create Variable Session Variable Names
As part of my user authentication class I've written a method that sets session variables. I pass an array to the function by reference which contains elements populated with information from the users table in the DB (name, street, country etc) At the moment the function looks like this: /* Set the session variables for easy access to user data */ function _setSessionData(&$userData) { $_SESSION['loggedOn'] = true; // Logged on $_SESSION['userID'] = $userData['UserID']; $_SESSION['username'] = $userData['UserName']; $_SESSION['password'] = $userData['Password']; $_SESSION['firstName'] = $userData['FirstName']; $_SESSION['surname'] = $userData['Surname']; $_SESSION['email'] = $userData['Email']; $_SESSION['street'] = $userData['Street']; $_SESSION['city'] = $userData['City']; return true; } What I'm wondering is if it is possible to loop through the $userData array, and dynamically name and populate the session variables rather than listing them all and assigning like I have?
Trying To Unset Single Session Variable Unsets Entire Session
I have all the data being stored in session variables, so when the student puts in his student ID, it passes it from one page to the next. After the student votes, I use a function called logout that checks if the vote was counted, then uses session_unset($_SESSION['studentID']) and I also have a place that passes an error through session to let the user know of various problems with their login, such as if they have already voted. if voting is disabled, or if there are no candidates to vote on. The problem I am having is when I use session_unset, it unsets ALL session variables, not just the ones I want. php.net says not to use session_unregister if register_globals is disabled, which it is. What else can I do? I need to be able to unset only $_SESSION['error'] (the returned error message) and $_SESSION['studentID'], instead of unsetting the whole session.
What? Assigning A Session Variable Also Assigns The Local Variable?
Alright, In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is burns. Here is the code: $frank = "burns"; $_SESSION['frank'] = "black"; echo "DEBUG: frank's last name is is $frank"; What is coming into play here? I thought of register_globals but I thought that only dealt with GET, POST, REQUEST, etc.
Session Variable Becoming Linked To Post Variable
Basically i have a user id stored in session variable eg user_id =1. I have a simple forum that i created myself that inserts this session variable into the db with the persons entry. eg insert into forum value (session[user_id],'$_post['content']); This is all working fine until i go to edit this post from say the moderator account. I set the user_id for the "replace into db" initially to my session value unless i have selected to edit someone elses post, then i set it to the value submited back from the <form action=self> i get as far as selecting the contents from db only for the session variable holding my id to change to the value of the user_id selected from the db. Code:
Check If Session & Session Variable Exist
I'm setting up a basic "shopping cart" using a multi-dimensional array stored in a session. I want to check if the session exists & if the cart has anything in it to determine whether or not to display "view cart" or "nothing in cart" - easy enough to do. BUT, I don't want to just session_start and then check if my variable is registered - or count() the variable (I'm thinking - why start a session if there is no need to at that stage?). Seeing as you can't session_start(); before sending headers to the browser, I thought I could run this function at the very top of every page that needs to know if the cart has items in it, while trying not to start a session if one DOESN'T exist: PHP Code:
Extract Variable From Database, Then Output That Variable.
I have this strange problem (and probably also a strange question). Let's say you set a variable $blah. The variable has 'test' as content. When I write the variable ($blah) to a database (and not the content of the variable 'test') and I want to output the variable again, I get $blah as output. And not 'test'. PHP Code:
Putting Info Into A DB / Passing Info Between Pages
I have run into an issue...I have posted previously, but my scenario has changed. Here is the situation... If a user clicks on a link ('abc123' for example) I want to insert into my database some predefined information about 'abc123' - I have assigned a value that is echoed in future pages for 'abc123'. So, what I need is some mechanism to, when a user clicks 'abc123', have a pre-defined username and password be entered into the database. I need this so future pages can utilize the session values.
Session Variable...
In PHP, how do I make a session variable. Such as, the user types in his/her login name and it will display it across the whole site.
SESSION Variable
$_SESSION['value1'] = mysql_real_escape_string($_POST['dt']); $sql = "INSERT INTO $table (value1) VALUES ("$_SESSION['value1']")" Something like that doesnt work. Is my syntax incorrect?
Php Session Variable
I am stuck on something really stupid and simple. Here is what I am trying to do. Login, check the username and password against db and if it checks out then check the logged variable session and pass the user to the next page. Here is a sample of the login process page: $user = 'test' $pass = sha1('testpass'); //set the database connection variables $hostname = "localhost"; $dbusername = "newuser"; $dbpassword = "newpassword"; $dbh = mysql_connect($hostname, $dbusername, $dbpassword) or die("Unable to connect to the database"); mysql_select_db("seandb", $dbh); $result = mysql_query("select * from users where username='$user' AND password='$pass'", $dbh); //check that at least one row was returned $rowCheck = mysql_num_rows($result); if($rowCheck 0){ while($row = mysql_fetch_array($result)){ //start the session session_start(); session_register('sname'); $sname = $user; //successful login code will go here... header( "Location: main.php" ); } }else { include 'index.php' printf("Incorrect Login..."); } Then on the Main page I want to be able check the variable sname and if it is set then say hi. For some reason this doesn't happen. The variable gets assigned a variable but once it is passed over to main.php, the session variable is not there anymore. Here is the code for main.php: if (!empty($_SESSION['sname'])) { ?> <p>Welcome</p><?php echo($_SESSION['sname']);?> <?php }else{ printf("failed..."); //header( "Location: index.php" ); } For some reason I always get the "failed" message....
Session (variable)
Many people seems to have similar problem that I have but no answer has helped me. I'm using the superglobals ($_SESSION['some_variable']) and trying to check this array element after I have started a session. For example: calling login (see below) will print "Welcome Jim", but when I log out it says that I weren't logged in (even if I try to log out immediately). This is true for all other scripts that try to access any $_SESSION['variable']. ANd the setting for register_globals is on. Do I do something terribly wrong? function login(){ $userid = strtolower($_POST['userid']); if ($_POST['userid'] != "some_user"){ //Will of course be replaced to a more secure way $this->main(); }else{ session_start(); $_SESSION['userid'] = $userid; include('header.php'); if (isset($_SESSION['userid'])){ print("Welcome $userid! <br />"); }else{ print("Welcome<br />"); } } } function logout(){ if (isset($_SESSION['userid'])){ session_unset(); print("Logging out $userid"); } else{ print("You weren't logged in!"); } $this->main(); }
Session Variable?
I creating a page that will be getting refreshed multiple times. I'm running a database query and doing a fair bit of other processing, that will remain the same when the page gets refreshed. Instead of processing the same data over and over I'm wondering if I should be using session variables to save the data. I'm not too familiar with using them so I'm looking for some advice also is the following code proper usage? PHP Code:
Session Variable
I have following problem: I try to retrieve images from mysql and show it. I retrieve them in loop using getData.php. getData.php uses session variable ($_SESSION['num']) to get image. However $_SESSION['num'] seems to be always 0. why? //showAll.php <?php session_start(); $num=0; session_register('num'); ?> <html> <head><title>Show data from SQL Database</title></head> <body> <?php MYSQL_CONNECT("localhost","root","pw"); mysql_select_db("database"); $sql = "SELECT count(id) FROM store;"; $result = MYSQL_QUERY($sql); $count = MYSQL_RESULT($result,0,"count(id)"); //------------------------------------------------------------------- //here is loop where $_SESSION['num'] is set and getData.php called while($count >1) { $_SESSION['num']=$count--; echo $_SESSION['num']; ?> <IMG SRC="getData.php"> <?php } //------------------------------------------------------------------- ?> </body> </html> //------------------------------------------------------------------- //getData.php <?php session_start(); if(isset($_SESSION['num'])) { @MYSQL_CONNECT("localhost","root","pw"); @mysql_select_db("database"); $num=$_SESSION['num']; $query = "select FileData,filetype from store where id=$num"; $result = @MYSQL_QUERY($query); $data = @MYSQL_RESULT($result,0,"FileData"); $type = @MYSQL_RESULT($result,0,"filetype"); Header( "Content-type: $type"); echo $data; } ?>
Session Variable
how am i surpose to set a variable from the previous page check if its same as before if it is then leave the session variable at same value if not change it to $_post['text'] which is the new value to use . Code:
Session Variable
I am using session variables in order to insert the username into the database when the user submits a form. I was just wondering as I don't fully understand session variables could this cause any problems? For example if one user logs in and then another will the first users session vars be overwritten? (I am only making a localhost site which is run locally, so if I did this on my machine logging in two different users one in firefox one in ie would this also be ok?)
Session Variable
I'm new to php and am currently running php5 with a mysql. The program all runs except for one major issue, the session variable. The following is my session header: <?php session_start(); require "systemClasses.php"; if (!isset($_SESSION["basePage"])) {$_SESSION["basePage"] = new SemesterHandler ();}?> and for the rest of the program I just use $_SESSION["basePage"] to access my object. The program is set up in two files right now, one is index.php where you start and it reads out to a semesters.php. The object works and I have tested it the issue is the session variable. The error I'm getting is this: PHP Fatal error: main() [<a href='function.main'>function.main[/url]]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "SemesterHandler" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in C:Program FilesApache Software FoundationApache2.2htdocsUniversitySchedulerPHPsemesters.php on line 22
Use SESSION Variable?
How do I get a POST variable into a session variable so I can use it in any other page I want to use it in? Apparently posted variables are only available in the Form page in...
Overwriting Session Variable
I have a form that when a user clicks a button it sends the data from a hidden field to a session variable. When the user clicks again I want that new value to be added to the other one like with an array. When i do this though the first variable always get overwritten so I can only store 1 value.
Session Variable Calling
My main three questions here are: if I set a variable to be registered in the session, do i include the "$" in session_register?: I.E: if ($num != 0){ $verified_user = $username; session_register("verified_user"); header("Location: redirect.php"); This is part of my login script, basically if they match a person my my database, their name is registered in a variable "$verified_user" and then $verified_user" is registered as a session variable so I can call it from different pages. So my do I need to include a $? Second question: When calling the session variable "verified_user" on a different page, do I include a "$" in from on it? say I wanted to print their name, would "echo "$verified_user";" work assuming sessions were started on every page. Third Question: this ties in to the first, when I want to unregister "verified_user", do I include the "$" once again? So basically I wondering on the rules for the "$" sign and with variables.
|