SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Did you install PHP, MySQL and the webserver (presumably Apache) separately or use a "canned" installer like WAMP?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,904
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Php files must have a .php extension and start with <?php

    Also try saving your file using another editor.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  4. #4
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    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?

  5. #5
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    Did you install PHP, MySQL and the webserver (presumably Apache) separately or use a "canned" installer like WAMP?
    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

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If you upload your files to a webserver with PHP installed then don't worry about that part.
    Quote Originally Posted by kumsan View Post
    someone suggested that i try phpinfo() and it worked, it gave me a list of info. pls advice
    So apparantly everything is ok, and the problem should be your code. Is
    PHP Code:
    <?php
    echo 'something';
    ?>
    all there is in this particular file? Or are these three lines just a part of it?

  7. #7
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    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 Code:
    <?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

  8. #8
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?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.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by StarLion View Post
    Right, so... doesnt immediately look like anything else is wrong
    There is a missing > here:
    Code:
    <input type="submit" name="submit" value="Register"

  10. #10
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    .. so if the OP looked at the source code of the generated web page, they would see the 'broken' html .. I guess.

  11. #11
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    .. 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.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  12. #12
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!!!

  13. #13
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,904
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by kumsan View Post

    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 Code:
    <?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.
    Last edited by John_Betong; Jan 15, 2013 at 08:13. Reason: spellin: not my fortay
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  14. #14
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    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 Code:
    <?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.
    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'])))

  15. #15
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    if(isset ($_POST(['submit'])))

    too many brackets, SB:

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

    }


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •