SunQuest
           PHP Installation
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Installation

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 23rd, 2004, 01:51 PM
Garcia Garcia is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Aberdeen, Scotland
Posts: 19 Garcia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP, MySQL & Apache

Hi, I've just installed Apache 2.0.48, PHP 4.3.4 and MySQL 3.23.49 on my Windows machine. I've got simple functions like phpinfo() and some code from a PHP & MySQL for Dummies book, and they both work fine - I'm getting information on PHP, and some tables from MySQL. However, a simple database interface included with the book, which has two fields, one for entering the database name, and the other for entering the query, just plain isn't working.
First up, the $PHP_SELF variable. I get the following error message:

Notice: Undefined variable: PHP_SELF in D:serverdummiesmysql_send.php on line 76
?form=yes method="post">

Okay, fair enough. I've replaced that with other variations of the same function, and the error message disappears. However, the problem of it not doing anything still stands.
To make it work, I've been told by the book to simply enter 'show databases', to display a list of all the databases. No prizes for guessing what happens (or doesn't happen).
Below is the entire code for the page, if anyone has any ideas on whats going on, please let me know so I can get back to work on my website
(installing PHP and MySQL on my machine was only as a testing area - I'm on 56k, so uploading all the time is a bit of a bother).

php Code:
Original - php Code
  1. <!-- Program Name:  mysql_send.php
  2.      Description: PHP program that sends an SQL query to the
  3.                   MySQL server and displays the results.
  4. -->
  5. <html>
  6. <head>
  7. <title>SQL Query Sender</title>
  8. </head>
  9. <body>
  10. <?php
  11.  $user="root";
  12.  $host="localhost";
  13.  $password="";
  14.  
  15.  /* Section that executes query */
  16.  if (@$form == "yes") 
  17.  {
  18.    mysql_connect($host,$user,$password);
  19.    mysql_select_db($database);
  20.    $query = stripSlashes($query) ;
  21.    $result = mysql_query($query);
  22.    echo "Database Selected: <b>$database</b><br>
  23.           Query: <b>$query</b>
  24.           <h3>Results</h3>
  25.           <hr>";
  26.    if ($result == 0)
  27.       echo("<b>Error " . mysql_errno() . ": " . mysql_error() . "</b>");
  28.  
  29.    elseif (@mysql_num_rows($result) == 0)
  30.       echo("<b>Query completed. No results returned.</b><br>");
  31.    else
  32.    {
  33.      echo "<table border='1'>
  34.            <thead>
  35.             <tr>";
  36.              for ($i = 0; $i < mysql_num_fields($result); $i++)
  37.              {
  38.                  echo("<th>" . mysql_field_name($result,$i) . "</th>");
  39.              }
  40.      echo " </tr>
  41.            </thead>
  42.            <tbody>";
  43.              for ($i = 0; $i < mysql_num_rows($result); $i++)
  44.              {
  45.                 echo "<tr>";
  46.                 $row = mysql_fetch_row($result);
  47.                 for ($j = 0; $j < mysql_num_fields($result); $j++)
  48.                 {
  49.                   echo("<td>" . $row[$j] . "</td>");
  50.                 }
  51.                 echo "</tr>";
  52.              }
  53.              echo "</tbody>
  54.                   </table>";
  55.    }
  56.    echo "<hr><br>
  57.          <form action=$PHP_SELF method=post>
  58.           <input type=hidden name=query value="$query">
  59.           <input type=hidden name=database value=$database>
  60.           <input type=submit name="queryButton" value="New Query">
  61.           <input type=submit name="queryButton" value="Edit Query">
  62.          </form>";
  63.    unset($form);
  64.    exit();
  65.  }
  66.  
  67.  /* Section that requests user input of query */
  68.  @$query = stripSlashes($query);
  69.  if (@$queryButton != "Edit Query") 
  70.  {
  71.    $database = " ";
  72.    $query = " ";
  73.  }
  74. ?>
  75.  
  76. <form action=<?php echo $PHP_SELF ?>?form=yes method="post">
  77.  <table>
  78.   <tr>
  79.    <td align="right"><b>Type in database name</b></td>
  80.    <td>
  81.      <input type=text name="database" value=<?php echo $database ?> >
  82.    </td>
  83.   </tr>
  84.   <tr>
  85.    <td align="right" valign="top"><b>Type in SQL query</b></td>
  86.      <td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea>
  87.    </td>
  88.   </tr>
  89.   <tr>
  90.    <td colspan="2" align="center"><input type="submit" value="Submit Query"></td>
  91.   </tr>
  92.  </table>
  93. </form>
  94. </body>
  95. </html>


Thanks.

Reply With Quote
  #2  
Old January 23rd, 2004, 02:51 PM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: PHP, MySQL & Apache

I haven't gone through PHP & MySQL for Dummies book. It might be that it supports older version of PHP. (Not sure though) For the error that you are getting it might be that the register_globals setting is set to off in your php.ini file.
So instead of $PHP_SELF try using $_SERVER["PHP_SELF"]
Instead of $database try using $_POST["database"]
Instead of $query try using $_POST["query"]

Thats what I spotted for the moment. Try that out and see.




Reply With Quote
  #3  
Old January 23rd, 2004, 07:27 PM
Andrew's Avatar
Andrew Andrew is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,937 Andrew User rank is Private First Class (20 - 50 Reputation Level)Andrew User rank is Private First Class (20 - 50 Reputation Level)  Folding Points: 2429 Folding Title: Novice Folder
Time spent in forums: 4 Days 1 h 57 m 37 sec
Reputation Power: 3
Orkut
RE: PHP, MySQL & Apache

dont forget your ;'s

Reply With Quote
  #4  
Old January 23rd, 2004, 09:32 PM
Andrew's Avatar
Andrew Andrew is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,937 Andrew User rank is Private First Class (20 - 50 Reputation Level)Andrew User rank is Private First Class (20 - 50 Reputation Level)  Folding Points: 2429 Folding Title: Novice Folder
Time spent in forums: 4 Days 1 h 57 m 37 sec
Reputation Power: 3
Orkut
RE: PHP, MySQL & Apache

Because you have missed some out.

Reply With Quote
  #5  
Old January 23rd, 2004, 10:27 PM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: PHP, MySQL & Apache

If you would like to use $PHP_SELF as a variable as the book suggests, you need to edit your php.ini file to turn register_globals [b]on[b]. Theoretically, the book is right, but it assumes you have globals turned on.

Reply With Quote
  #6  
Old January 24th, 2004, 01:08 PM
Garcia Garcia is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Aberdeen, Scotland
Posts: 19 Garcia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: PHP, MySQL & Apache

Quote:
If you would like to use $PHP_SELF as a variable as the book suggests, you need to edit your php.ini file to turn register_globals [b]on[b]. Theoretically, the book is right, but it assumes you have globals turned on.


nawlej, you hero - works perfectly
Thanks a lot guys!

Reply With Quote
  #7  
Old January 24th, 2004, 01:22 PM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: PHP, MySQL & Apache

Quote:
nawlej, you hero - works perfectly


He is.. But other's aren't zero either.

The book is right for the time when it was written. But you need to get used to new releases of PHP. So only a book won't do the job for you. You need to be in touch. www.php.net the home of PHP is always the first option. And Codewalkers.com community will keep you up-to-date.

I recommend you to set the register_globals option to OFF. Even though you are a Newbie learn the better way.

Have a look at this http://www.php.net/register_globals

Reply With Quote
  #8  
Old January 24th, 2004, 09:35 PM
Andrew's Avatar
Andrew Andrew is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,937 Andrew User rank is Private First Class (20 - 50 Reputation Level)Andrew User rank is Private First Class (20 - 50 Reputation Level)  Folding Points: 2429 Folding Title: Novice Folder
Time spent in forums: 4 Days 1 h 57 m 37 sec
Reputation Power: 3
Orkut
RE: PHP, MySQL & Apache

Yeh You should write your scripts to cope with register_globals being turned off which is set as default on most servers. Even if you have register_globals on then there will come a day when you give the script to someone and it wont work because register_globals is off on their server and they cant turn it on because its a shared host. So its better to make your scripts work without register globals.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Installation > PHP, MySQL & Apache


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games