OK, this is my entire code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

OK, this is my entire code

Post by pinehead18 »

I get $pic by the url which looks like http://url.com/edit_pics.php?pic=pic2
So i try to set the session so when i try and upload the file it remebers
pi2, but when i upload the page it seems to loose the session.

if your browse down towards the middle of the page and look for
MY PROBELM then you will see the rest of the session code and wehere it
looses it at.

Thank you for any help you can provide me with.

Code: Select all

<?php 
session_start(); 
$_SESSION["pic"] = $_GET['pic']; 
$pic = $_SESSION["pic"]; 
$_SESSION["newpic"] = $pic; 
print $_SESSION["newpic"]; 
include('includehtml.inc'); 
$name = $HTTP_COOKIE_VARS['user']; 

$con = mysql_connect("localhost","pinehead","") or die(mysql_error()); 
        $db = mysql_select_db("pinehead",$con) or die(mysql_error()); 
        $sql = "SELECT * FROM users WHERE user='$name'"; 
        $result =  mysql_query($sql,$con); 
        $row = mysql_fetch_array($result); 
        $picname = $row['pic_url']; 
        $pictrue = $row['pic']; 
    mysql_close(); 

if ($_POST['updatepic']) { 
        $con = mysql_connect("localhost","pinehead","") or
die(mysql_error()); 
        $db = mysql_select_db("pinehead",$con) or die(mysql_error()); 
        $sql = "UPDATE users SET pic_text='$update' WHERE user='$name'"; 
        mysql_query($sql,$con); 
        mysql_close(); 
} 
   

if (isset($_FILES['file']['name'])) { 
    if ((($_FILES['file']['type'] == 'image/gif') ||
($_FILES['file']['type'] == 'image/pjpeg')) &&
(($_FILES['file']['size'] 
< 512000))) { 
    // Rename file using the date rename 
    // Get the extention then rename it and past the extention back onto the name 
        $ext = explode(".",$_FILES['file']['name']); 
        $mydate = date('Ymdhis'); 
        $newname = "image$mydate.$ext[1]"; 
        echo $newname; 
        if (file_exists('pics/' . $newname)) { 
        echo "File already exists!"; 
    } else { 
// Upload the file to the new location with the new name 

            move_uploaded_file($_FILES['file']['tmp_name'],
$_SERVER['DOCUMENT_ROOT'] . 'pics/' . 
$newname); 
        echo "File uploaded sucessfully."; 
     

// OTHER PART OF MY PROBLEM 



// Here i'm trying to pull pic2 from the session created at the begginning of
//the page yet it wont - thats my probel please help if you can 


session_start();; 
    $pic = $_SESSION["newpic"]; 
echo "</p>"; 
    print $_SESSION["newpic"]; 
    echo "</p>"; 
// end grab 
    $con = mysql_connect("localhost","pinehead","") or die(mysql_error()); 
    $db = mysql_select_db("pinehead",$con) or die(mysql_error()); 
    echo $pic; 
//    $sql = "UPDATE users SET ".$pic_id."='".$newname."', pic='true'
//WHERE user='".$name."'"; 
    $sql =  "UPDATE users SET $pic='$newname', pic='true' WHERE
user='$name'"; 
    mysql_query($sql,$con); 
    mysql_close($con); 
    $oldpic = "/home/pinehead/www/pics/$picname"; 
    if ($pictrue == "true") { 
    unlink($oldpic); 
    } 
    echo $newpicname; 
    echo $name; 
     
    } 
    } else { 
        echo "There was a problem uploading the file. Image restrictions were not
met."; 
        echo $_FILES['file']['error'] . "<br>"; 
        echo $_FILES['file']['type'] . "<br>"; 
        echo $_FILES['file']['size']; 
    } 
} else { 
    echo "No file was submitted or there was an error. Err num: "; 
    echo $_FILES['file']['error'] . "<br>"; 
    echo $_FILES['file']['type'] . "<br>"; 
    echo $_FILES['file']['size']; 
} 

?> 


<table border=0 cellpadding=0 cellspacing=0 width=97%> 
        <tr><td>Upload or change your picture below</td></tr> 
</table> 
<table cellpadding=0 cellspacing=0 width=97%> 
        <tr><td align=center> 
        <table border=0 cellpadding=0 cellspacing=0 width=80%> 
        <tr><td> 
        In order to add a picture to your profile or to update a current picture
on 
your profile, click on the "Browse" button 
below and select the picture file on your computer you wish to upload.  Once you
have selected the file click on "Submit 
Picture" and the picture will be added to your profile.  You will be able to
see your current picture at the bottom of the 
page.</p> </tr></td></table> 

<form action=edit_pics.php method=post enctype=multipart/form-data> 
    <input type=file name=file><br> 
    <input type=submit value='Submit form'> 
</form></tr></td></table> 
<table border=0 cellpadding=0 cellspacing=0 height=3> 
        <tr><td>&nbsp;</td</tr> 
</table> 

<?PHP 
    $con = mysql_connect("localhost","pinehead","") or die(mysql_error()); 
    $db = mysql_select_db("pinehead",$con) or die(mysql_error()); 
    $sql = "SELECT * FROM users WHERE user='$name'"; 

     $result =  mysql_query($sql) or die(mysql_error()); 
        $row =  mysql_fetch_array($result) or die(mysql_error()); 


    $picname = $row['pic_url']; 
    $pic = $row['pic']; 
    $pictext = $row['pic_text']; 
    mysql_close($con); 
?> 

<?php 
        if($_POST['delete']) { 
    $picer = "/home/pinehead/www/beta/pics/$picname"; 
        unlink($picer); 
        echo $picname; 
        echo " has successfully been removed"; 
    $default_pic = "nopic.jpg"; 
    $con = mysql_connect("localhost","pinehead","") or die(mysql_error()); 
    $db = mysql_select_db("pinehead",$con) or die(mysql_error()); 
    $sql = "UPDATE users SET pic_url='$default_pic', pic='false'"; 
    mysql_query($sql); 
        } 
?> 
<table border=0 cellpadding=0 cellspacing=0 width=97% align=center> 
    <tr><td>Your profile picture</td></tr> 
</table> 
<table border=0 cellpadding=0 cellspacing=0 width=97%> 
    <tr><td width=80%> 
    In order to update your picture you may upload a new one without deleting the
existing one. 
    If you would like to delete it alltogether click the delete link and your
picture will be removed. 
    </tr></td> 
    <tr><td align=center> 
    <?php 
    if ($pic == "false") { 
        echo ""; 
    } else { 
        echo "<img src=http://lifeinkc.com/pics/$picname>"; 
        echo "<br><form method=post action=edit_pics.php> 
        <input type=submit name='delete' value='Delete Picture'> 
        </form>"; 
    } 
    ?> 
        </tr></td> 
</table> 
<table border=0 cellpadding=0 cellspacing=0 width=97%>      
    <tr><td>&nbsp;</td></tr> 
</table> 
<?php 
    if($id == "main") { 

echo "<table border=0 cellpadding=0 cellspacing=0 width=97%> 
        <tr><td>Piction text</td></tr> 
</table> 
<table border=0 cellpadding=0 cellspacing=0 width=97% align=center> 
        <tr><td align=center>   
        <table border=0 cellpadding=0 cellspacing=0 width=80% align=center> 
        <tr><td> 
       This is your picture text area, what you type below will show up directly
under your picture on your profile.  You 
are only allowed 155 charecters so choose your words wisely!</p> 



    <center><form action=edit_pics.php method=post> 
        <input type=text name='update' value=$pictext> 
        &nbsp;<input type=submit name='updatepic' value=Update> 
    </form> 


</p> </tr></td></table>"; 

} else { 

echo ""; 

} 


include('includefooter.inc'); 

?>
That is all of my code.. The problem is with sessions.. I think my // COmments describe my problem and where it is at
IF you have any questions please ask and if you have any solutions to my problem PLEASE help i pulled my hair out over this session problem all night for about 3 hours.

Thank you so much.
Anthony
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

eeck. please put your code in the [ php] [ /php] tags!!
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

I cannot edit the post.. Would you like me to compeltly re-post it again
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

when logged in you should have a button "edit" in the top/right corner of each of your posts.

I've added the

Code: Select all

tags for you, excluding the first (comment-)text and extending the comments to the second line of[quote]// Here i'm trying to pull pic2 from the session created at the begginning of
//the page yet it wont - thats my probel please help if you can[/quote][quote]//    $sql = "UPDATE users SET ".$pic_id."='".$newname."', pic='true'
//WHERE user='".$name."'";[/quote]
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Thank you for editing that.. NOw hopefulyl someone will help me out with it lol
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

oops, does another script start at // OTHER PART OF MY PROBLEM?

edit: no, doesn't seem so. But why another session_start() then?
edit #2: if the code is in more than one file could you please show me where each file starts and end?
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

No, it is all one page.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$_SESSION["pic"] = $_GET['pic'];
$pic = $_SESSION["pic"];
$_SESSION["newpic"] = $pic;
what do you use $_SESSION["pic"] and $_SESSION["newpic"] for?
$sql = "UPDATE users SET pic_text='$update' WHERE user='$name'";
where does $update come from?
$newname = "image$mydate.$ext[1]";
what happens with image-names like just.a.test.jpeg?
hmmm...there's quite a lot strange to me.
Let's start with

Code: Select all

<?php
error_reporting(E_ALL);   // Let's see
ini_set('display_errors', TRUE); // wether php want's to tell you something

session_start();
$_SESSION["pic"] = $_GET['pic'];
$pic = $_SESSION["pic"];
$_SESSION["newpic"] = $pic;
print $_SESSION["newpic"];
include('includehtml.inc');
Does this shed some ligth on your problem?
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

IF you havea better way to work the sessions please let me know.> The problem is the session wont hold the info of $pic and i need it to so my upload script knows what sql feild to upload it to.

I'm half tempted just to write a cookie and have it do that for now.
Post Reply