The following code is a simple example of api Messages output registered in the database, but the information is not recorded where is the problem from?


  • | 2360 points

    The following code is a simple example of api
    Messages output registered in the database, but the information is not recorded
    where is the problem from?

    file api.php
    <?php

    include 'db_config.php';
    /(start) random string with length 4/
    $length = 4;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';
    for ($p = 0; $p < $length; $p++) {
    $string .= $characters[mt_rand(0, strlen($characters))];
    }
    /(end) random string with length 4/

    /check url/
    if(@$_GET['url']) {
    $url = $_GET['url'];
    $mm = array();
    $mm = (explode('/', $url));
    foreach ($mm as $nn) {
    $path = $nn;
    }
    $time2 = date('H:i:s');
    $date2 = date('Y M d');

    // start code(insert to database)
    $sql=' SELECT * FROM short WHERE fullurl=:url1 ';
    $rr=$link->prepare($sql);
    $rr->bindParam( ':url1', $path);
    $rr->execute();
    $num = $rr->rowCount();
    if($num == 0)
    {
        $sql=' INSERT INTO short (fullurl,stime,sdate,scode) VALUES (:url1,:time1,:date1,:code1)';
        $rr=$link->prepare($sql);
        $rr-> bindParam(':url1', $path);
        $rr-> bindParam(':time1', $time2);
        $rr-> bindParam(':date1', $date2);
        $rr-> bindparam(':code1', $string);
        $rr-> execute();
        echo "URL was added in the database";
    }
    else{
        echo "Not be added. Such addresses in the database is available";
    }
    // end code(insert to database)
    

    }


  • administrators
    | 68677 points

    @sajjadkazemi10 : It is not related to Laragon and stackoverflow is a better place to post this issue. However, I want to share with you something:

    1. To find out the problem, you must check or provide the error messages.
    2. When posting, please format the post nicely and carefully. It will become a habit to help you make less bugs.

Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.