Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


 

Previous Page Page 2 of 3 Next Page

Frequently Asked Questions

  1. Tutorials
    There are several tutorials available in the Articles section.  They cover everything from PHP for beginners to database scripts.

     
  2. How To Post Questions
    There are a few things that you can do to make it easier for others to answer your question:
    • Show the Incorrect Line:
      For example, if your error message says that there is an error on line 24, indicate which line is line 24.
    • Show the Error Message:
      If your code produces an error message, include the error message.
      E.g.   Fatal error: Call to undefined function: style_code_begin() in /test/testPage.html on line 48.

     
  3. SQL Query Not Working
    There are a few basic things you can to do to get the most information about your problem as possible:
    • Getting MySQL Errors:
      In order to get error messages from MySQL, you must call mysql_error() to find out what the error is:

      PHP Code:

      <?php

      $ret = mysql_query($query);
      if (!$ret)
        echo "ERROR: " . mysql_error() . "<br />\n";

      ?>

      An '@' at the beginning of the MySQL function (e.g. "@mysql_query($query);") will suppress all output.
    • Making Sure Your Query Is Correct:
      To make sure that your query is correct, create it in a variable and echo the variable to the browser before calling the sql query command:

      PHP Code:

      <?php

      $query = "SELECT user_name FROM user WHERE user_id=19";
      echo "...query: $query<br />\n";
      $ret = mysql_query($query);

      ?>

    • Testing Your Query:
      If your query is still giving you problems, echo it as it's done in the above test.  Then copy it from the browser and paste it into you database client program.  This will show you if the query in your code is a correct query according to your database program.
    • Searching Out the Problem:
      Should your query continue to cause problems, strip the query from the above test down to it's smallest, simplest query.  E.g.:

      PHP Code:

      <?php

      "SELECT user_name, user_id, company_name FROM user, company WHERE user_id=19 AND user.user_id=company.user_id";

      ?>

      becomes:

      PHP Code:

      <?php

      "SELECT user_name, user_id FROM user WHERE user_id=19";

      ?>

      Keep making the simple query bigger and bigger one item at a time, testing each result to see if this is where the error is occurring.

     
  4. Split Query Result Across Several Pages
    Here is some code to do it:

    PHP Code:

    <?php

    Function paginate_and_display_results ($rowResultsArray, $pageNum=1, $rowsPerPage=10, $extraHTMLParms="")
    {
      global $PHP_SELF;

      $output = "";

      // $pageNum starts at 1.
      $startRow = ($pageNum - 1) * $rowsPerPage;
      $stopRow = $startRow + $rowsPerPage;
      $cnt = 0;

      for ($i = $startRow; ($i < count($rowResultsArray)) && ($i < $stopRow); $i++){
        while (list ($k,$v) = @each($rowResultsArray[$i])){
          echo "$v |";
        }
        echo "<br>\n";

        $cnt++;
      }

      $url = "$PHP_SELF?$extraHTMLParms";

      $numPages = ceil(count($rowResultsArray) / $rowsPerPage);

      $output .= "<table width=\"100%\">\n";
      $output .= "<tr><td width=\"15%\">";
      if ($pageNum != 1)
        $output .= "<a href=\"$url&pageNum=" . ($pageNum-1) . "\">previous</a>";
      $output .= " </td><td align=\"center\" width=\"70%\">\n";

      for ($i = 1; $i < $numPages+1; $i++){
        if ($pageNum == $i) $output .= "$i ";
        else $output .= "<a href=\"$url&pageNum=" . $i . "\">$i</a> ";
      }

      $output .= "</td><td align=\"right\" width=\"15%\">";
      if ($pageNum < (int)$numPages)
        $output .= "<a href=\"$url&pageNum=" . ($pageNum+1) . "\">next</a>";
      $output .= " </td></tr>\n";
      $output .= "</table>\n";

      echo $output;
    }

    $results[0] = array ("id","name");
    $results[1] = array ("12","kris");
    $results[2] = array ("14","john");

    if (!isset($pageNum)) $pageNum = 1;

    paginate_and_display_results ($results, $pageNum, 1);


    ?>

     
  5. Free PHP/MySQL Servers
    A search result of PHP hosting sites submitted by members is available here.
    A search result of MySQL hosting sites submitted by members is available here.

     
  6. Free Scripts
    Free scripts are available at www.hotscripts.com

     
  7. Fatal error: Call to undefined function: ocilogon()
    You either need the php_oci.dll (Windows) or configure PHP with Oracle (Unix).

     
  8. How To Show PHP Data in HTML Form Fields
    To display PHP data in the HTML form inside an HTML page, just do the following:

    PHP Code:

    <?php

    $name = "Sam";

    ?>

    HTML page:

    <html>
      <form enctype="multipart/form-data" method="post" action="<?php global $PHP_SELF; echo $PHP_SELF ?>">
        <input type="text" name="name" value="<?php echo $name ?>">
      </form>
    </html>

     
  9. Warning: Undefined variable
    It has to do with your error reporting level in the php.ini file;  you may not have E_NOTICE turned off.  Make sure your error_reporting line looks like this:

    php.ini:

    error_reporting = E_ALL & ~E_NOTICE

     

Previous Page Page 2 of 3 Next Page