1

My PHP File is showing raw code in the browser when accessed through a POST request.

I've created a phpinfo.php page on the localhost and when accessing it via a simple GET request, it shows the page properly, so I assume my PHP is all set up...

I am new to PHP and want to fix this. Here is the code for the PHP file...

< ?php

mysql_connect("localhost", "root", "Elixir") or die('Cannot connect to the dataabase because ' . mysql_error()); 

mysql_select_db("sslweb") or die('database name invalid... ' . mysql_error());

$Query = "INSERT INTO 'Login' ('UserName','FName','LName','Email','UserPassword') VALUES ('" . $_POST['UserName'] . "', '" . $_POST['FName'] . "','" . $_POST['LName'] . "','" . $_POST['Email'] . "','" . $_POST['Password'] . "')";

mysql_query($Query); 

mysql_close();

 header("Location: login.html");
?>

and here is the code that calls this page dynamically

<form id="frmSignUp" method="post" action="SignUp.php">
    <table class="Form" cellpadding="0" cellspacing="0" border="0" align="center" style="width: 300px;">
        <tr>
            <td>
                <span>First Name:</span>
            </td>
            <td>
                <input type="text" id="txtFName" name="txtFName" />
            </td>
        </tr>
        <tr>
            <td>
                <span>Last Name:</span>
            </td>
            <td>
                <input type="text" id="txtLName" name="txtLName" />
            </td>
        </tr>
        <tr>
            <td>
                <span>E-mail Address:</span>
            </td>
            <td>
                <input type="text" id="txtEmail" name="txtEmail" />
            </td>
        </tr>
        <tr>
            <td>
                <span>User Name:</span>
            </td>
            <td>
                <input type="text" id="txtUserName" name="txtUserName" />
            </td>
        </tr>
        <tr>
            <td>
                <span>Password:</span>
            </td>
            <td>
                <input type="password" id="txtPassword" name="txtPassword" />
            </td>
        </tr>
        <tr>
            <td>
                <span>Confirm Password:</span>
            </td>
            <td>
                <input type="password" id="txtConfirmPassword" name="txtConfirmPassword" />
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><span style="font-weight: normal;">Already have a login?</span>&nbsp;<a href="Login.html">Sign in</a>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <img alt="" src="images/spacer.gif" height="12px" border="0" />
            </td>
        </tr>
        <tr>
            <td>&nbsp;

            </td>
            <td>
                <input type="submit" value="Sign up" id="btnSignUp" name="btnSignUp" style="width: 100px;" />
            <!--onClick="btnSignUp_click();" --></td>
        </tr>
    </table>
    </form>

Just for the information, I am trying to run the PHP on IIS 7 on a Windows 7 machine.

2

3 Answers 3

4

Maybe it's a daft response, but have you tried changing < ?php to <?php ? It could be that the parser isn't parsing it because it's not valid syntax ... just a wild guess!

2
  • I am very very sorry for putting in such a poor post... That was a bad mistake really :$ Jul 9, 2011 at 8:40
  • no such thing as a stupid question ... that's the saying right? : )
    – sdolgy
    Jul 9, 2011 at 8:41
1

user remove space from "< ?php".

other than this all is fine with coding i think.

1

Try changing < ?php with <?php and see if that works.

If that doesn't, make sure that Apache knows to interpret php files in the directory of your file as php scripts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.