kankai's avatar

mysql_fetch_array undefined function

Previously i had build a code redeem website with php old version, but then i upgraded php version to 7. After that i found mysql fetch array function has been removed. What should i need to change in my code?

$sql = "SELECT * FROM code_redeem WHERE redeemCode='$promoCode'";
$result = mysqli_query($connection,$sql)or die('error getting data');
            $num_rows = mysqli_num_rows($result);
            if ($result->num_rows == 1) {
                while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
                    if($num_rows==1){
                        if($row['used']==1){
                            echo "<script type='text/javascript'>alert('Code has been used');</script>";
                        }else{
                            $sql = "UPDATE code_redeem SET used='1', user= '$userName', contactNo= '$contactNo',email= '$email', browserName= '$browserName', browser= '$browser', location= '$location', regDate= '$regdate', device= '$device' WHERE redeemCode='$promoCode'";
                            if ($connection->query($sql) === TRUE) {
                                //echo "Record updated successfully";
                            } else {
                                //echo "Error updating record: " . $connection->error;
                            }
                            require_once ('run/start.php');
                            return;
                        }
                    }
                }
            }
0 likes
4 replies
kankai's avatar

if i change it to mysqli_fetch_array, it will be given this error message. mysqli_fetch_array() expects parameter 2 to be integer, string given

arukomp's avatar
arukomp
Best Answer
Level 10

then change the MYSQL_ASSOC to MYSQLI_ASSOC

1 like

Please or to participate in this conversation.