Jump to content

play_

Staff Alumni
  • Posts

    717
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by play_

  1. [!--quoteo(post=371146:date=May 4 2006, 12:25 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 4 2006, 12:25 AM) [snapback]371146[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    well umm.. i tested your code (from original post) on my server. the only thing i changed was change the $path to ./images/ instead of ./images/logos/ (to suit my own directories) and it worked just fine

    p.s.- maybe you should try using || instead of && (or instead of and) in your if statement
    [/quote]

    Oh.
    If you upload a directory full of images to your server, it till upload 'Thumbs.db' with it.
    Keep clicking refresh on your browser, and you'll see that sometimes the image won't show up.
  2. Hey James. It just so happens i figured a way to make it work (right after you posted too....i waited a few minutes and no one replied, so i figured everyone was asleep).

    Here is what i came up with:

    [code]
                    $path = './images/logos/';
            $dir = opendir($path) or die('Could not open directory for main image selection.');
            $images = array();
            while ( !(($file = readdir($dir)) === false)) {
                if ( ($file != 'Thumbs.db') && ($file != '.') && ($file != '..') ){
                    array_push($images, $file);
                    
                }
            }
            shuffle($images);
            print $images[0];        [/code]

    It's pretty small and so far works fine. If you can see something that might not be well written, let me know though.

    But, i still dont understand why in that first script i posted, php was selecting 'Thumbs.db' and '.' and '..' from the directory even though i had an IF statement telling it to skip those files.
  3. Ok ill be honest. It's been quite a bit since ive done php and now im redoing my site. Instead of using the old scrips ive made, im making everything from scratch, to refresh the memory.

    Im making a script that pics a random image out of a directory. It looks like this:

    [code]
            <?php //Random image loader.
            $path = './images/logos/';
            $dir = opendir($path) or die('Could not open directory for main image selection.');
            $i = 0;
            
            // Loops through directory and append filenames to the array 'file'.
            while( ($file[$i] = readdir($dir)) ) {
                $i++;
            }

            // pick a random item (image name) out of the 'file' array :: $file[1] or $file[2], etc.
            $image = array_rand($file);

            

            if( ($file[$image] != '.') && ($file[$image] != '') && ($file[$image] != 'Thumbs.db') && ($file[$image] != '..') && ($file != ' ') ) {
                            $all = $path.$file[$image];
                echo '<img src="'. $all .'" />';
            } else {
                echo $file[$image];
            }
    [/code]

    As you can see, in the 'else' statement, it prints the name of the image/file (i put it there because sometimes the image doesnt show up). And so, when the image doesn't show up, it prints either 'Thumbs.db' or '.' or '..'.

    Why is that happening, when i have that long ass 'if' statement there telling the script to not print those files?
  4. [!--quoteo(post=360844:date=Apr 2 2006, 05:44 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 2 2006, 05:44 AM) [snapback]360844[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    In that case, are you using nl2br() when you put it into textarea for editing?
    [/quote]

    Yes.

    I suppose i should take that out huh?
  5. {
    $name = $_POST['name'];
    $email = $_POST['email'];

    $check = "SELECT * FROM email_list WHERE name='$name' and email='$email'";
    $check_result = mysql_query($check);
    $num = mysql_num_rows($check_result);
    if (num > 0) {
    echo "You are already on the mailing list";
    } else {
    $query = "INSERT INTO email_list (name,email) VALUES ('".$name."','".$email."')";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.

    // start visual
    if($result)
    {
    print "This is a message displayed upon query success!";
    }
    else
    {
    print "This is a message displayed due to insert failure";
    }
    // end visual
    }

    }
  6. [!--quoteo(post=360796:date=Apr 1 2006, 10:24 PM:name=ajrpg1)--][div class=\'quotetop\']QUOTE(ajrpg1 @ Apr 1 2006, 10:24 PM) [snapback]360796[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    is there anywhere i can go where i can go that a php site is set up for me without having to do all that complicated stuff?
    if no can anyone help on installing php with tripod?
    [/quote]

    When you say "where i can go that a php site is set up for me without having to do all that complicated stuff?"

    do you mean without having to install php, or you want a site already made?
    Dont know where you can fnid that.

    And im pretty sure you cant install php on your tripod site. they have to do it themselves.
  7. do this to echo out the query to help us:

    [code]
    if (isset($_POST['submit'])) {
    inlclude('./connect.php');
    $name = $_POST['name'];
    $email = $_POST['emai'];
    $query = "INSERT INTO email_list (name, email) VALUES ('$name', '$email')";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    echo $query;
    if ($result) {
    echo 'This is email:'.$email.'<br>';
    echo 'This is name:'.$name.'<br>';
    } else {
    echo 'Failed to add:'.$email.' to database<br>';
    echo 'Failed to add:'.$name.' to database<br>';
    }
    [/code]
  8. Then that should work but its not a good method.

    When the user presses submit, you should check like this.

    if(empty($username)) {
    echo "Must enter a username";
    $username = false;
    } else {
    escape_data($username);
    $username = TRUE;
    }

  9. Not sure what youre trying to do. Im assuming comare. so here it goes

    if($first = NULL or
    $last = NULL or
    $gun = NULL or
    $age = NULL or
    $saying = NULL or
    $email = NULL or
    $phone = NULL or
    $users = NULL or
    $passs = NULL){

  10. [!--quoteo(post=360761:date=Apr 1 2006, 07:36 PM:name=jeliot)--][div class=\'quotetop\']QUOTE(jeliot @ Apr 1 2006, 07:36 PM) [snapback]360761[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Ok i figured out that if i take out the ID field I recently added in my db then my populate.php WILL populate my db with test names but................
    my old email_form script

    <?php
    $db_host = "mysql";
    $db_user = "jeliot";
    $db_pwd = "8013301";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);
    if (!isset($_POST['submit'])) {
    ?>
    <form action="" method="post">
    Name: <input type="text" name="name" size="20"><br>
    Email: <input type="text" name="email" size="20"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>
    <?php
    } else {
    $name = $_POST[‘name’];
    $email = $_POST[‘email’];
    $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    }
    ?>
    still sends the form with the Name: empty and Email: empty

    my revised script (with play's help)

    <?php
    $db_host = "mysql";
    $db_user = "jeliot";
    $db_pwd = "8013301";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);
    if (!isset($_POST['submit'])) {
    ?>
    <form action="" method="post">
    Name: <input type="text" name="name" size="20"><br>
    Email: <input type="text" name="email" size="20"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>
    <?php
    } else {
    $name = $_POST[‘name’];
    $email = $_POST[‘email’];
    $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    }
    ?>
    doesn't error but doesn't send anything to the database
    [/quote]

    That's not my revised script :D. I separated all the php and html in half, instead of having php, html and php again.


    here, try this one:
    [code]

    <form action="#" method="post">
    Name: <input type="text" name="name" size="20"><br>
    Email: <input type="text" name="email" size="20"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>


    <?php

    if (isset($_POST['submit'])) {
    inlclude('./connect.php');
    $name = $_POST['name'];
    $email = $_POST['emai'];
    $query = "INSERT INTO email_list (name, email) VALUES ('$name', '$email')";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    if ($result) {
    echo 'This is email:'.$email.'<br>';
    echo 'This is name:'.$name.'<br>';
    } else {
    echo 'Failed to add:'.$email.' to database<br>';
    echo 'Failed to add:'.$name.' to database<br>';
    }

    ?>[/code]

    Make connect.php and put it on the same directory as your email script, and put this inside:
    [code]
    $db_host = "mysql";
    $db_user = "jeliot";
    $db_pwd = "8013301";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
    mysql_select_db($db_name) or die(mysql_error());
    [/code]
    Try that and let me know.

    Also, for the varchars columns in your database table, you did give a number of allowed input right? And for int also?
  11. [!--quoteo(post=360757:date=Apr 1 2006, 07:12 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 1 2006, 07:12 PM) [snapback]360757[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    you sholdn't have any problems.....

    There is one session per client visiting the site (or have left without closing their browser and session has not been destroyed!) but I think you are trying to avoid problems that just won't occur.
    [/quote]


    Thanks.
    But still...i'd prefer if i could use an alternative. not sure why
  12. Also, you dont need to split up your code like that.

    This looks cleaner:

    [code]


    <form action="" method="post">
    Name: <input type="text" name="name" size="20"><br>
    Email: <input type="text" name="email" size="20"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>


    <?php
    $db_host = "mysql";
    $db_user = "jeliot";
    $db_pwd = "8013301";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);

    if (isset($_POST['submit'])) {
    $name = $_POST[‘name’];
    $email = $_POST[‘email’];
    $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    }
    ?>

    [/code]

    aaaaalso, instead of typig out:
    [code]
    $db_host = "mysql";
    $db_user = "jeliot";
    $db_pwd = "8013301";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);
    [/code]
    every time you wanna connect to the database, you can put it in a separate file and call that file. this makes your code shorta & cleaner.

    so you could make connect.php and put this there:
    [code]
    $db_host = "mysql";
    $db_user = "jeliot";
    $db_pwd = "8013301";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);
    [/code]

    and then, on the email page you call it.
    [code] inlclude('./connect.php');[/code].

    So to summerize, here is the final thing:

    [code]
    <form action="" method="post">
    Name: <input type="text" name="name" size="20"><br>
    Email: <input type="text" name="email" size="20"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>


    <?php
    if (isset($_POST['submit'])) {
    inlclude('./connect.php');
    $name = $_POST[‘name’];
    $email = $_POST[‘email’];
    $query = "INSERT INTO `email_list` (name, email) VALUES ('$name', '$email' )";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    }
    ?>
    [/code]
  13. [!--quoteo(post=360724:date=Apr 1 2006, 05:23 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:23 PM) [snapback]360724[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    On each page with a form that you want to pass it to you will need to get the $sql_id from the $_GET or $_POST arrays and put the hidden field in the form.

    So it's a case of

    get the values
    save in hidden field
    pass it on when form is submitted

    then same with next page and so on.

    But as you are using SESSION anyway, why don't you want to use that method for sql_id?
    [/quote]


    For some reason i prefer $_POST or GET over a session.

    i think the less sessions active the better.
  14. [!--quoteo(post=360727:date=Apr 1 2006, 05:33 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 1 2006, 05:33 PM) [snapback]360727[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    That will only work if the call is from a file in a directory of teh same level as the inc directory.

    if inc is in teh root dir then a call to "../inc/menu.php" from root/dir1/dirx/diry/file.php would NOt call the correct file (the only time infact, that no error would be returned in that situation is if this existed.. root/dir1/dirx/inc/menu.php)

    MAKE SURE YOUR PATH IS CORRECT AT ALL TIMES (which is why $_SERVER['DOC_ROOT'] is so very useful)
    [/quote]

    If inc was in the root dir, wouldn't he use "./inc/menu.php" ?

    I think you put an extra '.' in there ;)
  15. [!--quoteo(post=360725:date=Apr 1 2006, 05:25 PM:name=sford999)--][div class=\'quotetop\']QUOTE(sford999 @ Apr 1 2006, 05:25 PM) [snapback]360725[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    If the file you need to include is in a different directory, then you can just use:

    [code]include ("../inc/file.php");[/code]
    [/quote]

    No no, the file is in the same directory always, but he calls the file from different directories.

    [!--quoteo(post=360723:date=Apr 1 2006, 05:22 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 1 2006, 05:22 PM) [snapback]360723[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Alternatively you could use this...

    [code]<?php

    include($_SERVER['DOC_ROOT'] . "/includes/menu.php");

    ?>[/code]

    Should be able to use that on each and every page with no problem.

    Bear in mind that apache shutting down could be as a result of a different error in your scripts... even if it only occure when you implemented this.
    [/quote]


    Yea..maybe the intallation went wrong somewhere?

    SO yea, completeamateur, try uploading it to your web host.

    Also, replace 'include' with 'require'
  16. Oh, Barand i think i didn't explain very well the problem, sorry.

    here's exactly how it goes:

    - I type the news in a text area and click submit and it puts it in the database

    - I use am redirected to the index page, and notice that the news don't have any linebreaking at all. It's all crumbled up together.

    - Then i click "edit", and i am taken to the edit form, but now i see <br> where i had pressed enter when i first entered the news. So since the <br>'s are there when i go edit it, i just click "submit updated news".


    so it doenst show on the news page, but only when i edit.


    Hope this helps better.



    And i don't format it with nl2br before entering it in the db. here is the full code for "add news":
    [code]
    <?php
    $title = 'Post news';
    $header_title = 'Add news. . .';
    include ('./includes/header.php');
    if (!isset($_SESSION['user_name'])) {
        header ("Location: index.php");
    }
    ?>

    <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
        <table cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td>Title:</td>
            </tr>
            
            <tr>
                <td><input type="text" name="title"  /></td>
            </tr>
            
            <tr>
                <td></td>
            </tr>
            
            <tr>
                <td>News:</td>
            </tr>
            
            <tr>
                <td><textarea name="news" rows="7" cols="40"></textarea></td>
            </tr>
            
            <tr>
                <td><input type="submit" name="submit" value="post news" /></td>
            </tr>
        </table>
    </form>


    <?php

    if (isset($_POST['submit'])) {    
        require_once ('./db_connect.php');
        $news = escape_data($_POST['news']);
        $title = escape_data($_POST['title']);
        
        $query = "INSERT INTO news (title, news, date_submitted, author) VALUES ('$title', '".wordwrap($news, 45, "\n", 1)."', NOW(), '". $_SESSION['user_name'] ."')";
        $result = mysql_query($query) or die (mysql_error());
        
        if ($result) {
            header ('Location: index.php');
        } else {
            echo 'Could not add news.';
        }
    }

    include ('./includes/footer.php');
    ?>
    [/code]

    Escape data, goes as follows:
    [code]
        function escape_data($data) {
            global $dbc;
            if (ini_get('magic_quotes_gpc')) {
                $data = stripslashes($data);
                } return mysql_real_escape_string(trim($data), $dbc);
            }[/code]

    Ive also tried inserting it without wordwrap, to see if it was the problem, and it wasn't. same thing happens
  17. [!--quoteo(post=360583:date=Apr 1 2006, 05:26 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:26 AM) [snapback]360583[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    Don't store formatted news in the DB. Store it from the textarea complete with "\n"s.

    Format it when you output it.
    [/quote]


    Hi Barand.

    Are you talking about this: wordwrap($news, 45, "\n", 1) ?
    Thats the only formatting i do when inserting news into the db (besides escaping quotes)

  18. [!--quoteo(post=360584:date=Apr 1 2006, 05:33 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:33 AM) [snapback]360584[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    You could add a hidden input field to your form

    <INPUT type='hidden' name='sql_id' value='$sql_id'>
    [/quote]


    And that will be preserved each time the page is refreshed/redirects to itself?

    Thanks.
  19. 1) I don't recommend doing any design on a WYSIWYG (what you see is what you get) program. Buy a CSS book, it'll help you alot more.

    2)
    sample.php is displaying the names because of this:
    $row["Name"]

    so, to display the other ones:
    $row["email"]
    $row["phone"]

    etc.


    I also recommend buying a phpbook. youll get a much better understanding. I say this because once you get it to work, there are a million other things you will want to do, like align the results, display each row in different colors, format the strings, purify data, etc....Which if you had a bookf or, it'd be a quick reference, instead of having to rely on others to post code for you.

  20. [!--quoteo(post=360553:date=Apr 1 2006, 12:29 AM:name=jeliot)--][div class=\'quotetop\']QUOTE(jeliot @ Apr 1 2006, 12:29 AM) [snapback]360553[/snapback][/div][div class=\'quotemain\'][!--quotec--]
    This is my first post and yes I am a newbie but I did alot of research before posting.... so here it goes

    I have a test script wich will populate my db
    and I have a test script wich will then take the data make it viewable in a browser...but.....
    this email form script

    <?php
    $db_host = "host_name";
    $db_user = "my_user_name";
    $db_pwd = "3456789";
    $db_name = "email";
    mysql_connect($db_host, $db_user, $db_pwd);
    mysql_select_db($db_name);
    ?>
    <?php
    if (!isset($_POST['submit'])) {
    ?>
    <form action="" method="post">
    Name: <input type="text" name="name" size="20"><br>
    Email: <input type="text" name="email" size="20"><br>
    <input type="submit" name="submit" value="Submit!">
    </form>
    <?php
    } else {
    $name = $_POST[‘name’];
    $email = $_POST[‘email’];
    mysql_query("INSERT INTO `email_list` (name, email, ) VALUES ('$name', ‘$email’, )");
    }
    ?>
    won't populate the data to my db
    Any Help with this would be greatly appreciated I've been racking my brain
    [/quote]



    You dont need a coma after your last values on the query. so change this
    [code]mysql_query("INSERT INTO `email_list` (name, email, ) VALUES ('$name', ‘$email’, )");[/code]

    to this
    [code]mysql_query("INSERT INTO `email_list` (name, email) VALUES ('$name', ‘$email’)");[/code]


    Also, You wanna put the sql query in a variable, so you can check it.
    so instead of this:
    [code]mysql_query("INSERT INTO `email_list` (name, email, ) VALUES ('$name', ‘$email’, )");[/code]

    Do this:
    [code]
    $query =  "INSERT INTO `email_list` (name, email) VALUES ('$name', ‘$email’ )";
    $result = mysql_query($query) or die(mysql_error()); // this performs the actual query.
    [/code]


    That should do it and if not it will print out an error message. If it does, let us know what it was
×
×
  • 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.