简体   繁体   中英

why my php code does'nt work on wamp server

I have the following PHP code, but it doesn'nt seem to execute on my WAMP server. It just returns the .php pages as raw text. Am I missing some obvious syntax or configuration?.

    <?php
    $uname =$_POST["uname"];
    $email =$_POST["email"];
    $pw =$_POST["password"];
    $pw2 =$_POST["repassword"];
    $cno =$_POST["cnumber"];
    $add =$_POST["add"];

    $con=mysql_connect("localhost","root","");
    mysql_select_db("rcj company",$con);

    mysql_query("INSRET INTO customer(username, email, password, cnumber, address)VALUES('".$uname."', '".$email."', '".$pw."', '".$pw2."', '".$cno."', '".$add."')");
    mysql_close($con);

    ?>

Reinstall your Wamp server and then check it,

And also fix the bugs what you did in your query,

For example change INSRET to INSERT .

You must actually access it from the server, ie. with a URL like http://localhost/test.php , otherwise you're just asking the browser to get the file from your hard drive!

Also, INSRET isn't going to work, and of course obligatory xkcd reference:

xkcd

Sanitise your inputs before it is too late! — Or better still, use PDO , I actually just started using it yesterday - not because I'm incapable of writing valid MySQL queries the "raw" way, but because it's actually really tidy.

Also also, always enclose your table and column names in `backticks` ! Otherwise you're relying on the same behaviour as what makes $foo = bar; a "valid" way to define a string, namely "if it's not a constant or other keyword, it must be [a string / an identifier]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM