SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 44
  1. #1
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Login Script

    When users login I want a php script that will direct them to a page which is then filled in with their info. Their info is on a different page. How can I have php search and find the user on the "master.php" page based on the login they provide on the "index.php" page and load them the "infomaster.php" page with their info in it.
    The login asks them for their last name and the year of their plow. The php needs to find this on the "master.php" page and put their whole table row of information in the corresponding places on the "infomaster.php" page.

    I know this sounds like a lot, but for you who know more about php than I it is probably nothin at all. (I am still learning!).
    Is this possible?

    Attached are the pages.
    Attached Files Attached Files
    Last edited by rmv17; Jul 7, 2005 at 20:21.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I have finally set up a MySQL database in which I am putting data for customers.
    With php, how do I tell it to find a specific name or text query?

    Code:
    <?php
    $strServer="mysql12.powweb.com"; // Server IP Address 'or' Name
    $strDatabase="blanchatmfg"; // Database Name
    $strUser="root"; // User ID
    $strPwd="pwd"; // Password
    
    $strDB=mysql_connect($strServer,$struser,$strPwd);
    
    $database=mysql_select_db("strDatabase",$strDB); 
    ?>
    My input boxes are called 'Name' and 'Year'. How do I input that here??

    Then once it is connected, how do I tell it to search for the queries in the the two text boxes together (they must match the same row)?

    Thanks so much for your help!!

  3. #3
    SitePoint Zealot sidhighwind's Avatar
    Join Date
    Aug 2003
    Location
    Indianapolis, IN
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is more a mysql question but here is a basic query.
    Code:
      $sql = "select * from 'table name' where name = '$name' and year ='$year';"
      $rs = mysql_query($sql)
      while($row = mysql_fetch_array($rs)) {
      	 //parse out $row here
      	 ...
      }
    Hope that is what you are looking for.

    I would suggest picking up this book if you are new php and or mysql
    Jon Whitcraft :: It's the Bombdiggity!
    Web Applications Developer :: Zend Certified Engineer
    http://www.indycar.com

  4. #4
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by this line
    Code:
    //parse out $row here
    and would this also work for a regular search of the database table?

  5. #5
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get this error when I try to use it.

    Parse error: parse error, unexpected T_VARIABLE in /www/b/blanchatmfgc/htdocs/plows/loginplow.php on line 12
    Line 12 is
    Code:
    $rs = mysql_query($sql)

  6. #6
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse Error

    This is the code I have so far.
    The part in red is not working properly. I get the parse error like I said above.
    What I want to do where the "print" part is - is load a page called "infomaster.php" and input the values that are accessed from the row on the database into the appropriate places on the page.
    Code:
    <?php
    $strServer=""; // Server IP Address 'or' Name
    $strDatabase=""; // Database Name
    $strUser=""; // User ID
    $strPwd=""; // Password
    
    $strDB=mysql_connect($strServer,$struser,$strPwd);
    
    $database=mysql_select_db("strDatabase",$strDB); 
    
    $sql = "SELECT * FROM `Plow Customer Information` WHERE `Last Name` = '$lastname' and `Year` = '$year'"
      $rs = mysql_query($sql)
      while($row = mysql_fetch_array($rs)) {
      	 if ($row){
      	 print "<meta http-equiv=\"refresh\" content=\"0;URL=infomaster.php\">";
      	 
      	 }
      	 else{
      	 print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
      	 }  }
    
    ?>
    Thanks
    Last edited by rmv17; Jul 8, 2005 at 12:55.

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    First things first, please tell me that those aren't your actual username, password details! If they are, edit your post and remove them.
    You have missed a ; form the end of your query line...
    PHP Code:
    <?php
    $strServer
    ="mysql12.powweb.com"// Server IP Address 'or' Name
    $strDatabase="blanchatmfg"// Database Name
    $strUser="blanchatmfg"// User ID
    $strPwd="firetruck"// Password

    $strDB=mysql_connect($strServer,$struser,$strPwd);

    $database=mysql_select_db("strDatabase",$strDB); 

    $sql "SELECT * FROM `Plow Customer Information` WHERE `Last Name` = '$lastname' and `Year` = '$year'";
      
    $rs mysql_query($sql)
      while(
    $row mysql_fetch_array($rs)) {
           if (
    $row){
           print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=infomaster.php\">";
           
           }
           else{
           print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
           }  
    }

    ?>
    Cheers

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get an error on line 13 now.

    Parse error: parse error, unexpected T_WHILE in /www/b/blanchatmfgc/htdocs/plows/loginplow.php on line 13
    That is this line:

    Code:
    while($row = mysql_fetch_array($rs)) {

  9. #9
    SitePoint Addict DA Master's Avatar
    Join Date
    Apr 2004
    Location
    /etc/php.ini
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $rs = mysql_query($sql)

    Should be...

    $rs = mysql_query($sql);

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    oops missed that one!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL, thanks

  12. #12
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I have stumped myself. It is supposed to load either infomaster.php or error.php after it finds the query...instead it just shows a blank page.
    Here is the url http://blanchatmfg.com/plows/
    Put in "Ayers" and "2005" cause I know that one works.

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK I think I know what you are trying to achieve, the user logs in and depending upon the result of the query is sent either to the infomaster page or the error page....

    PHP Code:
    <?php 
    $strServer
    =""// Server IP Address 'or' Name 
    $strDatabase=""// Database Name 
    $strUser=""// User ID 
    $strPwd=""// Password 

    $strDB=mysql_connect($strServer,$struser,$strPwd); 

    $database=mysql_select_db("strDatabase",$strDB); 

    $sql "SELECT * FROM `Plow Customer Information` WHERE `Last Name` = '$lastname' and `Year` = '$year'"
      
    $rs mysql_query($sql);
      
    $cr mysql_num_rows($rs);
    if(
    $cr 0) {
        
    header("Location: infomaster.php");
        exit();
        } else {
        
    header("Location: error.php");
        exit();
    }
    ?>
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand the code right - it logs on the database, trys to find the query and if it does, sends the user to the infomaster.php page, if it doesn't sends them to the error.php page. Right?
    What needs to happen now is that if it finds the query it needs to load the row information in the infomaster.php page.
    I am learning, and this part has me stumped!
    The page is set up so that the different 9 fields in the table row have a "$whateverthenameis" where I want them to show up.
    I just need to know how to tell the database to place them there.
    Thanks guys

  15. #15
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code gave me the error page every time.

    Code:
    if($cr > 0) { 
        header("Location: infomaster.php"); 
        exit(); 
        } else { 
        header("Location: error.php"); 
        exit(); 
    }
    mysql_close($strDB);
    ?>
    So I got to experimenting and came up with this - which takes me to the right page. The part in red is not doing its job and I tried "echo" too. What do I need here?

    Code:
    if($sql) { 
        header("Location: infomaster.php"); 
    print "'First Name' = '$firstname','Last Name' = '$lastname','Street Address' = '$saddress','City' = '$city','State' = '$state','Zip' = '$zip','Phone' = '$phone','Year' = '$year','Serial Number' = '$sn','Description' = '$descrip'";
        exit();
    
        } else { 
        header("Location: error.php"); 
        exit(); 
    }

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, this is where it gets interesting!

    Investigate sessions and session variables to pass the data across to the next page. Below is a BASIC example of what I mean.
    Any Questions, just ask!

    PHP Code:
    <?php 
    $strServer
    =""// Server IP Address 'or' Name 
    $strDatabase=""// Database Name 
    $strUser=""// User ID 
    $strPwd=""// Password 
    $strDB=mysql_connect($strServer,$struser,$strPwd); 

    session_start(); # START THE SESSION ***IMPORTANT***

    $database=mysql_select_db("strDatabase",$strDB); 

    $sql "SELECT * FROM `Plow Customer Information` WHERE `Last Name` = '$lastname' and `Year` = '$year'"
      
    $rs mysql_query($sql
      
    $cr mysql_num_rows($rs);
    if(
    $cr 0) {
    $rows mysql_fetch_assoc($rs);
    # register the fields as SESSION variables
    # change the fields to your table
    $_SESSION['field1'] = $rows['field1'];
    $_SESSION['field2'] = $rows['field2'];
    $_SESSION['field3'] = $rows['field3'];
    $_SESSION['field4'] = $rows['field4'];

        
    header("Location: infomaster.php");
        exit();
        } else {
        
    header("Location: error.php");
        exit();
    }
    ?>
    infomaster page...
    PHP Code:
    <?
    session_start
    (); # START THE SESSION ***IMPORTANT***

    echo $_SESSION['field1'];
    echo 
    $_SESSION['field2'];
    echo 
    $_SESSION['field3'];
    echo 
    $_SESSION['field4'];

    ?>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    What parse error do you get?
    PHP Code:
    if($sql) { 
        
    header("Location: infomaster.php"); 
    print 
    "'First Name' = '$firstname','Last Name' = '$lastname','Street Address' = '$saddress','City' = '$city','State' = '$state','Zip' = '$zip','Phone' = '$phone','Year' = '$year','Serial Number' = '$sn','Description' = '$descrip'";
        exit();

        } else { 
        
    header("Location: error.php"); 
        exit(); 

    This won't echo as the header redirection has already taken place and any code below it wont be executed.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #18
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After I put all that session stuff in - I now get a parse error that reads

    Parse error: parse error, unexpected T_VARIABLE in /www/b/blanchatmfgc/htdocs/plows/loginplow.php on line 15
    The line is:
    Code:
    $rows = mysql_fetch_assoc($rs);

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    both, what are your field names?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I have like "First Name" in the database and like "firstname" in the infomaster page. They need to associate to each other.

    Just thinking:
    I only want it to work if it finds only one row that meets the criteria so should I change if($cr > 0) to if($cr = 1)?

  21. #21
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    First of all, avoid putting spaces in field names. It causes many problems later!

    $_SESSION['firstname'] = $row['First Name'];
    etc...

    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  22. #22
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry!!
    Ok- I did that right though and I still get the parse error like I said above.

  23. #23
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    My fault....again!
    missed the sodding colon again!

    $rs = mysql_query($sql);


    This part,
    if($cr > 0)
    can be changed to
    if($cr == 1)

    if you want to but it kind of amounts to the same in this scenario.
    Note that there are two ='s
    Two ='s is a comparison operator


    Cheers
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  24. #24
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    kansas
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL, I should be catching those semi colons by now!!
    Alrighty, all is good now in parse error land, but it takes me to the error page. What could be causing this?
    Last edited by rmv17; Jul 8, 2005 at 09:32.

  25. #25
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just try,
    after you create the query do this
    echo $sql and then run it manually in phpmyadmin or any ther utility you have and see if it returns anything
    ---------------------------
    Errors = Improved Programming.
    My Site


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •