xampp problem

Problems with the Linux version of XAMPP, questions, comments, and anything related.

xampp problem

Postby conta » 26. July 2010 20:36

so i reinstalled debian for salix... i couldn't find easy way to get lamp to get inside my machine so I decided for xampp

installation easy, no problems ;]

but, i copied backuped code i used in debian and put to xampp

i got errors, thought no idea why, cause in debian no problem ;\

Notice: Undefined index: id in /home/conta/web/admin/add.php on line 16
Notice: Undefined index: comments in /home/conta/web/admin/add.php on line 17

i put numbers in code so you can see which ones they are

Code: Select all
<?php
include("menu.php");
?>
 <p>Be patient, please, Adding might be slowly. It's not fault of your keyboard, we all know ...
<form action="<?php echo $PHP_SELF;?>" method="post">
<p>ID: <input type="text" name="id" /></p>

<p>Your comments:<br />
<textarea name="comments" rows="4" cols="26"></textarea></p>

<p><input type="submit" value="OK"></p>
</form>

<?php

16>> $id=$_POST['id'];
17>> $comments=$_POST['comments'];

if ($id<>0) {
$xml = simplexml_load_file("http://api.erepublik.com/v2/feeds/citizens/$id");
$name = $xml->name;   
mysql_query("INSERT INTO legionar (id, name, comment)
VALUES (\"$id\",\"$name\",\"$comments\")")
                              or  die('<b>Data Insert Error:</b> ' . mysql_error());
?>

<p>I added ID <b><?php echo $_POST['id']; ?></b> with Comment <b><?php echo $_POST['comments']; ?></b>. 
Let's go back to <a href="index.php" target="_self">Main menu</a>!                       
<?php  }
mysql_close($con1);
?>


i dont know why is that, but after I write something and push OK, i get 404 error...

adress bar of my browser looks like this after pushing OK:

Code: Select all
http://localhost/web/admin/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20variable:%20PHP_SELF%20in%20%3Cb%3E/home/conta/web/admin/add.php%3C/b%3E%20on%20line%20%3Cb%3E5%3C/b%3E%3Cbr%20/%3E


with debian [some debian lamp, not xampp] i never get such a stuff, everything was working well

thanks for any ideas, i use latest xampp
conta
 
Posts: 3
Joined: 26. July 2010 20:24

Re: xampp problem

Postby Altrea » 26. July 2010 21:01

conta wrote:Notice: Undefined index: id in /home/conta/web/admin/add.php on line 16
Notice: Undefined index: comments in /home/conta/web/admin/add.php on line 17

$_POST['id'] and $_POST['comments'] were not filled initially. They are just filled if you submit your form.

conta wrote:i dont know why is that, but after I write something and push OK, i get 404 error...

Look which url is in your address bar after submitting your form! $PHP_SELF is not filled.
Try $_SERVER['PHP_SELF'] instead

conta wrote:with debian [some debian lamp, not xampp] i never get such a stuff, everything was working well

webserver and php configurations can be differend. Maybe a differend error_reporting level?

Just do everything right and it will work ;)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: xampp problem

Postby conta » 26. July 2010 21:27

$_SERVER['PHP_SELF']

this worked... but still it is weird after all, i tried my website with more webhostings, but i have never had any problem with that...

in fact my code is just modification of some tutorials...
conta
 
Posts: 3
Joined: 26. July 2010 20:24

Re: xampp problem

Postby Altrea » 26. July 2010 21:55

In fact, your code is sloppy.

$PHP_SELF is just setted on some webhosts because they use or simulate register_globals. register_globals is a really bad php setting. It can be a big big security risk, especially if you don't know much from php, like in your case.

To get rid of your warnings use isset() or empty()

or test if your form is submitted with something like that
Code: Select all
if ('POST' == $_SERVER['REQUEST_METHOD']) {
...
}
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: xampp problem

Postby conta » 27. July 2010 09:10

sure thing, my code is far away from being perfect ;]

i am not developer, I have no experience with coding and what i did is put some tutorials together.. sometimes i dont even know [or I dont care] how it works, if it works ok, and it always did ;]

i mean, until I tried to run it in xampp, and I am not trying to say that xampp is bad. nope.
what i try to say is question: can possibly happen that something that works fine with xampp gonna work bad in another one? just like happend to me now when I changed to xampp?

thanks for help ;]
conta
 
Posts: 3
Joined: 26. July 2010 20:24

Re: xampp problem

Postby Altrea » 27. July 2010 09:28

conta wrote:sometimes i dont even know [or I dont care] how it works, if it works ok, and it always did ;]
i mean, until I tried to run it in xampp, and I am not trying to say that xampp is bad. nope.


In many cases older Versions of php are less strict than newer ones. It's very easy to configure php to hide notices and warnings, too. In both cases your script looks alright. But thats not the truth. Thats like running down a hill with hands in front of your eyes (everything is alright until there is a rock on your way).

conta wrote:what i try to say is question: can possibly happen that something that works fine with xampp gonna work bad in another one? just like happend to me now when I changed to xampp?

Sure. Easiest case: your webhost runs an older php version and you uses PHP 5.3 Syntax, because you read in some tut that PHP 5.3 is such a cool thing.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 13 guests