Find text in database and insert results in same database

Discussion in 'PHP' started by paul174, Feb 7, 2015.

  1. #1
    hello friends , here the code i did,
    the output is like http://www.domain.com/rai/2037/play.php
    and i want to insert this url and overwrite any existing value
    <?php
    $servername = "localhost";
    $username = "root";
    $password = "root";
    $dbname = "tube";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    $sql = "SELECT video FROM videos WHERE video LIKE '%rai%'";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
         
            preg_match('/(http:\/\/www.domain.com\/rai\/)(.*play.php)/', $row["video"], $link);
            if (empty($link[0])) {
        echo "Nothing found!";
    } else {
        echo $link[0];
    }
        }
    }
    $conn->close();
    ?>
    PHP:
    here i want to replace $row["video"] value with $link[0]

    thanks for any help
     
    paul174, Feb 7, 2015 IP
  2. ralphnsk

    ralphnsk Member

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    } else {
        echo $link[0];
        $conn->query('UPDATE videos SET video ="'.$link[0].'" WHERE video ="'.$row['video'].'"');
    }
    PHP:
     
    ralphnsk, Feb 13, 2015 IP