0

I'm making a technical evaluation system for the company I worked. when I uploaded it to online host there's some error "Array string conversion".

Notice: Array to string conversion in /storage/ssd5/805/10576805/public_html/UI/data.php on line 4 Notice: Undefined property: UserData::$Array in /storage/ssd5/805/10576805/public_html/UI/data.php on line 4 Fatal error: Uncaught Error: Function name must be a string in /storage/ssd5/805/10576805/public_html/UI/data.php:4 Stack trace: #0 {main} thrown in /storage/ssd5/805/10576805/public_html/UI/data.php on line 4

I tried to run the program in PHP5 down to an older version of PHP it is worked. But in PHP7 to newest version doesn't work. I think there is the new syntax for array conversion of PHP7. can you help me please to fix this problem? Thanks a lot.

Data.php

<?php
$process = new UserData();

if(isset($_GET['q'])){

    $process->$_GET['q'](); //this line have an error

}

class UserData {

    function deletePending(){
        require '../config.php';

        $trans_no = $_GET['trans_no'];
        $q = $connection->query("delete from tevaluation where TRANS_NO='$trans_no'");

        return $q;
    }

}
?>

View.php

<html>
<head>
<title>
 Technical Evaluation
</title>
</head>
<body>
<?php
include 'data.php';
$data = $process->pendingEvaluation();
?>
<table class="table table-hover" id="itemList">
<thead class="bg-primary">
<tr>
    <th class="text-center" width="35">TE #</th>
    <th class="text-center" width="10">QUANTITY</th>
    <th class="text-center" width="10">UNIT</th>
    <th class="text-center" width="20">DESCRIPTION</th>
    <th class="text-center" width="20">DEPARTMENT</th>
    <th class="text-center" width="130">DATE EVALUATED</th>
    <th class="text-center" width="50">STATUS</th>
    <th class="text-center">ACTION</th> 
</tr>
</thead>
<tbody>
    <?php if($data->num_rows > 0): ?>
        <?php while($row = mysqli_fetch_array($data)): ?>
        <?php if($row['STATUS'] == 2): 
        $stat = "<p class='text-danger'><b> For Approval</b></p>";
                    ?>
 <tr>
<td class="text-center" width="15"><?php echo $row['TRANS_NO']; ?></td>
<td class="text-center" width="10"><?php echo $row['QTY']; ?></td>
<td class="text-center" width="10"><?php echo $row['UNIT']; ?></td>
<td class="text-center" width="40"><?php echo $row['DESCRIP']; ?></td>
<td class="text-center" width="20"><?php echo $row['DEPT']; ?></td>
<td class="text-center" width="130"><?php echo $row['E_DATE']; ?></td>
<td class="text-center" width="50"><?php echo $stat; ?></td>
<td>

<a href="data.php?q=deletePending&trans_no=<?php echo $row['TRANS_NO']; ?>" class="btn btn-danger btn-sm" title="Click to Delete">
                                    <span class="fa fa-trash"></span><b> Delete</b>
                                </a>
</td>
</tr>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</tbody>
</table>
</body>
</html>
Phil
  • 157,677
  • 23
  • 242
  • 245
Romz_24
  • 11
  • 4
  • Can you post your error message? – Serghei Leonenco Aug 23 '19 at 04:37
  • Notice: Array to string conversion in /storage/ssd5/805/10576805/public_html/UI/data.php on line 4 Notice: Undefined property: UserData::$Array in /storage/ssd5/805/10576805/public_html/UI/data.php on line 4 Fatal error: Uncaught Error: Function name must be a string in /storage/ssd5/805/10576805/public_html/UI/data.php:4 Stack trace: #0 {main} thrown in /storage/ssd5/805/10576805/public_html/UI/data.php on line 4 – Romz_24 Aug 23 '19 at 05:11
  • try to assign your `$_GET['q']` to a value like `$function = $_GET['q']`, and do this `$process->function();` and try again. – Serghei Leonenco Aug 23 '19 at 05:16
  • 1
    And please add the error in a formatted version to the question instead of in a comment. – Markus Deibel Aug 23 '19 at 05:23
  • @SergheiLeonenco . thank you so much for your help but it wasn't worked. here is the error after i tested as what your comment. "Fatal error: Uncaught Error: Call to undefined method UserData::function() in /storage/ssd5/805/10576805/public_html/UI/data.php:5 Stack trace: #0 {main} thrown in /storage/ssd5/805/10576805/public_html/UI/data.php on line 5" – Romz_24 Aug 23 '19 at 05:40
  • @Romz_24 What you get in `GET` and what function are trying to call in `UserData()`? – Serghei Leonenco Aug 23 '19 at 05:42
  • @Romz_24 Ok, So you trying to delete pending data using `GET['q']` parameter? if so you have to call `$process->deletePending()` then. – Serghei Leonenco Aug 23 '19 at 05:48
  • @SergheiLeonenco. i'm using string query in the url like "data.php?q=deleteItem&trans_no=17" and UserData get the string "q" value and looking inside the class function if deleteItem is exist like "function deleteItem(){}". – Romz_24 Aug 23 '19 at 05:54
  • @Romz_24 This question marked as duplicate and it does have an answer already. Take a look. It will help you – Serghei Leonenco Aug 23 '19 at 05:56
  • thank you guys for helping me. my program is now finally fixed. – Romz_24 Aug 23 '19 at 06:09

0 Answers0