Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. No.

     

    Use separate connections.

     

    <?php
    $connection1 = mysql_connect("host","user","pass") or die (mysql_error());
    $database1 = mysql_select_db("database", $connection1);
    
    $connection2 = mysql_connect("host","user","pass") or die (mysql_error());
    $database2 = mysql_select_db("database", $connection2);
    
    $sql = "SELECT * FROM `table`";
    $res = mysql_query($sql, $database1) or die(mysql_error());
    
    $sql2 = "SELECT * FROM `table2`";
    $res2 = mysql_query($sql2, $database2) or die(mysql_error());
    ?>
    

  2. Start off easy, then continue to excel in harder questions.

     

    Correct delimiters to open PHP scripting...

    Valid / invalid variables? ($blah, $4, $blah4, $blah-4, etc...)

    Strings, yes.

    Math, incrementing and decrementing values.

    Connecting strings

    Echo / Print

    Include / Require

     

    Then move forth more difficult tasks, multi-dimensional arrays, MySQL, etc... logic....

  3. Correct.

     

    According to your form once you submit it, your URL will look something like this:

     

    http://website.tld/staffMenu?staffid=x&submit=Submit

     

    Using the $_GET method, you will define the two variables as:

     

    $staffid = $_GET['staffid'];
    $submit = $_GET['submit'];
    

     

    If you want to use this for continuous use you're going to want to use sessions or cookies to pass the data throughout any other pages that you wouldn't want the user having to type the Staff ID again.

  4. You can create a function I suppose. I do this with my website.

     

    function uname($id){
    $sql = "SELECT username FROM `users` WHERE `id`='".mysql_real_escape_string($id)."'";
    $res = mysql_query($sql) or die(mysql_error());
    
       if(mysql_num_rows($res) == 0){
          return "Invalid User";
       }else {
          $row = mysql_fetch_assoc($res);
          return $row['username'];
       }
    }
    
    echo uname(5);
    

  5. <?php
    //connect to MySQL
    $connect = mysql_connect("localhost", "root", "michael") or die("Could not connect to database.");
    //choose the database
    mysql_select_db("jostark");
    //get data from database
    $query = mysql_query("SELECT `companyID`,`compName`, `compCity`, `compCountry` FROM `placement` ORDER BY `companyID` ASC") or
        die(mysql_error());
    echo "<select name='placement'>\n";
    while ($data = mysql_fetch_array($query, MYSQL_ASSOC)) {
    $sql = "SELECT * FROM `table` WHERE `companyID`='".$data['companyID']."'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res);
    $sel = ($row['companyID'] == $data['companyID']) ? " SELECTED" : "";
        echo "<option value='".$data['companyID']."'6".$sel.">".$data['compName'].", ".$data['compCity'].", ".$data['compCountry']."</option>\n";
    }
    
    echo "</select>\n";
    ?>
    

     

    edit the $sql variable to fit your query needs

  6. <?php
    // Connects to your Database
    include ('Connect.php');
    
    $submit = $_POST['submit'];
    
    //Body Settings
    echo "<center><font color='#AFAFAF' face='verdana' size='1'>";
    
    //If User Is Logged In
    if (isset($_COOKIE['UserID'])) {
        //Display Message
        echo "Sorry, you are already logged in. Click <a href='index.php'>Here[/url] to go back.";
    
        //Exit Page
        exit;
    }
    
    //If Form Is Submitted
    if ($submit) {
        // Checks if pass/user exists
        $_POST['username'] = addslashes($_POST['username']);
        $usercheck = $_POST['username'];
        $_POST['password'] = addslashes($_POST['password']);
        $passcheck = $_POST['password'];
        $Result1 = mysql_query("SELECT * FROM users WHERE username='$usercheck' AND password='$passcheck'");
        $Rows1 = mysql_fetch_array($Result1);
        $Rows2 = mysql_fetch_array($Result2);
    
    
        if (mysql_num_rows($Result1) == 0) {
            echo "Invalid Username/password.";
            exit;
        }
    
        $UserID = $Rows1['ID'];
    
        setcookie("UserID", "$UserID", time() + 9999999);
    
        echo "You have successfully logged in.
    
    <a href='index.php'>Continue</a>";
    }
    //If Form Isn't Submitted
    else {
        echo "
    <form method='POST'>
    <input type='hidden' name='submit' value='1'>
    
    Username
    
    <input type=\"text\" name=\"username\" maxlength=\"30\">
    
    
    
    Password
    
    <input type=\"password\" name=\"password\" maxlength=\"25\">
    
    
    
    <input type='submit' value='Sign In' onclick=\"this.disabled='true'; this.value='Please Wait...'; this.form.submit();\">
    </form>";
    }
    
    ?>
    

     

    mysql_num_rows

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