hi, whats wrong with my terrible script?? im new at this

i blocked out the stuff thats sensitive with X's

it gets to test3, but test4 doesnt show up

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>phptest</title>
</head>
<body>
test1
<?php
        echo "test2";
        $username='XXXX';
        $password='XXXX';
        $database='XXXX;

    echo "test3";
    $conn=mysql_connect('localhost',$username,$password) or die ("cant connect");
    echo "test4";
    @mysql_select_db($database,$conn) or die("oops, sql died");

    echo "test5";

    $query = "SELECT path FROM files";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    $i=0;
    echo "test6 $i";
    while ($i < $num) {
            $path=mysql_result($result,$i,"path");
            echo "<b>$path<hr><br>";
            $i++;
    }
?>
test7
</body>
</html>




    Try quoting (double quotes) around the $username and $password values ... ?

      Incidentally, something like this:

      die("can't connect: ".mysql_error());

      might be helpful as well.

        thanks for the quick response.
        i tried it with regular quotes too, also i tried every combination of localhost in quotes, in single quotes and not in quotes at all but in all cases the

        or die

        half the of the statement never executes.

        the only thing that appears on the page is
        test1test2test3

        is there a way to run the mysql_connect command outside of the php script and get more info out of it?

        i mean, i can connect to the server fine from the shell with

        mysql --user=XXXX--password=XXXX

        maybe my mysql config is not allowing connections from php or something??

        this is a new php+mysql+apache on gentoo setup im playing with

          Well, throw in some more tests, I guess. Remove the "@" up there ... not sure, but I think error suppression wouldn't allow the die() statement to work there ... might be wrong. OTOH, I'm sure it's generally a bad idea to use "@" when debugging, like we are here.

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
          <title>phptest</title>
          </head>
          <body>
          test1
          <?php
                  echo "test2";
                  $username='XXXX';
                  $password='XXXX';
                  $database='XXXX;
          
              echo "test3";
              $conn=mysql_connect("localhost","$username","$password") or die ("cant connect".mysql_error());
              if (!$conn) die("Dying: connect variable returned false");
              echo "test4";
              $sel=mysql_select_db($database,$conn) or die("oops, sql died".mysql_error());
              if (!$sel) die("Dying: select variable returned false");
              echo "test5";
          
              $query = "SELECT path FROM files";
              $result=mysql_query($query);
              if (!$result) die("Dying: result variable returned false");
              $num=mysql_numrows($result);
               if (!$num) die("Dying: numrows call returned false");
              $i=0;
              echo "test6 $i";
              while ($i < $num) {
                      $path=mysql_result($result,$i,"path");
                      echo "<b>$path<hr><br>";
                      $i++;
              }
          ?>
          test7
          </body>
          </html>

          Hmm, if you can connect in the shell, but not here, is there something wrong in php.ini??

            Lol, looky there : missing a quote after your db variable 😉

            Could that be it?

              :rolleyes: i wish... no i saw that too and fixed it, but even this one yeilds
              test1 test2test3... it doesnt even fail the connection string! the php is right, right? it has to be a config thing on my system?

                Is display_errors set to On and error_reporting set to E_ALL? I'm betting that the [man]mysql[/man] extension isn't even installed, thus calling mysql_connect() (an undefined function) will cause a fatal error.

                  yeah, you nailed it

                  test1 test2test3 Fatal error: Call to undefined function mysql_connect() in /var/www/localhost/htdocs/phptest.php on line 61

                  so how do i get the mysql extension installed on gentoo? i followed a step by step guide for installing php+apache+mysql on gentoo and i guess that step wasnt in it!

                    nosenseofhumor1;10974460 wrote:

                    so how do i get the mysql extension installed on gentoo?

                    [man]mysql.installation[/man]

                    However, note that the 'mysql' library is rather outdated and it is generally recommended that new projects switch to using something more up to date, such as [man]MySQLi[/man], [man]PDO[/man], etc.

                      Got it.

                      i had already added php and mysql to my use variable in make.conf and reran emerge php, but it didnt work. However, when i ran

                      USE="php mysql" emerge php

                      and restarted apache, now everything works like a charm.

                      Heads up gentoo users!

                        Write a Reply...