500 internal server error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whitey
    New Member
    • Sep 2007
    • 17

    #1

    500 internal server error

    Hi all,

    The below code should be allowing me to modify entries which i choose from the script before hand, however it give the 500 error code.

    it generates ......



    where 1 is the record number (which exists)

    Im baffled. can anybody help me please?




    [code=php]
    <?php
    if ((!$_POST) || (isset($_GET["master_id"] !=" ")) {
    //haven't seen the form, so show it
    $display_block = "
    <form method=\"post\" action=\"".$_SE RVER["PHP_SELF"]."\">";

    if (isset($_GET["master_id"])) {
    //connect to database
    $mysqli = mysqli_connect( "localhost" , "web88-farmer", "whitep8", "web88-farmer");

    //get first, last names for display/tests validity
    $get_names_sql = "SELECT concat_ws('', f_name, l_name) AS display_name
    FROM master_name WHERE id = '".$_GET["master_id"]."'";
    $get_names_res = mysqli_query($m ysqli, $get_names_sql)
    or die(mysqli_erro r($mysqli));

    if (mysqli_num_row s($get_names_re s) == 1) {
    while ($name_info = mysqli_fetch_ar ray($get_names_ res)) {
    $display_name = stripslashes($n ame_info['display_name']);
    }
    }
    }

    if (isset($display _name)) {
    $display_block .= "<p>Adding information for
    <strong>$displa y_name</strong>:</p>";
    } else {
    $display_block .= "
    <p><strong>Firs t/Last Names:</strong><br/>
    <input type=\"text\" name=\"f_name\" size=\"30\" maxlength=\"75\ ">
    <input type=\"text\" name=\"l_name\" size=\"30\" maxlength=\"75\ ">";
    }
    $display_block .= "<p><strong>Add ress:</strong><br/>
    <input type=\"text\" name=\"address1 \" size=\"30\"></p>
    <input type=\"text\" name=\"address2 \" size=\"30\"></p>

    <p><strong>Ci ty/State/Zip:</strong><br/>
    <input type=\"text\" name=\"city\" size=\"30\" maxlength=\"50\ ">
    <input type=\"text\" name=\"county\" size=\"20\" maxlength=\"20\ ">
    <input type=\"text\" name=\"post_cod e\" size=\"10\" maxlength=\"10\ "></p>

    <p><strong>Addr ess Type:</strong><br/>
    <input type=\"radio\" name=\"add_type \" value=\"home\" checked> home
    <input type=\"radio\" name=\"add_type \" value=\"work\"> work
    <input type=\"radio\" name=\"add_type \" value=\"other\" > other</p>

    <p><strong>Tele phone Number:</strong><br/>
    <input type=\"text\" name=\"tel_numb er\" size=\"30\" maxlength=\"25\ ">
    <input type=\"radio\" name=\"tel_type \" value=\"home\" checked> home
    <input type=\"radio\" name=\"tel_type \" value=\"work\"> work
    <input type=\"radio\" name=\"tel_type \" value=\"other\" > other</p>

    <p><strong>Fa x Number:</strong><br/>
    <input type=\"text\" name=\"fax_numb er\" size=\"30\" maxlength=\"25\ ">
    <input type=\"radio\" name=\"fax_type \" value=\"home\" checked> home
    <input type=\"radio\" name=\"fax_type \" value=\"work\"> work
    <input type=\"radio\" name=\"fax_type \" value=\"other\" > other</p>

    <p><strong>Emai l Address:</strong><br/>
    <input type=\"text\" name=\"email\" size=\"30\" maxlength=\"150 \">
    <input type=\"radio\" name=\"email_ty pe\" value=\"home\" checked> home
    <input type=\"radio\" name=\"email_ty pe\" value=\"work\"> work
    <input type=\"radio\" name=\"email_ty pe\" value=\"other\" > other</p>

    <p><strong>Pers onal Note:</strong><br/>
    <textarea name=\"note\" cols=\"35\" rows=\"3\" wrap=\"virtual\ "></textarea></p>";

    if ($_GET) {
    $display_block .= "<input type=\"hidden\" name=\"master_i d\" value=\"".$_GET["master_id"]."\">";
    }

    $display_block .= "<p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>
    </form>";

    } else if ($_POST) {
    //time to add to tables, so check for required fields
    if ((($_POST["f_name"] == "") || ($_POST["l_name"] == "")) &&
    (!isset($_POST["master_id"]))) {
    header("Locatio n: addentry.php");
    exit;
    }

    //connect to database
    $mysqli = mysqli_connect( "localhost" , "web88-farmer", "whitep8", "web88-farmer");

    if (!$_POST["master_id"]) {
    //add to master_name table
    $add_master_sql = "INSERT INTO master_name (date_added, date_modified, f_name, l_name)
    VALUES (now(), now(), '".$_POST["f_name"]."', '".$_POST["l_name"]."')";
    $add_master_res = mysqli_query($m ysqli, $add_master_sql ) or die(mysqli_erro r($mysqli));

    //get master_id for use with other tables
    $master_id = mysqli_insert_i d($mysqli);
    } else {
    $master_id = $_POST["master_id"];
    }

    if (($_POST["address1"]) || ($_POST["address2"]) ||($_POST["city"]) || ($_POST["county"]) || ($_POST["post_code"])) {
    //something relevant, so add to address table
    $add_address_sq l = "INSERT INTO address (master_id, date_added, date_modified,
    address1, address2, city, county, post_code, type) VALUES ('".$master_id. "',
    now(), now(), '".$_POST["address1"]."', '".$_POST["address2"]."', '".$_POST["city"]."',
    '".$_POST["county"]."' , '".$_POST["post_code"]."' , '".$_POST["add_type"]."')";
    $add_address_re s = mysqli_query($m ysqli, $add_address_sq l) or die(mysqli_erro r($mysqli));
    }

    if ($_POST["tel_number "]) {
    //something relevant, so add to telephone table
    $add_tel_sql = "INSERT INTO telephone (master_id, date_added, date_modified,
    tel_number, type) VALUES ('".$master_id. "', now(), now(),
    '".$_POST["tel_number "]."', '".$_POST["tel_type"]."')";
    $add_tel_res = mysqli_query($m ysqli, $add_tel_sql) or die(mysqli_erro r($mysqli));
    }

    if ($_POST["fax_number "]) {
    //something relevant, so add to fax table
    $add_fax_sql = "INSERT INTO fax (master_id, date_added, date_modified,
    fax_number, type) VALUES ('".$master_id. "', now(), now(),
    '".$_POST["fax_number "]."', '".$_POST["fax_type"]."')";
    $add_fax_res = mysqli_query($m ysqli, $add_fax_sql) or die(mysqli_erro r($mysqli));
    }

    if ($_POST["email"]) {
    //something relevant, so add to email table
    $add_email_sql = "INSERT INTO email (master_id, date_added, date_modified,
    email, type) VALUES ('".$master_id. "', now(), now(),
    '".$_POST["email"]."', '".$_POST["email_type "]."')";
    $add_email_res = mysqli_query($m ysqli, $add_email_sql) or die(mysqli_erro r($mysqli));
    }

    if ($_POST["note"]) {
    //something relevant, so add to notes table
    $add_notes_sql = "UPDATE personal_notes set note = '".$_POST["note"]."' WHERE
    master_id = '".$master_id." '";
    $add_notes_res = mysqli_query($m ysqli, $add_notes_sql) or die(mysqli_erro r($mysqli));
    }
    mysqli_close($m ysqli);
    $display_block = "<p>Your entry has been added. Would you like to <a href=\"addentry .php\">add another</a>?</p>";
    }
    ?>
    <html>
    <head>
    <title>Add an Entry</title>
    </head>
    <body>
    <h1>Add an Entry</h1>
    <?php echo $display_block; ?>
    </body>
    </html>
    [/code]
    Last edited by Atli; Nov 16 '07, 12:15 AM. Reason: Changed [code] tags to [code=php].
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    You should use PHP CODE tags instead of CODE. This helps others to read the source code easily.

    Turn On PHP Debugging Messages.

    What are you trying to do in this line?
    [PHP]if ((!$_POST) || (isset($_GET["master_id"] !=" ")) {[/PHP]

    See how isset() works.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Whitey.

      500 errors are usually caused by permissions issues or an error in a .htaccess file.

      Make sure all your scripts have execute permissions, and check the ownership. The files should be owned and/or in the same group as the web server (usually 'www' or 'apache').

      If you are using .htaccess files, verify that there are no errors or typos.

      Comment

      Working...