www.webdeveloper.com
Results 1 to 4 of 4

Thread: update DB get success but no change at MySQL

  1. #1
    Join Date
    May 2014
    Posts
    1

    update DB get success but no change at MySQL

    i have try more and more to update database
    and each time i get data update success but no change at database ?!!

    PHP Code:
    <script type="text/javascript">
            $(
    document).ready(function(){
                $(
    '.submit-green').live('click',function(){
                    
    name = $('#name').val();
                    
    collage = $('#collage').val();
                    
    certificate = $('#certificate').val();
                    
    details = $('#details').val();
                    
    id = $('#id').val();
                    
                    if (!
    name) {
                        $(
    '.name_error').html('من فضلك أدخل الاسم').css('color''red');
                    } else {
                        $(
    '.name_error').html('');
                    }
                    
                    if (!
    collage) {
                        $(
    '.collage_error').html('من فضلك أدخل الاسم').css('color''red');
                    } else {
                        $(
    '.collage_error').html('');
                    }
                    
                    if (!
    certificate) {
                        $(
    '.certificate_error').html('من فضلك أدخل الاسم').css('color''red');
                    } else {
                        $(
    '.certificate_error').html('');
                    }

                    if (!
    details) {
                        $(
    '.details_error').html('من فضلك أدخل التفاصيل').css('color''red');
                    } else {
                        $(
    '.details_error').html('');
                    }
                    
                    if (
    name && collage && certificate && details) {
                        $(
    '.name_error').html('');
                        $(
    '.collage_error').html('');
                        $(
    '.certificate_error').html('');
                        $(
    '.details_error').html('');
                        $.
    post('system/edit_about.php',{namenamecollagecollagecertificatecertificatedetailsdetailsid:id}, function(data) {
                            if(
    data == 0){
                                $(
    '.result').html('Error updating data').css('color''red');
                            }else{
                                $(
    '.result').html('Data updated successfully').css('color''green').fadeOut(3000,function(){
                                    
    window.location 'about.php';
                                });

                            }

                        });
                    }
                });
            });
        
    </script> 

    PHP Code:
    <div class="module-body">
                                <p>
                                    <label>الإسم</label>
                                    <input type="text" class="input-medium" name="name" id="name" value="<? echo $row['name'?>">
                                <div class="name_error"></div><br/>
                                <p>
                                    <label>الكلية</label>
                                    <input type="text" class="input-medium" name="collage" id="collage" value="<? echo $row['collage'?>">
                                <div class="collage_error"></div><br/>
                                <p>
                                    <label>الشهادات</label>
                                    <input type="text" class="input-medium" name="certificate" id="certificate" value="<? echo $row['certificate'?>">
                                <div class="certificate_error"></div><br/>
                                <p>
                                    <label>تفاصيل</label>
                                    <input type="text" class="input-medium" name="details" id="details" value="<? echo $row['details'?>">
                                <div class="details_error"></div><br/>

                                <p>
                                    <input type="hidden" value="<?= $row['id']?>" id="id"/>
                                    <input type="submit" value="Edit" class="submit-green">
                                    <input type="button" value="Cancel" class="submit-gray" onclick="javascript:self.location='admin.php';" />
                                </p>
                                <p class="result"></p>
                            </div>
    PHP Code:
    include 'config.php';
    $name $_POST['name'];
    $collage $_POST['collage'];
    $certificate $_POST['certificate'];
    $details $_POST['details'];
    $id $_POST['id'];

    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET CHARACTER SET utf8'); 

    $sql "UPDATE about SET name='$name',collage='$collage',certificate='$certificate',details='$details',WHERE id='$id'";
    $query mysql_query($sql);
        echo 
    1

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    660
    What makes you think this ran successfully? You aren't monitoring php errors. You are most definitely not validating your input nor sanitizing it to avoid tampering. AND you don't even check the results of the query to determine what happened.

    Did you even open a connection to the database?

  3. #3
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    PHP Code:
    $query mysql_query($sql);
        echo 
    1
    Is better written as
    PHP Code:
    if ($result = (mysql_query($sql)) !== false)
        echo 
    1

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,239
    So let's take all that advice, clean things up a bit, and try to find out if things will work at all, or if we can at least find out what the problem is:
    PHP Code:
    <?php
    include 'config.php';

    $name        mysql_real_escape_string($_POST['name']);
    $collage     mysql_real_escape_string($_POST['collage']);
    $certificate mysql_real_escape_string($_POST['certificate']);
    $details     mysql_real_escape_string($_POST['details']);
    $id          mysql_real_escape_string($_POST['id']);

    mysql_query("SET NAMES 'utf8'");
    mysql_query('SET CHARACTER SET utf8'); 

    $sql "UPDATE about SET name='$name',collage='$collage',certificate='$certificate',details='$details',WHERE id='$id'";
    if(
    mysql_query($sql) == false) {
        throw new 
    Exception("Query failed:".PHP_EOL.mysql_error().PHP_EOL.$sql);
    }
    echo 
    "Updated ".mysql_affected_rows()." rows.";
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles