PHP - My first hour

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
Aquachip
Forum Newbie
Posts: 1
Joined: Mon Aug 01, 2011 1:19 pm

PHP - My first hour

Post by Aquachip »

Hi!

I decided to take up learning PHP an hour ago. WOW its a powerful language.

The reason I decided to take it up is because I need to create a database for my website.
I am reading allot about PHP going hand in hand with MySQL, but I don't believe its necessary to use MySQL.

So, I started reading official introduction over at the PHP website.

Being someone with A.D.D, I tried so hard not to deviate, but couldn't help myself and started experimenting with code.

Using the tutorial guideline, I created this:

index.html

Code: Select all

<?php
 echo "test";
 echo $_SERVER['HTTP_USER_AGENT'];
?>
<form action="action.php" method="post">
 <p>Enter value: <input type="text" name="value" /></p>
 <p><input type="submit" /></p>
 </form>
action.php

Code: Select all

<?php echo htmlspecialchars($_POST['value']); ?>
Then when mass A.D.D kicked in, I tried to guess other 'instructions' and did this:
action.php

Code: Select all

<?php if ($_POST == ['1']) {echo "2"};
But I got a parse error.

Its pretty obvious what I want to do, so I won't state the obvious.

What I do need to learn is to create a search page for a website using radio box selections with the form POST, then PHP searches a database ("somedir/file.list")in a group list, and if the selected is in that group, then the website outputs some HTML or I guess the selection choices.

I can do it in python, so I am positive it can be done in PHP.

pro-airportpatdown = [party1, party4, party7]
neutral-airportpatdown = [party2, party6, party9]
anti-airportpatdown = [party3, party5, party8]

Then I want something like:
If question1 input in "pro-airportpatdown' then echo "Parties that support passenger Pat downs:" then output = "/var/www/website1/partylist/party1.html" "/var/www/website1/partylist/party4.html" "/var/www/website1/partylist/party7.html"
Get what I mean?

I don't have the time do read the entire documentation now, I will do it next week when I have time, but just to give me an example of what I should expect, how can this be done?


Oh God, all these fantastic PHP ideas are coming to my head. I actually have a head ache!


Thanks!
SabirAhmed
Forum Newbie
Posts: 23
Joined: Tue Aug 02, 2011 11:56 am

Re: PHP - My first hour

Post by SabirAhmed »

Im new to php but i'll try help if i can.

In terms of the parse error you got, you may want to re-phrase the coding to look like this :

<?php if ($_POST['value'] == 1 ) {echo "2"};

or something like that, but this is just syntax really and you've probably worked this out by the time u read this post anyway.

In terms of doing a site search, this shouldnt be too difficult. I've only worked with mysql databases so far, so i would do is store the relevant links into a mysql database, and then input certain information into the table to connect the data to what the user is searching for.

For example, if one of the search options is to search for 'pro-airportpatdown', then i would put this as a category in the database (for example, category name = description)

Then, in the HTML form , i would crate a variable called $choice that changes value depending on what the user has clicked (the PHP will allow it to change value based on the Form Submission).

Then in the MYSQL statement i would put "SELECT * where 'Description' like %$choice%"

Hope this helps!
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: PHP - My first hour

Post by genix2011 »

Hi,

that should be pretty easy to do with php:

Code: Select all

<?php
if($_POST['submit']){
    echo "Parties that support passenger Pat downs:";

    $displayfiles = null;
    $filelist = array(
        'pro-airportpatdown' => array('party1','party4','party7'),
        'neutral-airportpatdown' => array('party2', 'party6', 'party9'),
        'anti-airportpatdown' => array('party3','party5','party8')
    );

    foreach($filelists as $key => $val){
        if($_POST[$key]){
            foreach($filelist[$key] as $f){
                $path = "/var/www/website1/partylist/" . $f . ".html";
                if(!file_exists($path)) continue;
                echo file_get_contents($path);
            }
        }
    }
} else {
    // Put your form etc here...
    echo "Show form here if not submit";
}
?>
This is a really simple code, but you can see how this can be done in php (without database etc.).

Greets.
Post Reply