SunQuest
           Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

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:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old January 5th, 2007, 01:31 AM
drjake drjake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 drjake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Create dynamic sites with PHP and MySQL

Hey guys,

As you can see I'm new here, and very new to PHP and MySQL.

In this tutorial it talks about new versions of php may have difficulty with the code provided. Specifically the instructions on pages 8-10 of the Create Dynamic sites with PHP and MySQL tutorial, in the Putting it all together section. How would I complete that sections with newer php (without register_globals) or is it even possible?

Jake

Reply With Quote
  #2  
Old January 5th, 2007, 01:43 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 963 IAmALlama User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 7 h 9 m 43 sec
Reputation Power: 2
RE: RE: Create dynamic sites with PHP and MySQL

what register globals does is turns all the variables from user input like $_POST and $_GET into standard variables. for example on page 10, putting it all together, in the code they use if($submit){//whatever}. the proper way to call that is really if($_POST['submit']){//whatever}. if you use the $_POST part, then there is no problem.

Reply With Quote
  #3  
Old January 5th, 2007, 02:49 AM
drjake drjake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 drjake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: Create dynamic sites with PHP and MySQL

Thanks, that worked. I appreciate it.

Reply With Quote
  #4  
Old January 6th, 2007, 06:52 AM
drjake drjake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 drjake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: Create dynamic sites with PHP and MySQL

I ran into another problem in the same tutorial which I am unable to troubleshoot. Under the section, Editing data, I am running into trouble with the variable $PHP_SELF.
I using PHP 5.2, and Apache 2.2.3.

Here's the code (some changes that I made, due to the newer version of php. Some of them are guesses):

php Code:
Original - php Code
  1.  
  2. <HTML>
  3. <?php
  4. if($_GET['submit'])
  5. {
  6.     $db = mysql_connect("localhost", "root", "mypassword");
  7.     mysql_select_db("learndb",$db);
  8.     //for new PHP
  9.     $first=$_GET[first];
  10.     $last=$_GET[last];
  11.     $nickname=$_GET[nickname];
  12.     $email=$_GET[email];
  13.     $salary=$_GET[salary];
  14.     //
  15.     $sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES ('$first','$last', '$nickname','$email', '$salary')";
  16.     $result = mysql_query($sql);
  17.     echo "Thank you! Information Entered.n";
  18. }
  19. else if($_GET['update'])
  20. {
  21.     $db = mysql_connect("localhost", "root", "mypassword");
  22.     mysql_select_db("learndb",$db);
  23.     //for new PHP
  24.     $first=$_GET[first];
  25.     $last=$_GET[last];
  26.     $nickname=$_GET[nickname];
  27.     $email=$_GET[email];
  28.     $salary=$_GET[salary];
  29.     //
  30.     $id = $_GET['id'];
  31.     $sql = "UPDATE personnel SET firstname='$first', lastname='$last', nick='$nickname', email='$email', salary='$salary' WHERE id=$id";
  32.     $result = mysql_query($sql);
  33.     echo "Thank you! Information updated.n";
  34. }
  35. else if($id)
  36. {
  37.     $db = mysql_connect("localhost", "root", "mypassword");
  38.     mysql_select_db("learndb",$db);
  39.     $result = mysql_query("SELECT * FROM personnel WHERE id=$id",$db);
  40.     $myrow = mysql_fetch_array($result);
  41. ?>
  42. <form method="get" action="<?php echo "$PHP_SELF"?>">
  43. <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
  44. First Name:<input type="Text" name="first" value="<?php echo $myrow["firstname"]?>"><br>
  45. Last name:<input type="Text" name="last" value="<?php echo
  46. $myrow["lastname"]?>"><br>
  47. Nick Name:<input type="Text" name="nickname" value="<?php echo
  48. $myrow["nick"]?>"><br>
  49. E-mail:<input type="Text" name="email" value="<?php echo $myrow["email"]?>"><br>
  50. Salary:<input type="Text" name="salary" value="<?php echo $myrow["salary"]?>"><br>
  51. <input type="Submit" name="update" value="Update information"></form>
  52. <?php
  53. }
  54. else
  55. {
  56. ?>
  57. <form method="get" action="<?php echo $PHP_SELF?>">
  58. First name:<input type="Text" name="first"><br>
  59. Last name:<input type="Text" name="last"><br>
  60. Nick Name:<input type="Text" name="nickname"><br>
  61. E-mail:<input type="Text" name="email"><br>
  62. Salary:<input type="Text" name="salary"><br>
  63. <input type="Submit" name="submit" value="Enter information">
  64. </form>
  65. <?php
  66. }
  67. ?>
  68. </HTML>

This is following the tutorial referenced in the title of this thread.

Reply With Quote
  #5  
Old January 6th, 2007, 09:45 AM
DimX DimX is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 26 DimX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 32 sec
Reputation Power: 0
RE: RE: Create dynamic sites with PHP and MySQL

Use $_SERVER['PHP_SELF'], also
php Code:
Original - php Code
  1. $first=$_GET[first];

is actually wrong (although it may work and throw an E_NOTICE). It must be
php Code:
Original - php Code
  1. $first=$_GET['first'];

Reply With Quote
  #6  
Old January 7th, 2007, 07:45 PM
drjake drjake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 drjake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: Create dynamic sites with PHP and MySQL

Thanks for pointing out those missing single quotes, and I don't understand why I need the $_SERVER['PHP_SELF'] could you elaborate on that?

I made those changes, but I get the following error:

php Code:
Original - php Code
  1.  
  2. Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in (location) on line 41


What does T_ENCAPSED_AND_WHITESPACE mean?

Reply With Quote
  #7  
Old January 7th, 2007, 08:39 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 963 IAmALlama User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 7 h 9 m 43 sec
Reputation Power: 2
RE: RE: Create dynamic sites with PHP and MySQL

the variable is really $_SERVER['PHP_SELF']. the $PHP_SELF variable is the result of having register globals on, everything in the $_SERVER array is made into its own variable just like with $_POST, $_GET, $_REQUEST, $_COOKIE, $_SESSION, $_ENV, $_SERVER...those are all super-global arrays which means they are created by php and can be used anywhere without having to declare them as global. turning on register globals makes anything in those arrays be extract() from the array and turned into non array variables.

Reply With Quote
  #8  
Old January 8th, 2007, 04:47 AM
drjake drjake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 drjake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: Create dynamic sites with PHP and MySQL

Thanks for the explanation it makes sense now. Any idea why this wouldn't work?

Reply With Quote
  #9  
Old January 8th, 2007, 05:14 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: RE: Create dynamic sites with PHP and MySQL

I believe line 41 is this: <form method="get" action="<?php echo "$PHP_SELF"?>">

Could you post what you changed this to?

Reply With Quote
  #10  
Old January 8th, 2007, 05:20 AM
drjake drjake is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 drjake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: RE: Create dynamic sites with PHP and MySQL

Certainly

php Code:
Original - php Code
  1.  
  2. <form method="get" action="<?php echo "$_SERVER['PHP_SELF']?>">

Reply With Quote
  #11  
Old January 8th, 2007, 05:23 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: RE: Create dynamic sites with PHP and MySQL

To get the most help from PHP to find minor syntax errors, put the following line in after your first opening <?php tag -

error_reporting(E_ALL);

This will cause a number of Notice messages to be output. You should fix as many of these as possible in the name of syntacticly correct code. Each of these Notices are logged to the server log file and cause a minor speed penalty.

Reply With Quote
  #12  
Old January 8th, 2007, 05:28 AM