Results 1 to 7 of 7

Thread: Post Form data to Update MySQL get 500 Server Error

  1. #1
    Join Date
    Dec 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Post Form data to Update MySQL get 500 Server Error

    I am trying to put together a form that is populated from data in a MySQL. Then I want to allow the visitor to change information in that form and by pressing a button, update the database with the new information. This is going to be used by only about 700 people or less to update their member information and access to the form will be through an email that the member gets, so it doesn't have to be a bullet proof system. I found an example in this thread from 6 years ago posted by forum_amnesiac:

    http://www.dynamicdrive.com/forums/s...ith-MySQL-data

    I am giving the member a link that displays their member information (that part works) It is just when I attempt to send them to the last page that would do the update is where I get the 500 Server Error. Here is some of my code from the form for them to update. It populates the fields from the database and allows the member to edit the field :

    PHP Code:
    <form name="update" action="submitupdate.php" method="POST" />
            
            <input type="hidden" name="id" value="<?=$record['id']?>"
            <tr><b>Business Name: </b></br><input type="text" size="55" name="business_name" value="<?=$record['business_name']?>" ></tr></br></br>
    <tr><input type="submit" name="submit" value="update"  > </tr>
    Here is my submitupdate.php (That I get the 500 Server error on:

    PHP Code:
    <?php
    $con 
    =new mysqli('localhost'xxxxxx'xxxxxx','xxxxxx');
     
    mysqli_select_db($con"xxxxxx") or die(mysqli_error());


    $id $_POST['id'];
    $business_name $_POST['business_name'];
    $phone $_POST['phone'];
    $fax $_POST['fax'];
    $address1 $_POST['address1'];
    $address2 $_POST['address2'];
    $city $_POST['city'];
    $state $_POST['state'];
    $zip $_POST['zip'];
    $website $_POST['website'];
    $contact $_POST['contact'];
    $email $_POST['email'];


    if(isset(
    $_POST['id'])) {
        
    $UpdateQuery "UPDATE members SET business_name='$_POST[business_name]', phone='$_POST[phone]', fax='$_POST[fax]', address1='$_POST[address1]', address2='$_POST[address2]', city='$_POST[city]', state='$_POST[state]', zip='$_POST[zip]', website='$_POST[website]', contact='$_POST[contact]',  email='$_POST[email]', update_flag='$_POST[update_flag]',  WHERE id='$id'";
        
    mysqli_query($UpdateQuery$con);

    echo 
    "$UpdateQuery";exit();

    $sql "SELECT * FROM members WHERE id = $id";
    $my_Data mysqli_query($sql,$con);

    while(
    $record mysqli_fetch_array($my_Data)) {
    ?>

    </br> 

            <tr><b>Business Name: </b></br><input type="text" size="55" name="business_name" value="<?=$record['business_name']?>" ></tr></br></br>
            <tr><b>Phone: </b></br><input type="text" size="55" name="phone" value="<?=$record['phone']?>" > </tr></br></br>
    Just display the updated record here.
    Last edited by dnevels; 12-17-2015 at 04:15 AM. Reason: Updated to suggestions made by "james438"

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    First, you are using the deprecated mysql() queries as opposed to the current mysqli() queries. See this thread for more.

    Second, check your query before sending it to the database. For example insert

    Code:
    echo "$UpdateQuery";exit();
    just before

    Code:
    mysql_query($UpdateQuery, $con);
    Third, I do not see a place where $_POST['update'] has been set. It looks like other values have not been set either. echo "$UpdateQuery";exit(); should help expose the empty unpassed values.

    Last,

    Code:
    if ($retval )
    is always true

    There may be other errors, but those are the ones I saw at first glance.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Dec 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the suggestions james438! I updated the code above (hopefully correctly) to mysqli. added the "echo "$UpdateQuery";exit();" and got rid of the if ($retval ) since I always want it to show the updated record. However, I still have the same problem, I get the Server error 500! Did I do the conversion to mysqli wrong?

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Shouldn't there be apostrophes around each value too?;
    Code:
    $con =new mysqli('localhost', 'xxxxxx', 'xxxxxx', 'xxxxxx');
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    You may want to fix this too:

    Code:
    <tr><b>Business Name: </b></br><input type="text" size="55" name="business_name" value="<?=$record['business_name']?>" ></tr></br></br>
    The following is only to be used to test your code to look for empty values or unusual data. What exactly does the 500 server error say?
    echo "$UpdateQuery";exit();


    You may want to change your UPDATE to the following:
    Code:
    UPDATE members SET business_name='$business_name', phone='$phone', etc.
    but it is fine either way.

    The 500 server error generally means there is something else going on. In the past whenever I get a 500 server error as opposed to other errors it means I will be making a telephone call to my hosting service provider. It often meant my hosting service was updating the databases or I had a problem with some sort of infinite loop or was trying to get PCRE to process more than it reasonably should. You may even be having trouble with your .htaccess file.

    Try pruning your code down to as little as possible until the error no longer shows up so that you can pinpoint exactly what is causing the error to show up.
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    You may also wish to fix all the "</br>" tags. The correct format for the self-closing line break tag is "<br/>".

  7. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    You may also wish to fix all the "</br>" tags. The correct format for the self-closing line break tag is "<br/>".
    I have not heard of that. Just use <br>

    See http://dev.w3.org/html5/html-author/#the-br-element
    To choose the lesser of two evils is still to choose evil. My personal site

Similar Threads

  1. Simple form to update mysql
    By lmbarns in forum PHP
    Replies: 1
    Last Post: 07-26-2012, 12:44 PM
  2. auto get data from MS SQL server n insert into mysql database? Urgent
    By cstan in forum MySQL and other databases
    Replies: 3
    Last Post: 05-06-2009, 06:28 AM
  3. Form data to Pass as XML to a response server
    By profexcon in forum JavaScript
    Replies: 0
    Last Post: 02-23-2009, 06:52 PM
  4. Replies: 3
    Last Post: 01-08-2008, 12:49 PM
  5. Update form data without refreshing page
    By devil_vin in forum PHP
    Replies: 3
    Last Post: 09-21-2007, 05:16 PM

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
  •