Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

This is a discussion on Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?> within the alt.comp.lang.php forums, part of the PHP Programming Forums category; First, Happy New Year 2007 in your office with MS Office! My question is not MS related. It's about ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2007
psnospam@googlemail.com
 
Posts: n/a
Default Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

First, Happy New Year 2007 in your office with MS Office!

My question is not MS related. It's about Php. I have started learning
it although I am not a programer.

I have installed Apache and MySql on my computer and set up Php to work
along. Then I also have PhpMyAdmin working from my Usb kye to avoid any
conflict with the Apache installation on my hard drive.

As done with my curriculum, I would like to know why the following
script doesnt work when I run it directly from the Apache Server (I get
:

"Forbidden

You don't have permission to access /< on this server." :

===O===

<html>
<head>
</head>

<body>

<?php

$_POST = '';

if (!$_POST['submit'])

{

?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

Enter a number : <input name='numb' size="2">

<input type="submit" name="submit" value="Valider">

</form>

<?php

}

else

{

$nombre = $_POST['numb'];

if ($numb < 0)

{echo 'your number is -';

}

elseif ($numb = 0)

{echo 'you have entered 0';

}

else

{echo 'your number is +';

}
}

?>

</body>

</html>

===O===

When I run the same script on PhpMyAdmin, I have this message :

Notice: Uninitialized string offset: 0 in
g:\easyphp1-8\www\site2practise\ex15h.php on line 13

line 13 is about this:

if (!$_POST['submit']).

and if I delete the entire "if" structure, still running the script on
PhpMyAdmin, I get:

"Notice: Undefined index: nombre in
g:\easyphp1-8\www\site2practise\ex15.php on line 25"

Line 25 is about this:

$nombre = $_POST['nombre'];

I don't think the last 2 errors are linked with the first one. The last
2 could be about the syntax and/or Php version I am running.

Now I think I know the answer on how to solve the first error about
Forbidden access

It's because I have set a password when I installed Apache. And the
issue is not the same when I run the script from PhpMyAdmin, because
there I have no password setup. So the issue is about the syntax.

How can the script above run on a Php engine that was setup with a
password with little change? for instance

-> $connection = mysql_connect($host, $user, $pass) or die ('impossible
de se connecter!');

???

Thanks,

Pascal

Reply With Quote
  #2 (permalink)  
Old 01-05-2007
Richard Schneidt
 
Posts: n/a
Default Re: Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

psnospam@googlemail.com schrieb:
> First, Happy New Year 2007 in your office with MS Office!
>
> My question is not MS related. It's about Php. I have started learning
> it although I am not a programer.
>
> I have installed Apache and MySql on my computer and set up Php to work
> along. Then I also have PhpMyAdmin working from my Usb kye to avoid any
> conflict with the Apache installation on my hard drive.
>
> As done with my curriculum, I would like to know why the following
> script doesnt work when I run it directly from the Apache Server (I get
> :
>
> "Forbidden
>
> You don't have permission to access /< on this server." :


Your webserver setup is not o.


>
> ===O===
>
> <html>
> <head>
> </head>
>
> <body>
>
> <?php
>
> $_POST = '';
>
> if (!$_POST['submit'])
>
> {
>
> ?>
>
> <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
>
> Enter a number : <input name='numb' size="2">
>
> <input type="submit" name="submit" value="Valider">
>
> </form>
>
> <?php
>
> }
>
> else
>
> {
>
> $nombre = $_POST['numb'];
>
> if ($numb < 0)
>
> {echo 'your number is -';
>
> }
>
> elseif ($numb = 0)
>
> {echo 'you have entered 0';
>
> }
>
> else
>
> {echo 'your number is +';
>
> }
> }
>
> ?>
>
> </body>
>
> </html>
>
> ===O===
>
> When I run the same script on PhpMyAdmin, I have this message :
>
> Notice: Uninitialized string offset: 0 in
> g:\easyphp1-8\www\site2practise\ex15h.php on line 13
>
> line 13 is about this:
>
> if (!$_POST['submit']).



you didn't call this page from a form that has a form element submit, so
you cannot evaluate $_POST['submit'], therefore you should check it this
way:

if(!isset($_POST['submit']))

>
> and if I delete the entire "if" structure, still running the script on
> PhpMyAdmin, I get:
>
> "Notice: Undefined index: nombre in
> g:\easyphp1-8\www\site2practise\ex15.php on line 25"
>
> Line 25 is about this:
>
> $nombre = $_POST['nombre'];


same here no nombre in POST data.

>
> I don't think the last 2 errors are linked with the first one. The last
> 2 could be about the syntax and/or Php version I am running.
>
> Now I think I know the answer on how to solve the first error about
> Forbidden access
>
> It's because I have set a password when I installed Apache. And the



apache setup needs no password, if you have created an htpass file then
you may need to adjust the webserver configuration.

> issue is not the same when I run the script from PhpMyAdmin, because
> there I have no password setup. So the issue is about the syntax.
>
> How can the script above run on a Php engine that was setup with a
> password with little change? for instance
>
> -> $connection = mysql_connect($host, $user, $pass) or die ('impossible
> de se connecter!');
>
> ???
>
> Thanks,
>
> Pascal
>


I think you should first get a basic php + Apache/IIS install.
Reply With Quote
  #3 (permalink)  
Old 01-05-2007
Hendri Kurniawan
 
Posts: n/a
Default Re: Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

In addition to Richard answer. If you just want Apache/MySQL/PHP to
work, not knowing how they
fit together, I suggest LAMP (I think the site is called apachefriend or
something like that - Just google it,
and you'll find it). It is a package installation. You won't learn how
to set up server properly tho.

Hendri Kurniawan

psnospam@googlemail.com wrote:
> First, Happy New Year 2007 in your office with MS Office!
>
> My question is not MS related. It's about Php. I have started learning
> it although I am not a programer.
>
> I have installed Apache and MySql on my computer and set up Php to work
> along. Then I also have PhpMyAdmin working from my Usb kye to avoid any
> conflict with the Apache installation on my hard drive.
>
> As done with my curriculum, I would like to know why the following
> script doesnt work when I run it directly from the Apache Server (I get
> :
>
> "Forbidden
>
> You don't have permission to access /< on this server." :
>
> ===O===
>
> <html>
> <head>
> </head>
>
> <body>
>
> <?php
>
> $_POST = '';
>
> if (!$_POST['submit'])
>
> {
>
> ?>
>
> <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
>
> Enter a number : <input name='numb' size="2">
>
> <input type="submit" name="submit" value="Valider">
>
> </form>
>
> <?php
>
> }
>
> else
>
> {
>
> $nombre = $_POST['numb'];
>
> if ($numb < 0)
>
> {echo 'your number is -';
>
> }
>
> elseif ($numb = 0)
>
> {echo 'you have entered 0';
>
> }
>
> else
>
> {echo 'your number is +';
>
> }
> }
>
> ?>
>
> </body>
>
> </html>
>
> ===O===
>
> When I run the same script on PhpMyAdmin, I have this message :
>
> Notice: Uninitialized string offset: 0 in
> g:\easyphp1-8\www\site2practise\ex15h.php on line 13
>
> line 13 is about this:
>
> if (!$_POST['submit']).
>
> and if I delete the entire "if" structure, still running the script on
> PhpMyAdmin, I get:
>
> "Notice: Undefined index: nombre in
> g:\easyphp1-8\www\site2practise\ex15.php on line 25"
>
> Line 25 is about this:
>
> $nombre = $_POST['nombre'];
>
> I don't think the last 2 errors are linked with the first one. The last
> 2 could be about the syntax and/or Php version I am running.
>
> Now I think I know the answer on how to solve the first error about
> Forbidden access
>
> It's because I have set a password when I installed Apache. And the
> issue is not the same when I run the script from PhpMyAdmin, because
> there I have no password setup. So the issue is about the syntax.
>
> How can the script above run on a Php engine that was setup with a
> password with little change? for instance
>
> -> $connection = mysql_connect($host, $user, $pass) or die ('impossible
> de se connecter!');
>
> ???
>
> Thanks,
>
> Pascal
>

Reply With Quote
  #4 (permalink)  
Old 01-05-2007
Rik
 
Posts: n/a
Default Re: Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

Hendri Kurniawan wrote:
> In addition to Richard answer. If you just want Apache/MySQL/PHP to
> work, not knowing how they
> fit together, I suggest LAMP (I think the site is called apachefriend
> or something like that - Just google it,


I think you mean XAMPP?

--
Rik Wasmus


Reply With Quote
  #5 (permalink)  
Old 01-05-2007
Hendri Kurniawan
 
Posts: n/a
Default Re: Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

Yup I was just going to amend that.
:)

Hendri Kurniawan

Rik wrote:
> Hendri Kurniawan wrote:
>> In addition to Richard answer. If you just want Apache/MySQL/PHP to
>> work, not knowing how they
>> fit together, I suggest LAMP (I think the site is called apachefriend
>> or something like that - Just google it,

>
> I think you mean XAMPP?
>

Reply With Quote
  #6 (permalink)  
Old 01-08-2007
n0ctis
 
Posts: n/a
Default Re: Php newbie ; $connection and <?=$_SERVER['PHP_SELF']?>

I use XAMPP for off-server site testing. Its a great tool for either setting up
your own minimal-hassle web server or as a script testing device.

Hendri Kurniawan wrote:
> Yup I was just going to amend that.
> :)
>
> Hendri Kurniawan
>
> Rik wrote:
>> Hendri Kurniawan wrote:
>>> In addition to Richard answer. If you just want Apache/MySQL/PHP to
>>> work, not knowing how they
>>> fit together, I suggest LAMP (I think the site is called apachefriend
>>> or something like that - Just google it,

>>
>> I think you mean XAMPP?
>>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0