Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • I want to convert the query php code into the Prepare statement php code

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.04k
    Answer it

    Here is my query code, How can write same code in the prepare statement php.

        <?php
    
       header('Content-type : bitmap; charset=utf-8');
    
       if($&#95;SERVER['REQUEST&#95;METHOD']=='POST'){
    
    $encoded&#95;string = $&#95;POST['image'];
    $name = $&#95;POST['name'];
    require&#95;once('dbconnect.php');
    
    
    $sql ="SELECT id FROM images ORDER BY id ASC";
    
    $res = mysqli&#95;query($con,$sql);
    
    $id = 0;
    
        while($row = mysqli&#95;fetch&#95;array($res)){
                $id = $row['id'];
        }
    
        $path = "uploadedimages/$id.jpg";
    
        $actualpath = "http://plantnow.net16.net/$path";
    
    
    $query = "INSERT INTO images(image, name) values ('$actualpath','$name')";
    
    
    
    if(mysqli&#95;query($con,$query)){
            file&#95;put&#95;contents($path,base64&#95;decode($encoded&#95;string));
            echo "Successfully Uploaded";
        }
    
        mysqli&#95;close($con);
    
    
    }
    
    else{
        echo "Error";
    }
    
     ?>
    

 1 Answer(s)

  • Welcome to Findnerd. You can simply bind the different parameters like this.

        $stmt = $con->prepare("INSERT INTO images (image, name) VALUES (?, ?)");
        $stmt->bind_param("ss", $actualpath,$name);
    

    Regards Deepak

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: