This is a discussion on "Inserting Session into the database" within the PHP Forum section. This forum, and the thread "Inserting Session into the database are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Inserting Session into the database
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Inserting Session into the database
Ok, I am very confuse on this one,
I have a page where users can send a message into the database which eventually the business can log in and he/she can see, his/her messages. that had been posted to his business, i am doing it with a session which, i will call later to display the messages sent to that business my problem is that the $_SESSION['BusinessName']; is not bein taken to page2. I did some testing and it takes other values to page2 but not BusinessName value here is my code for page1 please help
|
|
|
|
|||
|
Re: Inserting Session into the database
Hi I am quite new to php but looking at your code on page1 shouldnt you have something like this.
|
|
|||
|
Re: Inserting Session into the database
ok, that is what i have
|
|
|||
|
Re: Inserting Session into the database
this is the code you posted.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> if(isset($_GET['BusinessName'])){ $query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName' "; $result = mysql_query($query) or die (mysql_error()); $row = mysql_fetch_assoc($result); $BusinessName= ($row['BusinessName']); $Keyword =($row['Keyword']); $Picture1 = ($row['Picture1']); $Headline = ($row['Headline']); $Slogan2 = ($row['Slogan2']); $Description1 =($row['Description1']); $Description2 = ($row['Description2']); $Description3= ($row['Description3']); $Contact2 = ($row['Contact2']); $Picture2 = ($row['Picture2']); $Picture3 = ($row['Picture3']); $Business_Address=($row['Business_Address']); $make=($row['make']); $type=($row['type']); $Tel=($row['Tel']); $Website=($row['Website']); } ?> There is no <? between </head> and if(isset($_GET['BusinessName'])){ |
|
|||
|
Re: Inserting Session into the database
In your first script:
$_SESSION['BusinessName'] ='$BusinessName'; should be $_SESSION['BusinessName'] = $BusinessName; (test var is ok with the quotes since its a string). In your page 2 script: $BusinessName = addslashes($_POST['BusinessName']); is used ok here but later in your code you reload the same var again without the slashes so you're over writing your BussinessName var! Rather than use [SESSION] so much (which you can do) I declare my php vars needed as globals as globals - that way I can access them from any script. I also use this naming convention so I know a global php var from a local php var: $php_g_var = 'test'; // global var $php_var is a local var. Being new to php you may not know that the form that does the post method call will pass all of it's html tag objects to the called php script ONLY! Therfore, you have to use or assign to global vars those values from the calling form. Yolu can't use those html object values on any other php script other than the one called in the method post. For example I can do this in the called php script: $php_g_var = $chk_include_reports; Assigns checkbox true or false to a php global var. You cannot do this from your page 2 script - it won't work. So you have to store the value in a global php var. I hope this helps. RalphF GoldRushWebHosting.com |
|
|||
|
Ok, it is making some sense to me now, So basicly i am destroying BusinessName value on page2
ok Here is my question where i place BusinessName = addslashes($_POST['BusinessName']); because i added it at the top of the page where i open the session and i was still getting the same error i guess, i will nee a little bit of help here |
|
|||
|
Re: Inserting Session into the database
This line:
BusinessName = addslashes($_POST['BusinessName']); should be like this: $BusinessName = $_POST['BusinessName']; You don't need the addslashes() function and you forgot the $ char on the php var. Try that - if that doesn't work, show me your code thus far. RalphF GoldRushWebHosting.com |
|
|||
|
Re: Inserting Session into the database
Well that didnt work
here is my full code for page2
|
|
|||
|
Re: Inserting Session into the database
Your still pulling BusinessName from a POST[] - is this a php var or it is a form html object tag? See why it's important to develop a naming convention for your php vars? Your code isn't easily maintainable and when you come back to this code in 3 months you won't recall either (I'm guessing, you might!).
Since this is page 2 I'm guessing it's being called from your php script that was called from your main form post? Is this correct? In other words, your page 2 script was called from your 'dispatcher' php script correct? If page 2 is called from the 'dispatcher' script then you need to make sure you are sending BusinessName as an argument otherwise you won't be able to pick up its value. This is the big reason I first mentioned to use global php vars - this wouldn't happen if you had set BusinessName value in the post method called script. Once you set it in that script you can use it anywhere - but let's continue on where you are for now. I know this may seem a bit complex but it's not really. You just need to understand the structure of a php form page and how php grabs the html object tag values (checkboxes, text boxes, etc.). How about using a little debugging like this (below your first line) $BusinessName = $_POST['BusinessName']; print 'BusinessName '.$BusinessName."<br>"; exit; Run your code and see what the value is if anything - if its blank then your not grabbing the post data and you'll want to look at how your passing it from the calling script which I think is the key question at this point. Don't give up!!! We'll get it. RalphF GoldRushWebHosting.com Last edited by rfresh; Jun 16th, 2007 at 22:28. |
|
|||
|
Re: Inserting Session into the database
I guess, i had not post all my code really,
Well, this is what i display with the print BusinessName on page2 because really, i am not selectin anything on page2, i am inserting values into the table name message. i just need the BusinessName value that come from page1 through a session, But then it is not giving me any value i will post my full value for page2
|
|
|||
|
Re: Inserting Session into the database
Well, i did something and it is working now, honestly, i dont know what i did but it works
thank u |