PHP Malfunction

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

PHP Malfunction

Postby chtoledo » 23. February 2010 04:05

Does anybody know why the following PHP function is not working with my XAMPP software ?

Example:

<?php

$num1 = $_POST ['Numero1'];
$num2 = $_POST ['Numero2'];

echo "El incremento del primer número es: " .$num1++;

?>

when echoing the instruction $num1++ it just copies the same number without any increment, I have tried other methods like: num$1 = num$1 + 1; but nothing seems to work. Can anybody help me ?

Thank you very much.
chtoledo
 
Posts: 4
Joined: 23. February 2010 03:54

Re: PHP Malfunction

Postby Altrea » 23. February 2010 06:42

$var++ is a POST-increment. Your var is been incremented after you outputed it.
you can use Pre-increment: ++$var. try if this works for you in an echo.

it is cleaner to increment your var a line earlier
Code: Select all
<?php

$num1 = $_POST ['Numero1'];
$num2 = $_POST ['Numero2'];

$num1 = $num1 + 1;
echo "El incremento del primer número es: " .$num1;

?>
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: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP Malfunction

Postby chtoledo » 23. February 2010 17:13

Thank you very much... Ill try that and let you know.
chtoledo
 
Posts: 4
Joined: 23. February 2010 03:54

Re: PHP Malfunction

Postby chtoledo » 24. February 2010 03:43

This didn't work, do you have any other suggestions? Im using XAMPP on a Mac OS Snow Leopard....
chtoledo
 
Posts: 4
Joined: 23. February 2010 03:54

Re: PHP Malfunction

Postby caltuna » 24. February 2010 06:23

My guess is that there is nothing or garbage in $_POST ['Numero1']

Do echo $_POST ['Numero1'];

and see what is there.
caltuna
 
Posts: 111
Joined: 05. May 2009 16:35

Re: PHP Malfunction

Postby Altrea » 24. February 2010 06:31

I haven't got a Mac OS to test.

But on my machine, it works.
Try my Test-Code:
Code: Select all
<?php
error_reporting(E_ALL);
if ('POST' == $_SERVER['REQUEST_METHOD']) {
    $num1 = $_POST['Numero1'];
    $num2 = $_POST['Numero2'];

    var_dump($num1, $num2);
   
    $num1 = $num1 + 1;
    echo "El incremento del primer número es: " .$num1;
}
   
?>
<html>
<head>
<title>Test</title>
</head>
<body>
   
    <form action="" method="post">
        <input name="Numero1" type="text" />
        <input name="Numero2" type="text" />
        <input type="submit" />
    </form>
   
</body>
</html>
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: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: PHP Malfunction

Postby chtoledo » 25. February 2010 00:47

The php code you sent me worked with my form, but how? and why is my original code not working? I really appreciate all your help.

Best Regards
chtoledo
 
Posts: 4
Joined: 23. February 2010 03:54

Re: PHP Malfunction

Postby Altrea » 25. February 2010 06:34

I don't know.
I haven't got your Form-Code to test it.

Are your input fields named correct?

You can check every variable value with an echo to find out, where your variable has unexpected values.
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: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 13 guests