0

I'm trying to update entries in my DB Table but I keep getting the following error message:

Warning: mysqli_errno() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Bugtracker\UpdateBugReport.php on line 43

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\Bugtracker\UpdateBugReport.php on line 43

My code is:

<!DOCTYPE html>

    <head>
    
        <title>Update a Bug Report</title>
        <meta charset="utf-8" />
        
    </head>
    
        <body>
        
            <h1>Update Bug Report</h1>
            
                <?php

                    echo "------CALL TO UPDATEBUGREPORT.PHP---------<br /> \n";
                    $ShowForm=FALSE;
                    echo "DEBUG PRINT 11: ShowForm: FALSE <br /> \n";
                    $fields = array('product', 'version', 'hardware', 'os', 'frequency', 'solutions');
                    $report=array();
                    foreach ($fields as $field)
                        $report[$field]="";
                    
                    // if report_id field has been set from calling form    
                    if (isset($_POST['report_id'])) {
                    
                        $report_id=$_POST['report_id'];
                    
                    }
                    
                    else if (isset($_GET['report_id'])) {
                    
                        $report_id=$_GET['report_id'];
                    
                    }
                    
                    if (isset($report_id)) {
                        
                        echo "DEBUG PRINT 26 : report_id set : $report_id <br /> \n";
                        $DBConnection = mysqli_connect("...", "...", "...");
                        if (!$DBConnection === FALSE) 
                            echo "<p>Unable to connection to the database server.</p>\n" . 
                            "<p>error code " . mysqli_errno() . ": " . mysqli_error() . "</p> \n";
                        
                    // db selection successful  
                    else {
                        
                        $DBName = "r00054908_bugreports";
                        $TableName = "bugtracker";
                        
                        if (!mysqli_select_db($DDConnection,$DBName))
                            echo "<p>Unable to connect to the $DBName database!</p>";
                            
                        else {
                        
                            $SQLString="SELECT * FROM $TableName WHERE report_id='" .
                            stripslashes($report_id) . "'";
                        
                        $QueryResult = mysqli_query($DBConnection,$SQLString);
                        
                        if (!$QueryResult === FALSE) 
                            
                            echo "<p>There was an error retrieving the record.<br />\n" .
                                    "The error was " .
                                    htmlentities(mysqli_error($DBConnection)) .
                                    ".<br />\nThe query was '" .
                                    htmlentities($SQLString) .
                                    "'</p>\n";
                            
                            else if (mysqli_num_rows($QueryResult)==0) {
                            
                            echo "<p>" . stripslashes($report_id) . " is an invalid id</p>\n";
                            
                            }
                            
                    else {
                        
                        $report=mysqli_fetch_assoc($QueryResult);
                        echo "DEBUG PRINT: Fetched record <br /> \n";
                        if (isset($_POST['submit'])) {
                        
                            echo "DEBUG PRINT 60: Form submitted with UPDATE data. <br /> \n";
                            // validate form fields
                            foreach ($fields as $field) {
                            
                                if ((!isset($_POST[$field])) || strlen(trim(($_POST[$field]))==0)) {
                                
                                echo "<p>'$field' is a required field.</p>\n";
                                $ShowForm=TRUE;
                                echo "DEBUG PRINT: ShowForm: TRUE <br /> \n";
                                
                                }
                            
                                    else {
                                        
                                        $report[$field]=stripslashes(trim($_POST[$field]));
                                
                                    }
                            
                            }
                    
                    // update db with new data
                    if ($ShowForm===FALSE) {
                        
                        echo "DEBUG PRINT : ShowForm: FALSE<br /> \n";
                        $connector="";
                        //build update sql string
                        $SQLString = "UPDATE $TableName SET ";
                        foreach ($field as $fields) {
                            $SQLString .= $connector . $field . "='" . $report[$field] . "'";
                            $connector=", ";
                        }
                        
                        $SQLString .= "WHERE report_id = '" .$report_id. "'";
                        echo "DEBUG PRINT 87: UPDATE SQL: $SQLString <br /> \n";
                        $QueryResult = mysqli_query($DBConnection,$SQLString);
                        if ($QueryResult === FALSE) 
                            echo "<p>There was an error saving the record. <br />\n" . 
                                "The error was " .
                                htmlentities(mysqli_error($DBConnection)) .
                                ".<br />\nThe query was '" .
                                htmlentities($SQLString) . 
                                "'</p>\n";
                    
                        
                        
                        else {
                        
                            echo "<p>The bug report was saved.</p>\n";
                        
                        }
                    }
                        else {
                
                                $ShowForm=TRUE;
                                echo "DEBUG PRINT 104 : ShowForm: TRUE <br />\n";
                
                            }
                    }
        
            }
        } 
    }
    }

                    
                    else {
                        
                        echo "<p>You must select a report to update.</p>\n";
                        $ShowForm=FALSE;    
                        echo "DEBUG PRINT 114: ShowForm: FALSE <br /> \n";
                    
                    }
                    
                    if ($ShowForm===TRUE) {
                    
                    ?>          
            
                    <form action='UpdateBugReport.php' method='POST'>

                        <table>
                
                            <tr><td align='right'>Report ID</td><td align='left'> <?php echo $report['$report_id']; ?>
                                <input type='hidden' name='report_id' value='<?php echo $report['report_id']; ?>' />
                            </td></tr>
                            <tr><td align='right'>Product</td><td align='left'>
                                <input type='text' size='80' name='product' value='<?php echo $report['product']; ?>' />
                            </td></tr>
                            <tr><td align='right'>Version</td><td align='left'>
                                <input type='text' size='80' name='version' value='<?php echo $report['version']; ?>' />
                            </td></tr>
                            <tr><td align='right'>Type of Hardware</td><td align='left'>
                                <input type='text' size='80' name='hardware' value='<?php echo $report['hardware']; ?>' />
                            </td></tr>
                            <tr><td align='right'>Operating System</td><td align='left'>
                                <input type='text' size='80' name='os' value='<?php echo $report['os']; ?>' />
                            </td></tr>
                            <tr><td align='right'>Frequency of Occurrence</td><td align='left'>
                                <input type='text' size='80' name='frequency' value='<?php echo $report['frequency']; ?>' />
                            </td></tr>
                            <tr><td align='center' colspan='2'>Please either enter both the count and period, as in 20 times a month, 
                                    or a descriptive term, like 'often', 'rarely', or 'always'.</td></tr>   
                            <tr><td align='right'>Proposed Solutions</td><td align='left'>
                                <textarea cols='80' rows='6' name='solutions'><?php echo $report['solutions']; ?></textarea>
                            </td></tr>
                    
                            <tr><td align='center' colspan='2'>
                                <input type='reset' name='reset' value='Clear Form' /> &nbsp;
                                <input type='submit' name='submit' value='Save Report' />
                            </td></tr>
                    
                        </table>
                
                <?php
                }
                ?>
                
                <a href="ViewBugReport.php">View Bug Reports</a>

        </body>

</html>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Jaywin
  • 65
  • 3

1 Answers1

0

mysqli_errno and mysqli_error are not used for connections errors, therefore replace

$DBConnection = mysqli_connect("157.190.186.37", "R00054908", "R00054908");
if (!$DBConnection === FALSE) 
    echo "<p>Unable to connection to the database server.</p>\n" . 
    "<p>error code " . mysqli_errno() . ": " . mysqli_error() . "</p> \n";

by

$DBConnection = mysqli_connect("...", "...", "...");
if (mysqli_connect_error()) {
    echo "<p>Unable to connect to the database server.</p>\n" . 
    "<p>error code " . mysqli_connect_errno() . ": " . mysqli_connect_error() . "</p> \n";
    die;
}

and try again. it won't fix the problem with the database connection but at least it should show you what actually went wrong....

see: http://docs.php.net/mysqli.construct

edit: What is the line if (!$DBConnection === FALSE) supposed to do anyway? Cast $DBConnection to boolean than negate it and then test "is FALSE"? That doesn't make sense and probably tests the exact opposite of what you want it to test there.

VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • Done, and sorry again :D – Ares Draguna Oct 31 '14 at 15:29
  • and about that if... seamed strange to me too... like `if $DBConnection` is false then `if not $DBConnection === FALSE` or viceversa... this will never be true, or? – Ares Draguna Oct 31 '14 at 15:30
  • I guess it's true when the connection could be established. A cast resource->boolean evaluates to true, negate that and the test ===FALSE is true -> exact opposite of what should be tested there. – VolkerK Oct 31 '14 at 15:31
  • It's like scratching your head backwards and still have an itch... completely useless in my opinion... – Ares Draguna Oct 31 '14 at 15:32