Jump to content

alexdemers

Members
  • Posts

    65
  • Joined

  • Last visited

    Never

Posts posted by alexdemers

  1. Also, if (isset($_POST['display'])) might not work because the actual form element will not send data to the server. It's its elements inside that will. So, you can just check isset($_POST['show']) and it will work.

     

    Edit-Adding: Naming a form element's purpose is mostly just for JavaScript. You shouldn't name it. It might work in IE (haven't tried it) but I'm guessing future browser might not work.

  2. Do the logic. Check to see what $_SERVER['REQUEST_URI'] returns for each page. Just echo the variable.

     

    <?php
    $file_parts = explode('/', $_SERVER['REQUEST_URI']);
    $current_file = end($file_parts);
    ?>
    

     

    This will return the file only, not its directories.

  3. There's alot of things wrong with your script. First, remove completely ereg functions. Second, you don't have any $_POST variables (unless you have register globals set to on, which is a very bad idea).

     

    Also, where you have :

    <?php
    for ($t = 0; $t < $showtalks; $t++) {   
    $talk_array = explode("|", $talks[$t]);   
    echo "<b>".$talk_array[2]."</b> (<a href=\"http://collect.myspace.com/index.cfm?fuseaction=invite.addfriend_verify&friendID=".$talk_array[1]."\" target=\"_blank\">Add</a> | <a href=\"http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=".$talk_array[1]."\" target=\"_blank\">View</a> )<BR> ";
    }
    

     

    Replace $talk_array[1] with $talk_array[0] and $talk_array[2] with $talk_array[1]. Arrays start at 0.

  4. Okay i would like to find a php script where, People can enter there friend ID and there picture URL .jpg or anything else. And it will show to everyone who goes to that website.

    Like a myspace whore train joiner. Something like thatt. it can be simple. and i can make the template. Alll i need is the php script or anything needed

     

    We are help to help with your code. Not provide you complete scripts.

     

    http://www.rentacoder.com/RentACoder/DotNet/default.aspx

  5. I am trying to run this:

    <?php
    if(!preg_match("/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/", $local_array[$i]))?>

     

    And i get this:

    Unknown modifier '='

     

    Whats up here?!

     

    thanks

     

    First, it's not the correct forum. Second, it's caused because you have your delimiter in there (the character before the = which is a slash which is your delimiter). The delimiter is what tells preg_* that the actual regex is between those chars. You can use / # ~ @ ! . Those are all that I saw once, possibly there's more, I don't know. The escape char is backslash \ so replacing / with \/ should do the trick. Same goes for all occurrences in your regex except the last one of the string obviously.

  6. Look. Replace this code (yours):

    <?php
    // we must never forget to start the session
    session_start();
    
    if (isset($_POST['username']) && isset($_POST['password'])) {
                
       $username = $_POST['username'];
       $password = $_POST['password'];
    
    require_once("connect.php");
    
       // check if the user id and password combination exist in database
       $query = "SELECT username
               FROM members
               WHERE username = '$username'
                     AND password = '$password'";
    
       $row = mysql_query($query)
       or die ("Error - Couldn't login user."); 
    
       if (mysql_num_rows($row) == 1) {
          // the user id and password match,
          // set the session
          $_SESSION[username] = $row[username];
    

     

     

    With my corrected code:

    <?php
    // we must never forget to start the session
    session_start();
    
    if (isset($_POST['username']) && isset($_POST['password'])) {
                
       $username = $_POST['username'];
       $password = $_POST['password'];
    
    require_once("connect.php");
    
       // check if the user id and password combination exist in database
       $query = "SELECT username
               FROM members
               WHERE username = '$username'
                     AND password = '$password'";
    
       $row = mysql_query($query)
       or die ("Error - Couldn't login user."); 
    if (mysql_num_rows($row) == 1) {
        // the user id and password match,
        // set the session
        $real_row = mysql_fetch_array($row);
        $_SESSION['username'] = real_row['username'];
    }
    ?>
    

     

     

    If that's not what you're looking for then I really don't know what you are trying to do. But, like I said, the code you provided in your first post is correct and there's no problems with it (except security, but that's not the issue).

  7. The idea is now first, if you login, print that, and not print that. My problem is i dont know the right script to call the db so it can see if someone is online or not

     

    <?php

    session_start();

    require_once("connect.php");

     

    if (mysql_num_rows($row) == 1) {

    {

    echo "You are currently logged in, <b>$_SESSION[username]</b>.";

    }

    else // bad info.

    {

    echo "You are currently <b>NOT</b> logged in.";

    }

     

    ?>

     

     

     

     

    Well, what I just explained you is it's not that script (which I just quoted here) you have problems with, it's the one where you assign the username to $_SESSION['username']. That's the problem. And I just corrected that problem. So refer to this post to fix your script http://www.phpfreaks.com/forums/index.php/topic,263787.msg1243513.html#msg1243513

  8. There's 3 steps in getting data from the database.

     

    1. Connect to the database (which hopefully you did in connect.php)

    2. Query the database (which is what mysql_query() does)

        a. mysql_query() returns either a resource (an internal pointer to that query) or false on failure (syntax error or any other MySQL related errors)

        b. You assign that returned value to $row (in your case, but I recommand changing the variable name to something more precise like $result)

    3. You fetch the results from that query: mysql_fetch_array()

        a. If you're sure you will always return 0 or 1 query, you don't have to use a loop; so you can assign it directly: $row = mysql_fetch_array($result). Else, you should to while ($row = mysql_fetch_array($query)) { echo $row['username']; }

        b. Now $row will contain an array which you can juggle with and do what you have to do. In your case, assign $row['username'] to a session variable: $_SESSION['username'];

     

     

  9. You didn't mysql_fetch_array(). $row actually contains a result and not an array.

     

    Change to this:

     

    <?php
    if (mysql_num_rows($row) == 1) {
        // the user id and password match,
        // set the session
        $real_row = mysql_fetch_array($row);
        $_SESSION['username'] = real_row['username'];
    }
    ?>
    

     

    2 things. I highly recommend you use quotes for non constant. If you didn't declare a constant then use quotes. In big applications, it will drastically slow down the application. Also, a little tip: when you do assign a variable to mysql_query(), I recommend naming it $result since it's the result and not records (array).

     

    Hope this solves it.

×
×
  • 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.