Program Error…? – PHP

  php

Q(Question):

hi all,
i dont know what the error with this program.I cannot get the value.

—-sample.php—–

<?php
ob_start();
@session_start();
require_once ("damn.php");
createsessions(sex);
?>
<html>
<body>
<form action="sample2.php" method="post">
<input type="radio" name="sex" value="male" /> Male
<br />
<input type="radio" name="sex" value="female" /> Female
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

——-sample2.php——-

<?php
$sex=$_SESSION[sex];
echo $sex;
?>

——-damn.php——

<?php
function createsessions($sex)
{
session_register();
$_SESSION["sex"] = $sex;
}
?>

wen i press submit button i am not getting the echo value i am not knowing wer the error is….? so can any one…?
thanks in advance…

A(Answer):

You’re going to need to compile the extension. What OS are you on?

A(Answer):

@Markus

Windows XP Professional but why…?
Is the code i had writen is correct…? can we create session like that. can we call the session value like that….?
i dont know why it is not printing the value.

A(Answer):

You be savvy to C programming, would you, i.e. have a compiler on your box (Visual Studio C++, or something like)?

A(Answer):

@Markus

sorry i dont understand wat ur saying..
why do we need that..?
u r asking wat compiler i am having right. i am using php debugger(Nusphere)

A(Answer):

Whoa. For some reason, I posted this in the wrong thread. My bad. 🙂

A(Answer):

@niths

There are a few problems with your code that you should fix before anything else.
First of all, as always when you are developing your code, you should turn on the error messages. Otherwise you are flying blind. Remove the @ from the session_start function. It’s rarely a good idea to suppress errors, especially errors relating to functions that would cripple your application when they fail. – If you want to hide the errors from your visitors, use the Error and Logging config directives to hide and/or re-route the error messages, but always keep them enabled in one way or another, and use them when you are debugging your code. (Use the ini_set function to change them, or simply change them in your php.ini file.) Always quote strings! PHP is smart (or dumb, depending on the perspective) enough to convert unquoted text into a string for you, but that’s no excuse.


// INCORRECT!
$_SESSION[whatever] = "whatever";
// Correct
$_SESSION["whatever"] = "whatever";
// INCORRECT
$something = something;
// Correct
$something = "something";
// INCORRECT!
functionCall(something);
// Correct
functionCall("something");

And so on… The session_register function is deprecated and should therefore be avoided. But even so, the way you use it in your code is not the right way. – Line #5 of your damn.php file is the right way to set a session variable. It’s best to just forget the session_register function altogether.
Try to fix that and see if you get anywhere. If not, post any error messages you get here and tell us exactly what is happening, or not happening.

LEAVE A COMMENT