1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Update query

Discussion in 'MySQL' started by Michael Bednarski, Mar 28, 2020.

  1. #1
    Hi I have been fighting for hours now and cant seem to work out what the issue is. I want to do a simple update query I have stripped it down to is bare minimum to try and get it to work but still no joy. If I was to run the update query directly in phpmyadmin then it works straight away but when i try to run it via php script it does not work. I get a message saying connection to my database is successful but that's about it. I have changed all the privilege settings to allow everything for the specific user but still nothing happens. the MySQL server is on a Godaddy server. The strange thing is I am able to insert new members into the database and also do select query fine. I have attached the code I am using below:

    <?php
    
    //Our connection details.
    $servername = 'localhost';
    $username = '*********';
    $password = '**********';
    $dbname = 'members';
    
    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    
    // Check connection
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }
    echo "Connected successfully";
    
    
    
    $sql = "UPDATE members SET verified_account=1 WHERE member_id=1";
    
    
    ?>
    Code (markup):
    If anyone is able to help it would be amazing
     
    Last edited by a moderator: Mar 28, 2020
    Michael Bednarski, Mar 28, 2020 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Your sql looks fine but have you edited out where you actually use it or is that the missing step?
     
    sarahk, Mar 28, 2020 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #3
    Add this after your sql
    
    if ($conn->query($sql) === TRUE) {
    echo"Record updated successfully";
    } else {
    echo"Error updating record: " . $conn->error;
    }
    
    Code (markup):
    It may throw the error.
     
    qwikad.com, Mar 28, 2020 IP