PHP white screen of death every time. What am I doing wrong?

前端 未结 5 455
傲寒
傲寒 2021-01-26 08:44

I\'m a complete noob to PHP and working with mysql so you know I do however have a great deal of experience with HMTL and CSS. All I need is for a form on my site to upload the

5条回答
  •  既然无缘
    2021-01-26 09:34

    Include this two lines at the very top of your php code:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    It is going to enable error reporting and so you will be able to debug your script. Maybe the problem is that the reading of $_POST variables (and of any array type variable) should be made with 'quotes' when using string index names:

     $_POST[firstName] must be written as follows:
     $_POST['firstName']
    

    A good way of making this query more secure (against sql injection attacks for example) is to scape the values in POST instead of passing it directly to the query.

     $firstName = mysql_real_escape_string($_POST['firstName']);
    

    The value in POST will be scaped so you can pass it to your SQL.

    Try to make that will all your variables:

    $sql = "INSERT INTO $usertable 
    (firstName, lastName, streetAddress, city, state, zip, country, email, phone, badgeName) 
    VALUES ('$firstName', '$lastName', '$streetAddress', '$city', '$state', '$zip', '$country', '$email', '$phone', '$badgeName')";
    

    Finally you need to actually execute the query:

    mysql_query($sql);
    

    If it goes ok you'll see no errors, but be shure to enable error reporting to this script. When everything it's ok remember to remove the error reporting.

提交回复
热议问题