-5

what am i gonna put inside the for loop to connect it to the database

<?php
try {
require ("db.php");
 $sql = ("select company_name, company_logo from company");
mysql_query($sql);

for () {
    print '<a href="systemlogin2.php">$row['company_name']</h2>';
    print '<p><img border="0" src="$row['company_logo']" width="230" height="198"></p>';
}
}
?>

2 Answers2

0

Hello PHP tries to execute "company_name"

print '<h2><a href="systemlogin2.php">'.$row["company_name"].'</a></h2>';

Should be working!

shubham715
  • 3,324
  • 1
  • 17
  • 27
  • Oh, i didnt looked on the other snipets, but: You need a db connection, i dont know if this happens in the db.php mysql_query is deprecated, and is completely removed in PHP7. – Gerald Vrana Oct 03 '16 at 07:48
  • Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\homepage.php:30 Stack trace: #0 {main} thrown in C:\xampp\htdocs\homepage.php on line 30 – Nzo Arroyo Oct 03 '16 at 07:50
0

mysql() - The old mysql_* functions deprecated in PHP 5.5. In this short tutorial you will get a instruction how to solve this error message.

Why was mysql deprecated in PHP 5.5?

Because the below listed are missing points in PHP 5.5

  • Stored Procedures
  • Prepared Statements
  • (SSL-)Encryption
  • Compression
  • Full charset support

How to solve the warnings?

Currently mostly many MySQL connections in PHP use this construct:

Replace:

<?php
$link = mysql_connect('localhost', 'user', 'password');
mysql_select_db('dbname', $link);
?>

With

The way with MySQLi would be like this:

<?php
$link = mysqli_connect('localhost', 'user', 'password', 'dbname');

Filthy and fastest solution:

Suppress all deprecated warnings including them from mysql_*:

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

Solution for your problem

Deprecated features in PHP 5.5.x

The original MySQL extension is now deprecated, and will generate E_DEPRECATED errors when connecting to a database. Instead, use the MYSQLi or PDO_MySQL extensions.

replace all mysql_ functions into mysqli_* functions

You have to make concatenation of the PHP variables in order to print it. Since then alone it will display the data.

Replace:

print '<a href="systemlogin2.php">$row['company_name']</h2>';
print '<p><img border="0" src="$row['company_logo']" width="230" height="198"></p>';

With:

print '<a href="systemlogin2.php">'.$row['company_name'].'</h2>';
print '<p><img border="0" src="'.$row['company_logo'].'" width="230" height="198"></p>';
Naresh Kumar P
  • 4,127
  • 2
  • 16
  • 33