Jump to content

Help Explaining This Code


Watertech

Recommended Posts

Can someone take a look at the code below. I am trying to get the session $_SESSION to be just like the second group of code that I posted. They both work individually but as soon as I use 'logged_in' instead of 'email_address' it stops showing in browser.

Maybe if I understoood the workings of the first code I can then alter it.

 

 

 

<?php
if(isset($_REQUEST['clear'])){
$email = $_SESSION['email_address'];
$query="UPDATE users SET id='', qty='', price='', name='', shipping='', addit='' WHERE email_address LIKE \"%$email%\"";
$results = mysql_query($query) or die("Error deleting cart contents");
}
if(isset($_SESSION['last_name'])){
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email_address'];
if(isset($_REQUEST['id'])){
    $id = $_REQUEST['id'];} 
if(isset($_REQUEST['qty'])){
    $qty = $_REQUEST['qty'];}   
if(isset($_REQUEST['price'])){
    $price = $_REQUEST['price'];}   
if(isset($_REQUEST['name'])){
    $name = $_REQUEST['name'];} 
if(isset($_REQUEST['shipping'])){
    $shipping = $_REQUEST['shipping'];} 
if(isset($_REQUEST['addit'])){
    $addit = $_REQUEST['addit'];}   
if(isset($id)){
$sql = mysql_query("UPDATE users SET id='$id', qty='$qty', price='$price', name='$name', shipping='$shipping', addit='$addit' WHERE last_name='$last_name' AND email_address='$email'"); 
}
?>

 

<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
echo "<h1>Logged In</h1>";
echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "
."[<a href=\"useredit.php\">Edit Account</a>]   ";
if($session->isAdmin()){
echo "[<a href=\"admin/admin.php\">Admin Center</a>]   ";
}
echo "[<a href=\"process.php\">Logout</a>]";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/100257-help-explaining-this-code/
Share on other sites

i dont know much about php.

but i think the problem is that your trying to change the array

$email - $_SESSION['email_address']

to

$email - $_SESSION['logged_in']

correct?

 

this means that any information put into 'email_address'

is lost in the code and it messes up your $email array.

you would need to go through all of your files and change any instance of 'email_address'

to 'logged_in'

other wise it would not work properly

 

ex.

i save  a notepad file as example.TXT

and then try to get information from it by entering

example.MP3 it just doesn't work. you need a music player to open an .mp3 file.

so for this case you need a so called 'email_address' "file" (not literally) to make the script work properly

it just doesn't work.

 

heres another example using a deffierent php script,

with a two file set-up.

 

this php script takes the information you submit to a form and emails it to any email you want.

this is the first file contact.php

notice the words: "firstname" "lastname" "email" "contact" and "say"

<form action="send.php" method="POST">
             <p><b>First Name</b><br/>
                <input type="text" name="firstname" size=40 />
               <br/>
              <b>Last Name:</b><b> (optional)</b>
               <input type="text" name="lastname" size=40 />
                <br />
                <b>Email:</b><br/>
                <input type="text" name="email" size=40 />
                <br />
                <br/>
                <p><select name="contact">
                  <option selected="selected">Why/who are you contacting?</option>
                  <option>I found a Problem</option>
                  </select></p>
             </p>
             <p><b>Type your statement here:</b></p>
             <p>
               <label for="say"></label>
               <textarea name="say" id="say" cols="45" rows="5"></textarea>
               <br/>
             </p>
             <p>
               <input type="submit" value=" Send ">
             </p>
           </form>]

 

ok now heres the second file named send.php

see how how send.php relates to the "send.php" on line 1 of the first code?

<?php

$email = $_POST['email'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$contact = $_POST['contact'];
$say = $_POST['say'];
$email1 = '[email protected]';


$subject = "$contact";
$message =  
"First name: $firstname 
Last Name $lastname 
Email: $email
$firstname $lastname is contacting us because of $contact
this is what they want to say: 
$say ";


if (mail($email1 , $subject,$message)) {
  echo "<h4>Thank you for sending email http://xxxxxxxxxxxxxx.com</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}?>

 

notice how the "firstname" from the first code corresponds to the ['firstname'] from the second code?

and the same with "lastname and "email"

to change the value from 'email_address' to 'logged_in' means you need to go through your script and change all the values of "email_address" to "logged in"

 

i hope this helped you in some way.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.