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.
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
$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’);
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
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.
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!!!
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’])))