0

how are you? I've been doing some code using "old commands" (or thats what i found) of php version 5. Yesterday i tried to run my program using php version 7 and i was given this alert (this alert does not appear when using php 5): Issue

Fatal error: Uncaught Error: Call to undefined function mysql_connect()

MAMP was running at version 5 (everything was right) but i gotta use the version 7!. Can help me to make my code runs using version 7?. Take a look (index.php)

<?php include('connect.php'); ?>
<html>
    <head>
        <script src="http://c...content-available-to-author-only...y.com/jquery-latest.min.js" type="text/javascript"></script>
    </head>
    <body>
        <a href="student.php">ADD NEW STUDENT</a><br/><br/>
        <h2 align="center">Chart</h2>
        <input id="search" type="text">
        <table align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="table">
            <thead>
                <th>id</th>
                <th>Subject</th>
                <th>Name</th>
                <th>Description</th>
                <th>Hours</th>
                <th>Action</th>
            </thead>
            <?php
            $sql = mysql_query("SELECT * FROM materias");
            $i = 1;
            while ($row = mysql_fetch_array($sql)) {
                echo "<tr>
                        <td>" . $i . "</td>
                        <td>" . $row['subject_id'] . "</td>
                        <td>" . $row['name'] . "</td>
                        <td>" . $row['description'] . "</td>
                        <td>" . $row['hours'] . "</td>
                        <td align='center'>
                            <a href='editar.php?editar=1&iden=" . $row['id'] . "'>UPDATE</a> |
                            <a href='borrar.php?borrar=1&iden=" . $row['id'] . "'>DELETE</a>
                        </td>
                     </tr>";
                $i++;
            }
            ?>
        </table>
    </body>
</html>

And the other file is connect.php (check the connection with the database)

<?php

$con=mysql_connect('localhost','root','root')OR die('error : '.mysql_error());
$db=mysql_select_db('test');

if($db){
    echo 'success';

}else{
    echo 'Error :' .mysql_error(); 
}

?>

Hope you can help me :( Thanks!

CodeGodie
  • 12,116
  • 6
  • 37
  • 66
  • did you try rename mysql => mysqli ? – PHPLego Mar 17 '17 at 23:54
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is **gone for ever in PHP7**. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Mar 17 '17 at 23:56
  • Thank you for reply! No,should i rename every single mysql in my code? –  Mar 17 '17 at 23:56
  • Unfortunately its not a simple change. Try a quick look at the [mysqli_ manual](http://php.net/manual/en/book.mysqli.php) OR better still the [PDO manual](http://php.net/manual/en/book.pdo.php) – RiggsFolly Mar 17 '17 at 23:58
  • Oh :(, but what about my code?.. cant be improved? :S –  Mar 18 '17 at 00:03

0 Answers0