Jump to content
Ronel

PHP update

Recommended Posts

<?php
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect("localhost","root", "","update");

//
//   PROCESS POSTED DATA
//
        if ($_SERVER['REQUEST_METHOD']=='POST') {
            $stmt = $conn->prepare("UPDATE ronel
                                    SET status = ?,
                                        comment = ?,
                                        department = ?
                                    WHERE id = ?
                                    ");
            $stmt->bind_param('ssi', $_POST['status'], $_POST['comment'], $_POST['department'], $_POST['id']);
            $stmt->execute();
            
            header("Location: ronel_dashboard.php");
            exit;
        }


if (!isset($_GET['id']) || trim($_GET['id'])=='') {
    header("Location: ");
    exit;
}

$res = $conn->prepare("SELECT id
                            
                            , location
                            
                            , status
                            , comment
                            , department
                       FROM ronel
                       WHERE id = ?
                       ");
$res->bind_param('i', $_GET['id']);
$res->execute();
$res->bind_result($id, $location, $status, $comment, $department);
$res->fetch();
$res->close();

//
//  status-dependent processing
//
$buttons = "<div class='data'>
            <button name='status' class='w3-button w3-khaki' value='$status'>Update</button> 
            </div>
            ";

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-language" content="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Details</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<style type='text/css'>
    body  { font-family: calibri, sans; font-size: 12pt; }
    label { display: inline-block; width: 150px; background-color:#E4EBC5; color:orangered; padding: 8px; font-weight: 600; margin-right:30px; vertical-align: top;}
    .data { display: inline-block; width: 500px; padding: 8px; vertical-align: top;}
    /*.comment { display: inline-block; width: 450px; vertical-align: top;}  */
</style>
</head>
<body>
<header class="w3-display-container w3-orange w3-padding" style='height:90px;'>
    <div class="w3-left">
        <h2>Details</h2>
    </div>
    <div class="w3-right w3-margin">
        <a href='ronel_dashboard.php' class='w3-khaki w3-button'>Dashboard</a>
    </div>
</header>
<div class='w3-container'> 
    <form method='POST'>
    
    <input type='hidden' name='id' value='<?=$id?>'>
    <div class="w3-card w3-padding" style='max-width: 750px; margin: 30px auto;'>
        <div>
            <label>ID</label>
            <div class="data"><?=$_GET['id']?></div>
        </div>
        
        <div>
            <label>Location</label>
            <div class="data"><?=$location?></div>
        </div>
        
        <div>
            <label>Status</label>
            <div><?=$status?></div>
        </div>
        <div>
            <label>Comments</label>
            <div class="data"><textarea name='comment' class='w3-input w3-border' rows='5'><?=$comment?></textarea></div>
        </div>
        <div><label for="cars">Select Department:</label>
<div class="data">
<select id="department">
  <option value="volvo">MMD</option>
  <option value="saab">O&M</option>
  <option value="opel">Civil</option>
  <option value="audi">C&M</option>
</select>
</div>  
</div>
    </div>
    <div class='w3-content w3-center w3-padding'>
        <?=$buttons?>
    </div>
    </form>
</div>
</body>
</html>

Dear Sir/Madame

Can someone help me with this piece of code? I have tried updating a comment section with approve and reject status button here and Sir Barand has helped me a lot with the project code which he provided me!! Now after the approval/reject part done  what i am trying to do is update a department section with the comment section as well and instead of approve/reject button i want to update only with a different page. 

Share this post


Link to post
Share on other sites

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in /opt/lampp/htdocs/new1/ronel_detail.php on line 15

Fatal error: Uncaught mysqli_sql_exception: No data supplied for parameters in prepared statement in /opt/lampp/htdocs/new1/ronel_detail.php:16 Stack trace: #0 /opt/lampp/htdocs/new1/ronel_detail.php(16): mysqli_stmt->execute() #1 {main} thrown in /opt/lampp/htdocs/new1/ronel_detail.php on line 16

 

This is the error it gave me!

Share this post


Link to post
Share on other sites

And?  It says that you don't have matching arguments and parameters.  That means you have x number of defined parms in your query statement and y number of arguments (variables) bound to those.   Fix that and try again.  Could be the ssi string is short one character?

AND upon a re-read of the message it is definitely the "ssi" string.  The number of these parms must match the number of arguments you are supplying.

Edited by ginerjm
  • Like 1

Share this post


Link to post
Share on other sites

First query, as ginerjm pointed out:

 

SET status = ?,
                                        comment = ?,
                                        department = ?
                                    WHERE id = ?

Four '?' , but your bind string is 'ssi'  ;)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.