Php code not working at all!

hi guys i am newbie. My php code is not working at all. When i post say this:
<?php
echo ‘something’;
?>
its not even posting the echo. see i have been trying to write a code for user registration n login and it did not work at all. the html form is showing but all i get from the php part is literally this : ?> In fact from the echo code i posted above, the same thing happens, only ?> shows. Can someone help me, i tried reading so many tutorials & forums for solution but cant seem to find one. Pls help.

Cheers

Kums

Did you install PHP, MySQL and the webserver (presumably Apache) separately or use a “canned” installer like WAMP?

Php files must have a .php extension and start with <?php

Also try saving your file using another editor.

yes i did start with <?php. and secondly i am using notepad++. after writing the code, i just copy the code and paste it in kompozer. kompozer has a feature where you can paste your php code. then i saved the page and uploaded it.i did not act save it as php and then upload it to my server because it is already posted via kompozer. is what i am doing wrong?

first of all i am using mssql. and no i did not do any installation. i do not understand something, do i have to actually install php to act use it? i am a newbie and i thought it is installed in the host server and all i have to do is just write the coed and post it using kompozer or some other software. i am using kompozer. i just write in notepad++ then i just copy it and paste it in kompozer, save then upload to the server. is what i am doing wrong? someone suggested that i try phpinfo() and it worked, it gave me a list of info. pls advice

If you upload your files to a webserver with PHP installed then don’t worry about that part.

So apparantly everything is ok, and the problem should be your code. Is


<?php
echo 'something';
?> 

all there is in this particular file? Or are these three lines just a part of it?

<?php

$host = ‘AAAAAA’;
$user = ‘AAAAA’;
$pass = ‘AAAAAA’;
$db = ‘AAAAA’;

$connect = mssql_connect($host,$user,$pass) or die(‘Unable to connect’);
$database = mssql_select_db($db,$connect) or die(‘Unable to connect to selected database’);

if(isset ($_POST([‘submit’])))
{
$email = S_POST[‘email’];
$firstname = S_POST[‘firstname’];
$lastname = S_POST[‘lastname’];
$pwd = S_POST[‘pwd’];

		if trim($firstname) == "" || trim($lastname)=="" || trim($pwd)== ""
		{
		 echo 'You must enter both a firstname, lastname and password!!';
		}
		else
		{
		 $sql = "INSERT INTO users ([email],[first_name],[last_name],[password])VALUES('$email','$firstname','$lastname','$pwd')";
		 $result = mssql_query($sql);
		  if(!$result)
           {
            echo mssql_error();
            exit;
           }
		  
		  
		  mssql_free_result($result); 
          mssql_close();
		  echo "Data successfully inserted!!";			
		}


}

<form method = “post” action = “check.php”>
Email : <input type=“text” name=“email”><br>
First Name: <input type=“text” name=“firstname”><br>
Last Name : <input type=“text” name=“lastname”><br>
Password : <input type=“password” name=“pwd”><br>
<input type=“submit” name=“submit” value=“Register”

</form>

?>

so the php code i originally gave you was just am example, even a simple echo code is nt working. well i hv been writing the code on notepad++ and uploading it by pasting the code in kompozer. see i was told that it has to be uploaded with .php extension instead of hmtl and thats the reason why its not working. but i find that confusing, so how do i attach it to a certain link in my index page. pls advice and let me know what you think. appreciate it :slight_smile:

Well i can tell you immediately that THAT isnt going to work.

Your form code cant be inside the PHP bare like that.

Lets wrap it in some tags and see if we can see anything else glaring…


<?php

$host = 'AAAAAA';
$user = 'AAAAA';
$pass = 'AAAAAA';
$db = 'AAAAA';

$connect = mssql_connect($host,$user,$pass) or die('Unable to connect');
$database = mssql_select_db($db,$connect) or die('Unable to connect to selected database');



if(isset ($_POST(['submit'])))
{
$email = S_POST['email'];
$firstname = S_POST['firstname'];
$lastname = S_POST['lastname'];
$pwd = S_POST['pwd'];

if trim($firstname) == "" || trim($lastname)=="" || trim($pwd)== ""
{
echo 'You must enter both a firstname, lastname and password!!';
}
else
{
$sql = "INSERT INTO users ([email],[first_name],[last_name],[password])VALUES('$email','$firstname','$lastname','$pwd')";
$result = mssql_query($sql);
if(!$result)
{
echo mssql_error();
exit;
}


mssql_free_result($result);
mssql_close();
echo "Data successfully inserted!!";	
}


}

<form method = "post" action = "check.php">
Email : <input type="text" name="email"><br>
First Name: <input type="text" name="firstname"><br>
Last Name : <input type="text" name="lastname"><br>
Password : <input type="password" name="pwd"><br>
<input type="submit" name="submit" value="Register"

</form>

?>

Input tag on the second-to-last last line is missing it’s >.

Right, so… doesnt immediately look like anything else is wrong… shift that ?> up to above the <form> tag, and see if that comes out the way you’d like.

There is a missing > here:

<input type="submit" name="submit" value="Register"

… so if the OP looked at the source code of the generated web page, they would see the ‘broken’ html … I guess.

They should see nothing. This page would generate a WPSE; PHP would choke as soon as it encountered the form tag (UNEXPECTED T_STRING). I’m guessing he doesnt have display errors enabled in his test environment.

You guys were right!!! I saved the file under the wrong extension. and the second thing is, when i added the link for the php code i added the target url as “login.html”. it shoud have been “login.php” !!! thats where i went wrong. when i post a simple php echo code, it is working perfectly!!! Thank you very very much to you guys!!!

I am pleased you managed to solve your problem.

Next it is good practise to set the following:


<?php

  # hopefully return with an error rather than a blank screen
  error_reporting(-1); 
  ini_set('display_errors', true);


Also become familiar with “http://php.net/manual/en/index.php”, it has many good examples and detailed descriptions.

so i made the changes you suggested but the browser now gives me this error Fatal error: Can’t use function return value in write context in E:\kunden\homepages… The error is in this line if(isset ($_POST([‘submit’])))

if(isset ($_POST([‘submit’])))

too many brackets, SB:

if(isset ($_POST[‘submit’])) {
// do stuff

}