tutorial problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ianpitter
    New Member
    • Aug 2006
    • 11

    #1

    tutorial problem

    I am having trouble printing out results using your tutorial php format. I can't see any errors of copying but they must be there somewhere! The database 'mail' has only one table: 'info' with four entries, one of which has 'good' in the 'opinion' field.

    My php file is:

    <html>
    <head><title> How to Grab your MySQL Data </title></head>
    <body bgcolor="#FFFFF F">

    <php?
    /* declare some relevant variables */
    $DBhost = "localhost" ;
    $DBuser = "root";
    $DBpass = "";
    $DBName = "mail";
    $table = "info";

    mysqli_connect( $DBhost,$DBuser ,$DBpass) or die("Unable to connect to database");
    @mysqli_select_ db("$DBName") or die("Unable to select database $DBName");
    $sqlquery = "SELECT * FROM $table WHERE opinion = 'good'";
    $result = mysqli_query($s qlquery);
    $number = mysqli_num_rows ($result);

    $i = 0;

    if ($number < 1) {
    print "<CENTER><P>The re Were No Results for Your Search</CENTER>";
    }
    else {
    while ($number > $i) {
    $thename = mysqli_result($ result,$i,"name ");
    $theemail = mysqli_result($ result,$i,"emai l");

    <p><b>Name:</b><?php $thename?><br /><b>E-Mail:</b><?php>$theema il?></p>";

    $i++;
    }
    }
    ?>
    </BODY></HTML>

    The result:

    $i) { $thename = mysqli_result($ result,$i,"name "); $theemail = mysqli_result($ result,$i,"emai l");
    Name:
    E-Mail:$theemail? >

    "; $i++; } } ?>

    There are no log errors in Apache22.
  • bevort
    New Member
    • Jul 2006
    • 53

    #2
    Instead of <?php $thename?> try to use
    <?php echo($thename); ?>
    Also set a close tag ?> befor the HTML part and a <?PHP after it

    Now is seems to be a part of the PHP code thus generating an error and showing a blanc page

    Comment

    • ianpitter
      New Member
      • Aug 2006
      • 11

      #3
      Originally posted by bevort
      Instead of <?php $thename?> try to use
      <?php echo($thename); ?>
      Also set a close tag ?> befor the HTML part and a <?PHP after it

      Now is seems to be a part of the PHP code thus generating an error and showing a blanc page
      Many thanks for your prompt reply; you were right about the echo additions. The tags aroung the HTML do not seem to make a difference.
      Also I was using mysqli_ functions which did not produce an error but there was no output. Changing them to mysql_ functions produced a result.
      I am appending the working script in case it is helpful.

      Comment

      • ianpitter
        New Member
        • Aug 2006
        • 11

        #4
        Originally posted by ianpitter
        Many thanks for your prompt reply; you were right about the echo additions. The tags aroung the HTML do not seem to make a difference.
        Also I was using mysqli_ functions which did not produce an error but there was no output. Changing them to mysql_ functions produced a result.
        I am appending the working script in case it is helpful.
        I didn't! Here it is:

        <html>
        <head><title> How to Grab your MySQL Data </title></head>
        <body bgcolor="#FFFFF F">

        <?php
        /* declare some relevant variables */
        $DBhost = "localhost" ;
        $DBuser = "root";
        $DBpass = "";
        $DBName = "mail";
        $table = "info";

        mysql_connect($ DBhost,$DBuser, $DBpass) or die("Unable to connect to database");
        @mysql_select_d b("$DBName") or die("Unable to select database $DBName");
        $sqlquery = "SELECT * FROM $table WHERE opinion = 'good'";
        $result = mysql_query($sq lquery);
        $number = mysql_num_rows( $result);

        $i = 0;

        if ($number < 1) {
        print "<CENTER><P>The re Were No Results for Your Search</CENTER>";
        }
        else {
        while ($number > $i) {
        $thename = mysql_result($r esult,$i,"name" );
        $theemail = mysql_result($r esult,$i,"email ");

        ?>
        <p><b>Name:</b><?php echo $thename;?><br /><b>E-Mail:</b><?php echo $theemail;?></p>";

        <?php
        $i++;
        }
        }
        ?>
        </body></html>

        Comment

        • Georges1979
          New Member
          • Aug 2006
          • 1

          #5
          hi everybody !
          if anybody can help me to get a program using php-mysql that will tell me ok after login in so i will be able to display data from any document saved on my folders

          Comment

          • bevort
            New Member
            • Jul 2006
            • 53

            #6
            George
            you can go to www.scribax.com. There you can find a free complete password script to protect pages on your site. It is a PHP-MySQL based solution with a MD5 javascript encription

            Comment

            • bevort
              New Member
              • Jul 2006
              • 53

              #7
              Iapiiter

              I rewrote the while loop as it normaly works with me with a simple echo to show the number of rows found.

              here is the code

              <html>
              <head><title> How to Grab your MySQL Data </title></head>
              <body bgcolor="#FFFFF F">

              <?php
              /* declare some relevant variables */
              $DBhost = "localhost" ;
              $DBuser = "root";
              $DBpass = "";
              $DBName = "mail";
              $table = "info";

              mysql_connect($ DBhost,$DBuser, $DBpass) or die("Unable to connect to database");
              @mysql_select_d b("$DBName") or die("Unable to select database $DBName");
              $sqlquery = "SELECT * FROM $table WHERE opinion = 'good'";
              $result = mysql_query($sq lquery);

              echo(mysql_num_ rows($result) . "rows found");

              if (mysql_num_rows ($result) < 1) {
              print "<CENTER><P>The re Were No Results for Your Search</CENTER>";
              }
              else {
              while ($result = mysql_fetch_arr ay($results)) {
              $thename = mysql_result($r esult,$i,"name" );
              $theemail = mysql_result($r esult,$i,"email ");
              echo("<p><b>Nam e:</b>" . $thename . "<br /><b>E-Mail:</b>" . $theemail . "</p>";
              }
              }
              ?>
              </body></html>

              Vincent

              Comment

              • bevort
                New Member
                • Jul 2006
                • 53

                #8
                If this dies not work please describe what you get, step by step.

                Comment

                • ianpitter
                  New Member
                  • Aug 2006
                  • 11

                  #9
                  Originally posted by bevort
                  If this dies not work please describe what you get, step by step.
                  I saved your program as display_query.p hp. When I ran it I got a blank screen and an error message in Apache22\log\er ror:parse error, unexpected ';' in C:\\www\\webroo t\\display_quer y.php on line 27. It looks alright to me!
                  Also I do not understand the '.' s which are inserted in the echo line; I have not found an explanation of their relevance anywhere.

                  Comment

                  Working...