php-general Digest 5 Aug 2011 04:49:13 -0000 Issue 7429

Topics (messages 314350 through 314369):

Re: Keyword Constructor
        314350 by: contact.global-web-designs.com

Re: Studying mcrypt
        314351 by: Donovan Brooke
        314352 by: Donovan Brooke
        314353 by: Alex Nikitin
        314358 by: Donovan Brooke

Complex (or not so) array data form submission?
        314354 by: Jamie Krasnoo
        314355 by: Andrew Ballard
        314356 by: Jamie Krasnoo
        314359 by: Andrew Ballard
        314360 by: Shawn McKenzie

Re: Form Already Filled Out
        314357 by: Ashley Sheridan

Re: testing
        314361 by: Tamara Temple

memory overflow :/
        314362 by: Tontonq Tontonq

saving sessions
        314363 by: wil prim
        314364 by: Midhun Girish

control structure
        314365 by: Chris Stinemetz
        314367 by: admin.buskirkgraphics.com
        314368 by: Chris Stinemetz

You can play with PHP 5.4.0 alpha3 on Windows, EasyPHP 5.4 alpha3 is out!
        314366 by: EasyPHP

Sending a message
        314369 by: wil prim

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
hello everyone. 

thanks for the email  re keyword constructor.  

but what exactly does it do?  i.e its function. 

warmest regards 

Andreea 

-----Original Message-----
From: Ren [mailto:lobbyjo...@gmail.com] 
Sent: 02 August 2011 06:29
To: php-gene...@lists.php.net
Subject: [PHP] Keyword Constructor

For a long time I wanted keyword parameters in PHP.  But thanks to newer 
features like traits and reflection classes I have come up with something that 
looks pretty close.

    trait KeywordConstructor {
        public function __construct($members) {
            $class = new ReflectionClass($this);
            $properties = $class->getProperties();

            foreach ($properties as $p) {
                $name = $p->getName();

                if (isset($members[$name])) {
                    $this->$name = $members[$name];
                }
            }
        }
    }

     class User {
         use KeywordConstructor;
         private $name;
         private $age;
     }

    $lobby = new User(['name' => 'Lobby', 'age' => 36]);

Right now this requires the trunk version of PHP to work.  I just wanted to 
share this in case anyone finds it interesting and/or useful.

--
ejmr
南無妙法蓮華經



--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: 
http://www.php.net/unsub.php




--- End Message ---
--- Begin Message ---
Alex Nikitin wrote:
[snip]
What makes your local system any less vulnerable of a point than your
server, of anything, its more vulnerable and failure-prone, so unless i'm
not getting something, that seems like a poor design decision (i'm sorry)
[snip]


In the model I profiled, it is a system design that * requires * the ability to retrieve secured data. For my solution, they would have to have physical entry into the premises that hold the key/s (local encryption done offline).

Donovan



--
D Brooke

--- End Message ---
--- Begin Message ---
Alex Nikitin wrote:
[snip]
There is code obfuscation with PHP, and you can compile it into C++ with
HipHop for php for example...
[snip]


Of course, obfuscation is never a great security solution. Compiling it into C++ is interesting... the question would be if the code could be de-compiled.. if so, then probably not a great solution either.

Donovan

--
D Brooke

--- End Message ---
--- Begin Message ---
On Thu, Aug 4, 2011 at 12:23 PM, Donovan Brooke <li...@euca.us> wrote:

> Alex Nikitin wrote:
> [snip]
>
>  There is code obfuscation with PHP, and you can compile it into C++ with
>> HipHop for php for example...
>>
> [snip]
>
>
> Of course, obfuscation is never a great security solution. Compiling it
> into C++ is interesting... the question would be if the code could be
> de-compiled.. if so, then probably not a great solution either.
>
>
> Donovan
>
> --
> D Brooke
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
It's never a good idea to store all your keys in code, that is why we have
an iv, and a salt that you can use... neither is program encryption, since i
can dump it in it's executing form out of memory fairly easily; this is why
hard drive encryption without a controller that does crypto off the main
system is fairly pointless...

--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late.  ~Seymour Cray

--- End Message ---
--- Begin Message ---
Alex Nikitin wrote:
[snip]

It's never a good idea to store all your keys in code,


True, but in the system I was referring to, only the closed source
app knows how to "see" the key in the encrypted templates and there is no way for another to know how to decrypt the encrypted templates to see any of the other keys in the code... It's a unique solution for this type of topic. I don't want to go into too many details because it's not about PHP and my intention with bringing it up was to see if others knew of a similar solution within PHP.. which I'm thinking there is not.


that is why we have
an iv, and a salt that you can use... neither is program encryption, since i
can dump it in it's executing form out of memory fairly easily;


Well, not with the situation/app I was talking about..


this is why
hard drive encryption without a controller that does crypto off the main
system is fairly pointless...


I'm not exactly sure what you are saying here.. but there are good reasons to have built the system that I was referring to... safe retrieval of secured data being the main idea.

Look, I agree that in a typical online passphrase type of setup, creating a hash to be matched for access is a great solution under sensitive situations. You don't need to retrieve the pass as the owner can change it if they forget... however, encryption is absolutely not worth nothing and the O.P. stated he was trying to learn about PHP's mcrypt.

Much of the time, a spec requires the access retrieval of secured data and a developer will have no choice anyway ;-). Not all sensitive data is at the same sensitivity level either... so mcrypt has its place.

Cheers,
Donovan


--
D Brooke

--- End Message ---
--- Begin Message ---
Hey all,

I get the basics of submitting a form and organizing the $_POST data within
arrays (name[], name[key], etc). But if I wanted to submit something like
multiple addresses and have it end up organized in array form like this from
submission is this possible?

$addresses = array(
    0 => array(
        'id'             => '1',
        'address1' => '...',
        'address2' => '...',
        'city'          => '...',
        'state'        => '...',
        'zip'           => '...'
    ),
    1 => array(
        'id'             => '2',
        'address1' => '...',
        'address2' => '...',
        'city'          => '...',
        'state'        => '...',
        'zip'           => '...'
    )
);

For some reason I can't seem to come up with the right naming schema in
forms in order to get this structure.

Jamie

--- End Message ---
--- Begin Message ---
On Thu, Aug 4, 2011 at 1:18 PM, Jamie Krasnoo <jkras...@gmail.com> wrote:
>
> Hey all,
>
> I get the basics of submitting a form and organizing the $_POST data within
> arrays (name[], name[key], etc). But if I wanted to submit something like
> multiple addresses and have it end up organized in array form like this from
> submission is this possible?
>
> $addresses = array(
>    0 => array(
>        'id'             => '1',
>        'address1' => '...',
>        'address2' => '...',
>        'city'          => '...',
>        'state'        => '...',
>        'zip'           => '...'
>    ),
>    1 => array(
>        'id'             => '2',
>        'address1' => '...',
>        'address2' => '...',
>        'city'          => '...',
>        'state'        => '...',
>        'zip'           => '...'
>    )
> );
>
> For some reason I can't seem to come up with the right naming schema in
> forms in order to get this structure.
>
> Jamie

It should be pretty straight foward. Your fields would have name such as these:

name="addresses[0][id]"
name="addresses[0][address1]"
name="addresses[0][address2]"
name="addresses[0][city]"
name="addresses[0][state]"
name="addresses[0][zip]"

And so on.

Andrew

--- End Message ---
--- Begin Message ---
Thanks. I think what I got hung up on was that I was trying this:

name="addresses[][id]"
name="addresses[][address1]"
name="addresses[][address2]"
name="addresses[][city]"
name="addresses[][state]"
name="addresses[][zip]"

Which wouldn't have given the end result I sought, I don't think. Clear case
of not seeing the forest for the trees.

Jamie

On Thu, Aug 4, 2011 at 10:31 AM, Andrew Ballard <aball...@gmail.com> wrote:

> On Thu, Aug 4, 2011 at 1:18 PM, Jamie Krasnoo <jkras...@gmail.com> wrote:
> >
> > Hey all,
> >
> > I get the basics of submitting a form and organizing the $_POST data
> within
> > arrays (name[], name[key], etc). But if I wanted to submit something like
> > multiple addresses and have it end up organized in array form like this
> from
> > submission is this possible?
> >
> > $addresses = array(
> >    0 => array(
> >        'id'             => '1',
> >        'address1' => '...',
> >        'address2' => '...',
> >        'city'          => '...',
> >        'state'        => '...',
> >        'zip'           => '...'
> >    ),
> >    1 => array(
> >        'id'             => '2',
> >        'address1' => '...',
> >        'address2' => '...',
> >        'city'          => '...',
> >        'state'        => '...',
> >        'zip'           => '...'
> >    )
> > );
> >
> > For some reason I can't seem to come up with the right naming schema in
> > forms in order to get this structure.
> >
> > Jamie
>
> It should be pretty straight foward. Your fields would have name such as
> these:
>
> name="addresses[0][id]"
> name="addresses[0][address1]"
> name="addresses[0][address2]"
> name="addresses[0][city]"
> name="addresses[0][state]"
> name="addresses[0][zip]"
>
> And so on.
>
> Andrew
>

--- End Message ---
--- Begin Message ---
On Thu, Aug 4, 2011 at 2:04 PM, Jamie Krasnoo <jkras...@gmail.com> wrote:
> Thanks. I think what I got hung up on was that I was trying this:
>
> name="addresses[][id]"
> name="addresses[][address1]"
> name="addresses[][address2]"
> name="addresses[][city]"
> name="addresses[][state]"
> name="addresses[][zip]"
>
> Which wouldn't have given the end result I sought, I don't think. Clear case
> of not seeing the forest for the trees.
>
> Jamie

It probably would have worked just fine. Not specifying the numeric
index means that PHP will depend on the order that the browser sends
the values, but they are generally sent in the order they appear on
the form. If the numeric index is important, it's better to provide it
explicitly.

Andrew

--- End Message ---
--- Begin Message ---
On 08/04/2011 01:56 PM, Andrew Ballard wrote:
> On Thu, Aug 4, 2011 at 2:04 PM, Jamie Krasnoo <jkras...@gmail.com> wrote:
>> Thanks. I think what I got hung up on was that I was trying this:
>>
>> name="addresses[][id]"
>> name="addresses[][address1]"
>> name="addresses[][address2]"
>> name="addresses[][city]"
>> name="addresses[][state]"
>> name="addresses[][zip]"
>>
>> Which wouldn't have given the end result I sought, I don't think. Clear case
>> of not seeing the forest for the trees.
>>
>> Jamie
> 
> It probably would have worked just fine. Not specifying the numeric
> index means that PHP will depend on the order that the browser sends
> the values, but they are generally sent in the order they appear on
> the form. If the numeric index is important, it's better to provide it
> explicitly.
> 
> Andrew

What Jamie posted is equivalent to this:

name="addresses[0][id]"
name="addresses[1][address1]"
name="addresses[2][address2]"
name="addresses[3][city]"
name="addresses[4][state]"
name="addresses[5][zip]"

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On Thu, 2011-08-04 at 17:02 +0100, jean-baptiste verrey wrote:

> if you want to force the browser to not be able to have this behaviour you
> need the name tag to always change
> a quick example would be that
> <?php // keep the name in session
> $_SESSION['formRandomName']=time();
> ?>
> <input type="password" name="<?php
> echo $_SESSION['formRandomName'];?>[password]" />
> 
> 
> 2011/8/4 Bálint Horváth <hbal...@gmail.com>
> 
> > Hi,
> > Use value="$_POST['user']" or sg like that because:
> > before send value eq null, after if returned -cause of a fail- the inputs
> > remain
> >
> > also set *autocomplete="off"* (at form) and if it doesn't work use js
> > to set null values to input boxes (add a name for ur form...)
> >
> > Another way, use Google: "javascript turn off autofill"
> >
> > be careful:
> > http://www.php.net/manual/en/security.database.sql-injection.php
> > http://php.net/manual/en/security.php
> >
> > *Valentine*
> >
> > On Thu, Aug 4, 2011 at 8:54 AM, James Yerge <ja...@nixsecurity.org> wrote:
> >
> > > On 08/05/2011 12:43 AM, wil prim wrote:
> > > > Hello, Soooo i created a simple login system, and I am using sessions
> > > Everything
> > > > seems to work fine, however; when I upload my files to my server and
> > type
> > > my
> > > > domain name my index.php page comes up and the form is automatically
> > > filled out
> > > > with a username and password. How do i make it empty when I initially
> > > enter the
> > > > site, and yes I did create a logout.php file that destroys a session.
> > > Please
> > > > help, it is hard to explain this when I cant show it in person. Thanks
> > in
> > > advance!
> > > >
> > > > Here is the login.php code, i didn't md5() the password yet:
> > > >
> > > >
> > > > <?php
> > > >
> > > > if ($_SESSION['user'])
> > > > {
> > > > header("Location: error.php");
> > > > exit();
> > > > }
> > > > include('connect.php');
> > > > if ($_POST['login']){
> > > >
> > > >
> > > > $user=$_POST['user'];
> > > > $pass=$_POST['pass'];
> > > > $sql="SELECT * FROM members WHERE username='$_POST[user]' and
> > > > password='$_POST[pass]'";
> > > > $result=mysql_query($sql, $con);
> > > > $count=mysql_num_rows($result);
> > > > if ($count==1){
> > > > $_SESSION['user'] = $user;
> > > > header('location: home.php');
> > > > }
> > > > else
> > > > echo "<p style='color:red'>Wrong Username or Password</p>";
> > > > }
> > > >
> > > > ?>
> > > > <html>
> > > > <head>
> > > > <title></title>
> > > > <link href="style.css" rel="stylesheet" type="text/css" />
> > > > </head>
> > > > <body>
> > > >
> > > > <div id="main">
> > > > <div id="menu">
> > > > <ul>
> > > > <li>
> > > > <a href="#">Home</a>
> > > > </li>
> > > > <li>
> > > > <a href="#">Topix</a>
> > > > </li>
> > > > <li>
> > > > <a href="#">Mission</a>
> > > > </li>
> > > > </ul>
> > > > </div>
> > > > <div id='content'>
> > > > <form method='post' action='index.php'>
> > > > Username: <br/>
> > > > <input type='text' name='user' maxlength='30'/><br/>
> > > > Password: <br/>
> > > > <input type="password" name='pass' maxlength='30'/><br/>
> > > > <input type="submit" value="Log In!" name="login"/>
> > > > </form>
> > > > <a href="register.html"> Register? </a>
> > > >
> > > > </div>
> > > > </body>
> > > > </html>
> > >
> > > Your browser is more than likely filling in the username and password
> > > fields for you, automatically. Most modern browsers offer this
> > > functionality by default. What you're looking for isn't relative to PHP.
> > >
> > > Have you tried visiting your page from multiple browsers, to see if you
> > > get the same results?
> > >
> > > You could set the value of the username and password fields in the form
> > > to NULL.
> > >
> > > e.g.;
> > > <input type='text' name='user' value='' maxlength='30'/>
> > > <input type="password" name='pass' value='' maxlength='30'/>
> > >
> > > I doubt your visitors are going to encounter the same issue you are,
> > > unless they allow their browser or some other 3rd party software to
> > > automatically fill in the form values for them.
> > >
> > > Another method would consist of using JavaScript, once the DOM is ready
> > > (all elements rendered), have JavaScript reset the form values.
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >


Please don't top-post, the gremlins don't like it :)

Going back to Bálint's post, the autocomplete="off" can be set either at
the form or form element (input) level. Bear in mind though that if you
do this, the HTML will not validate. This isn't normally an issue, and
may be an acceptable tradeoff for your website.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---

On Aug 4, 2011, at 10:21 AM, Jim Giner wrote:

Because I'm lazy. I LIKE the newsgroup method - all my mail in one place: email, newsgroups together yet separate so that I can read the news postings
when I have time, and the email is purely mine.
"Tim Streater" <t...@clothears.org.uk> wrote in message
news:08.87.13433.b57ba...@pb1.pair.com...
On 04 Aug 2011 at 15:48, Jim Giner <jim.gi...@albanyhandball.com> wrote:

Sounds like time for me to move on.
Thanks for the info Dan.

Perhaps so, when to support your laziness you expect other to spend lots of uncompensated effort....
--- End Message ---
--- Begin Message ---
hi  i can't see anything wrong that will cause memory problem

but parsing 1gb memory limit doesn't come enough for just parsing a 50 kb
file

but when i try to parse another file that is 24 kb 24 mb becomes enough
memory

here is the script

http://pastebin.com/H9mG7ucU

if you go to
rss.php?id=175069119656&titlebaslik=1

no problem

when you try to parse
rss.php?id=102741716484127&titlebaslik=1

Allowed memory size of 25165824 bytes exhausted (tried to allocate 90564532
bytes)

Just tried to increase with

ini_set('memory_limit','2048M');
still same error
Allowed memory size of -2147483648 bytes exhausted (tried to allocate
2137883596 bytes) in rss.php  on line 24

any idea ?

--- End Message ---
--- Begin Message ---
Hello, im new to the whole storing sessions thing and I really dont know how to ask this question, but here it goes.  So on my site when someone logs in the login.php file checks for a the username and password in the table i created, then if it finds a match it will store a $_SESSION [] variable. To be exact the code is as follows:
if ($count=='1')
{
session_start();
$_SESSION['user']=$user;   // $user is the $_POST['user'] from the login form
header('location: login_success.php');
}

Now what i would like to know is how do i make my website save new changes the user made while in their account?

thanks!


--- End Message ---
--- Begin Message ---
On Sat, Aug 6, 2011 at 7:56 AM, wil prim <wilp...@me.com> wrote:

> Hello, im new to the whole storing sessions thing and I really dont know
> how to ask this question, but here it goes.  So on my site when someone logs
> in the login.php file checks for a the username and password in the table i
> created, then if it finds a match it will store a $_SESSION [] variable. To
> be exact the code is as follows:
> if ($count=='1')
> {
> session_start();
> $_SESSION['user']=$user;   // $user is the $_POST['user'] from the login
> form
> header('location: login_success.php');
> }
>
> Now what i would like to know is how do i make my website save new changes
> the user made while in their account?
>
> thanks!
>
>

You will have to store the user account related data in the database for
persistence.... Or if the site not having a 'user account system'  you may
use cookies to store the settings...



Midhun Girish

--- End Message ---
--- Begin Message ---
I have a php script with a simple condition. If it is not satisfied I
want to exit the script otherwise I want to continue. I am having
difficulties getting it to work. The script is just exiting..

Please excuse my indention. Gmail tends to distort it.

Thank you,

Chris

This is what i have so far:

    if (!session_id())
        {
        session_start();
        }
    if($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 1
|| $_SESSION['user_level'] != 2  )
        {
        //the user is not an admin
        echo 'Sorry, you do not have sufficient rights to access this page.<br/>
              You must be a technician or an engineer to create a store visit.';
        
              exit;
        }
        else {
            continue;
        


If I get it to continue I want to execute the rest of the script, but
It will only exit. Current user has user_level of 1 so that is not an
issue.

Rest of script:

    $market = isset($_GET['market']) ? $_GET['market'] : $_SESSION['market'];
    $type = isset($_GET['type']) ? $_GET['type'] : $_SESSION['type'];
    $store = isset($_GET['store']) ? $_GET['store'] : $_SESSION['store'];

    $type = str_replace('-', ' ', $type);

    if($_SESSION['type'] != $type)
        {
        $_SESSION['type'] = $type;
        $store = '';
                }

    if($_SESSION['market'] != $market)
        {
        $type = '';
        $store = '';
        }

        $_SESSION['market'] = $market;
        $_SESSION['type'] = $type;
        $_SESSION['store'] = $store;

        $market_name = array();
        $market_prefix = array();
        $type_name = array();
        $market_prefix = array();
        $store_name = array();


    $query = "SELECT * FROM marketcode " ;
    $result = mysql_query($query) or die(report($query,__LINE__
,__FILE__)); //("Something went wrong");

        while($row = mysql_fetch_array($result))
        {
        $market_name[] = $row['market_name'];
        $market_prefix[] = $row['market_prefix'];
        }

    $query = "SELECT store_type FROM store_type WHERE market_prefix =
'$market' "     ;
    $result = mysql_query($query) or die(report($query,__LINE__
,__FILE__));

        while($row = mysql_fetch_array($result))
        {
        $type_name[] = $row['store_type'];
        }

        $type_name = array_unique($type_name);
        sort($type_name);

        if($type == '')
            {
            $type = $type_name[0];
            $_SESSION['type'] = $type;
            }

    $query = "SELECT store_name FROM store_list WHERE store_type =
'$type' AND market_prefix = '$market' "      ;
    $result = mysql_query($query) or die(report($query,__LINE__ ,__FILE__));
                
    while($row = mysql_fetch_array($result))
        {
        $store_name[] = $row['store_name'];
        }
             //   include ('includes/closedb.php');
   // close dB
        sort($store_name);
     }
?>

        <div id="myspan">
        <form action="index.php" method="post">
            <table>
                <tr>
                    <th class="market">Market</th>
                    <th class="type">Store Type</th>
                    <th class="store">Store Name</th>
                </tr>
                <tr>
                    <td>
                    <select name="market"
onchange="javascript:get(this.parentNode);">
                                        <option value="">Choose...</option>
                    <?php                                       
                        foreach($market_prefix as $key => $value)
                            {
                            $selected = '';
                            if($value == $market)
                            {
                            $selected = 'selected';
                            }
                            //echo("<option value=$value $selected
>$value : $market_name[$key]");
                                                        echo '<option value="', 
htmlspecialchars($value), '" ',
$selected, '>', htmlspecialchars($value.' : '.$market_name[$key]),
'</option>';
                            }
                            ?>
                    </select>
                    </td>
                    <td>
                    <select name="type"
onchange="javascript:get(this.parentNode);">
                                        <option value="">Choose...</option>
                    <?php
                        foreach($type_name as $value)
                            {
                            $selected = '';
                            if($value == $type)
                            {
                            $selected = 'selected';
                            }
                            $v = str_replace(' ', '-', $value);
                            //echo("<option value=$v $selected >$value");
                                                        echo '<option value="', 
htmlspecialchars($v), '" ', $selected,
'>', htmlspecialchars($value), '</option>';
                            }
                    ?>
                    </select>
                    </td>
                    <td>
                    <select name="store">
                                        <option value="">Choose...</option>
                    <?php
                        foreach($store_name as $value)
                            {
                            echo("<option value=$value>$value");
                    }
                    ?>
                    </select>
                    </td>
                    </tr>
                    <tr>
                    <td>
                        <p>
                            <input type="hidden" name="step" value="2">
                            <input type="submit" name="submit" value="Submit">
                        </p>
                    </td>
                    </tr>
            </table>
        </form>
    </div>
    </body>
</html>

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Chris Stinemetz [mailto:chrisstinem...@gmail.com]
> Sent: Thursday, August 04, 2011 11:34 PM
> To: PHP General
> Subject: [PHP] control structure
> 
> I have a php script with a simple condition. If it is not satisfied I
> want to exit the script otherwise I want to continue. I am having
> difficulties getting it to work. The script is just exiting..
> 
> Please excuse my indention. Gmail tends to distort it.
> 
> Thank you,
> 
> Chris
> 
> This is what i have so far:
> 
>     if (!session_id())
>       {
>       session_start();
>       }
>     if($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 1
> || $_SESSION['user_level'] != 2  )
>       {
>       //the user is not an admin
>       echo 'Sorry, you do not have sufficient rights to access this
> page.<br/>
>             You must be a technician or an engineer to create a store
> visit.';
> 
>             exit;
>       }
>       else {
>           continue;
> 
> 
> 
> If I get it to continue I want to execute the rest of the script, but
> It will only exit. Current user has user_level of 1 so that is not an
> issue.
> 
> Rest of script:
> 
>     $market = isset($_GET['market']) ? $_GET['market'] :
> $_SESSION['market'];
>     $type = isset($_GET['type']) ? $_GET['type'] : $_SESSION['type'];
>     $store = isset($_GET['store']) ? $_GET['store'] :
> $_SESSION['store'];
> 
>     $type = str_replace('-', ' ', $type);
> 
>     if($_SESSION['type'] != $type)
>         {
>         $_SESSION['type'] = $type;
>         $store = '';
>               }
> 
>     if($_SESSION['market'] != $market)
>         {
>         $type = '';
>         $store = '';
>         }
> 
>         $_SESSION['market'] = $market;
>         $_SESSION['type'] = $type;
>         $_SESSION['store'] = $store;
> 
>         $market_name = array();
>         $market_prefix = array();
>         $type_name = array();
>         $market_prefix = array();
>         $store_name = array();
> 
> 
>     $query = "SELECT * FROM marketcode " ;
>     $result = mysql_query($query) or die(report($query,__LINE__
> ,__FILE__)); //("Something went wrong");
> 
>       while($row = mysql_fetch_array($result))
>         {
>         $market_name[] = $row['market_name'];
>         $market_prefix[] = $row['market_prefix'];
>         }
> 
>     $query = "SELECT store_type FROM store_type WHERE market_prefix =
> '$market' "     ;
>     $result = mysql_query($query) or die(report($query,__LINE__
> ,__FILE__));
> 
>       while($row = mysql_fetch_array($result))
>         {
>         $type_name[] = $row['store_type'];
>         }
> 
>         $type_name = array_unique($type_name);
>         sort($type_name);
> 
>         if($type == '')
>             {
>             $type = $type_name[0];
>             $_SESSION['type'] = $type;
>             }
> 
>     $query = "SELECT store_name FROM store_list WHERE store_type =
> '$type' AND market_prefix = '$market' "      ;
>     $result = mysql_query($query) or die(report($query,__LINE__
> ,__FILE__));
> 
>     while($row = mysql_fetch_array($result))
>         {
>         $store_name[] = $row['store_name'];
>         }
>              //   include ('includes/closedb.php');
>    // close dB
>         sort($store_name);
>      }
> ?>
> 
>         <div id="myspan">
>         <form action="index.php" method="post">
>             <table>
>                 <tr>
>                     <th class="market">Market</th>
>                     <th class="type">Store Type</th>
>                     <th class="store">Store Name</th>
>                 </tr>
>                 <tr>
>                     <td>
>                     <select name="market"
> onchange="javascript:get(this.parentNode);">
>                                       <option value="">Choose...</option>
>                     <?php
>                         foreach($market_prefix as $key => $value)
>                             {
>                             $selected = '';
>                             if($value == $market)
>                             {
>                             $selected = 'selected';
>                             }
>                             //echo("<option value=$value $selected
> >$value : $market_name[$key]");
>                                                       echo '<option
value="',
> htmlspecialchars($value), '" ',
> $selected, '>', htmlspecialchars($value.' : '.$market_name[$key]),
> '</option>';
>                             }
>                             ?>
>                     </select>
>                     </td>
>                     <td>
>                     <select name="type"
> onchange="javascript:get(this.parentNode);">
>                                       <option value="">Choose...</option>
>                     <?php
>                         foreach($type_name as $value)
>                             {
>                             $selected = '';
>                             if($value == $type)
>                             {
>                             $selected = 'selected';
>                             }
>                             $v = str_replace(' ', '-', $value);
>                             //echo("<option value=$v $selected
> >$value");
>                                                       echo '<option
value="',
> htmlspecialchars($v), '" ', $selected,
> '>', htmlspecialchars($value), '</option>';
>                             }
>                     ?>
>                     </select>
>                     </td>
>                     <td>
>                     <select name="store">
>                                       <option value="">Choose...</option>
>                     <?php
>                         foreach($store_name as $value)
>                             {
>                             echo("<option value=$value>$value");
>                   }
>                     ?>
>                     </select>
>                     </td>
>                     </tr>
>                     <tr>
>                     <td>
>                         <p>
>                             <input type="hidden" name="step" value="2">
>                             <input type="submit" name="submit"
> value="Submit">
>                         </p>
>                     </td>
>                     </tr>
>             </table>
>         </form>
>     </div>
>     </body>
> </html>
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



        // This part makes no sense they are not logged in and they have a
level of 1 or 2 ?
        // And you was missing a Pipe after false. It will cause the If
statement to fail.

        if($_SESSION['signed_in'] == false || $_SESSION['user_level'] != 1
|| $_SESSION['user_level'] != 2  ) {







--- End Message ---
--- Begin Message ---
>
>        // This part makes no sense they are not logged in and they have a
> level of 1 or 2 ?

Yes. It might not be the best approach, but I am assigning the user a
value: 1, 2, or 3 while they create an account. This will limit what
they will be able to post. For example I only want users with user
level of 1 or 2 to be able to complete the form in this script. Hence,
the control structure I am trying to include.

>        // And you was missing a Pipe after false. It will cause the If
> statement to fail.

Thanks for pointing this out. I quess I have been staring at the
computer way too long!

Chris

--- End Message ---
--- Begin Message ---
Hi

PHP 5.4 alpha 3 is now included in a the Wamp package EasyPHP 5.4 alpha3.
Enjoy!


Website : www.easyphp.org
Screenshots : www.easyphp.org/screenshots.php
Facebook page : www.facebook.com/easywamp
Twitter : www.twitter.com/easyphp

--- End Message ---
--- Begin Message ---
Ok so I have tried to create a sort of messaging system on my website and I have run into some problems storing who the message is from, ill try to take you through step by step what I am trying to do.


step #1 (messages.php): <--This is where the member will view the recent messages that have been posted
<div id='messages'>
            <?php
            include 'connect.php';
            session_start();
            $_SESSION['user']=$user;
            //store sql queries
            $sql="SELECT * FROM entries";
            $result=mysql_query($sql, $con);
            $count=mysql_num_rows($result);
            if ($count<1){
                echo 'There are no messages yet!';
            }
            while ($row=mysql_fetch_array($result)){
                echo 'From: ' .$row['from'];
                echo '<br/>';
                echo 'Subject: ' .$row['subject'];
                echo '<br/>';
                echo 'Message: ' .$row['body'];
                echo '<hr/>';
           
            }
            ?>
        </div>

Step #2 (create_message.php):<-- This is where the user creates a new message

<h2> Create new message</h2>
            <table border='0' width='100%'  cellpadding='3px' style='text-align: top;'>
                <form method='post' action=''>
                <tr width='100%' height='30%' style='margin-top: 0px;'>
                    <td> Subject </td>
                    <td> <input type='text' name='subject' maxlength='30'></td>
                </tr>
                <tr width='100%' height='30%'>
                    <td> Body </td>
                    <td><textarea name='body' style='height: 200px; width: 400px;'></textarea></td>
                </tr>
                <tr>
                    <td colspan='2' align='center'><input type='submit' name='new_message' value='Send!'/> </td>
                </tr>
                </form>
            </table>

Step #3 (insert_message.php)<-- this is where my problem is (trying to insert $_SESSION['user'] into table ['from'])
<?php
include 'connect.php';
session_start();
$user=$_SESSION['user'];
if ($_POST['new_message']){
    include 'connect.php';
    session_start();
    $_SESSION['user']=$user;
    $body=$_POST['body'];
    $subject=$_POST['subject'];
    $date=' ';
    $sql="INSERT INTO `entries` (
    `id` ,
    `from` ,
    `subject` ,
    `body` ,
    `date`
    )
    VALUES (
    NULL , '$user', '$subject', '$body', '$date'
    )";
    if (mysql_query($sql,$con)){
        echo 'Inserted!';
        echo $user;
       
    }
    else
        echo 'Not Inserted';
   
}
?>

Hope i dont piss anyone off with such a long message, I just really need help on this.

Thanks!


--- End Message ---

Reply via email to