0

I am following a online tutorial to create a mini shopping cart, all is going well but now i am getting this error:

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

I cannot find any information anywhere on this error. Every time i google it ,solutions for:

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

appear.

PHP

 $id = substr($prod_name, 14, (strlen($prod_name) - 14));
 $get_query = mysql_query('SELECT Product_Id,Product_Name,Product_Price FROM Product WHERE Product_Id =' . mysql_real_escape_string((int) $id));
 while ($get_row = mysql_fetch_assoc($get_query)) {
 //subtotal
 $sub = $get_row['Product_Price'] * $value;
 echo $value . ' x ' . $get_row['Product_Name'] . ' @ ' . $get_row['Product_Price'] . ' ' . $sub . '<br/>';
            }

Is using mysql_query a bad idea? Where may have i/tutorial gone wrong? any help will be extremely helpful

Monroe
  • 177
  • 11
  • 3
    `mysql_*` functions has been removed in PHP 7, use `mysqli_*` instead – Panda Apr 20 '16 at 22:14
  • 1
    possible duplicate of http://stackoverflow.com/questions/13201095/call-to-undefined-function-mysql-query – David Wyly Apr 20 '16 at 22:14
  • 1
    You should've had a failure for `mysql_connect` because you need to establish a connection before you run a query. `mysql_*` functions are a bad idea because they've long been deprecated and there are better alternatives out there such as PDO. – skrilled Apr 20 '16 at 22:14
  • 1
    You should look for another online tutorial that uses mysqli or PDO and parameterized queries. The one you are using is probably outdated. – Cave Johnson Apr 20 '16 at 22:15
  • @skrilled i do at the top of my page, and thank you – Monroe Apr 20 '16 at 22:29

1 Answers1

2

If you are using PHP 7 mysql_* functions permanently removed from PHP7. You can check PDO or mysqli for Database Operations.

aprogrammer
  • 1,754
  • 9
  • 20