MrTV
asked on
Php my sql try to connect and query
when i run the code below it does not eork how can i fix it
Warning: mysql_query() expects parameter 1 to be string, object given in C:\wamp\www\asian\stockadj ust\montly concludesi oninvoice. php on line 25
Call Stack
# Time Memory Function Location
1 0.0110 252760 {main}( ) ..\montlyconcludesioninvoi ce.php:0
2 0.0198 291904 mysql_query ( ) ..\montlyconcludesioninvoi ce.php:25
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\asian\stockadj ust\montly concludesi oninvoice. php on line 26
Warning: mysql_query() expects parameter 1 to be string, object given in C:\wamp\www\asian\stockadj
Call Stack
# Time Memory Function Location
1 0.0110 252760 {main}( ) ..\montlyconcludesioninvoi
2 0.0198 291904 mysql_query ( ) ..\montlyconcludesioninvoi
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\asian\stockadj
<?php
session_start();
header('Content-Type: text/html; charset=utf-8');
error_reporting(E_ALL);
include "./common_db.inc";
$register_script = "./register.php";
// Create connection
$con=mysqli_connect("$dbhost","$dbusername","$dbuserpassword","$default_dbname1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "<h2>Category id and sum of total costs of purchases grouped by category id :</h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Category id</td><td width='100' align='center'>Sum of total costs of purchases</td>";
$result = mysql_query($con,"SELECT name,SUM(grandtotal) FROM asianinvoice GROUP BY name");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['name'] . "</td>";
echo "<td align='center' width='200'>" . $row['SUM(grandtotal)'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ray's right, you're mixing two different methods. You need to make it all 'mysqli' functions.
ASKER
hi Jagadishwor Dulal
I change the code to your suggestion it show
( ! ) Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\asian\stockadj ust\montly concludesi oninvoice. php on line 24
Call Stack
# Time Memory Function Location
1 0.0007 252760 {main}( ) ..\montlyconcludesioninvoi ce.php:0
2 0.0300 272376 mysql_query ( ) ..\montlyconcludesioninvoi ce.php:24
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\asian\stockadj ust\montly concludesi oninvoice. php on line 25
Call Stack
# Time Memory Function Location
1 0.0007 252760 {main}( ) ..\montlyconcludesioninvoi ce.php:0
2 0.0304 272608 mysql_fetch_array ( ) ..\montlyconcludesioninvoi ce.php:25
I change the code to your suggestion it show
( ! ) Warning: mysql_query() expects parameter 1 to be string, resource given in C:\wamp\www\asian\stockadj
Call Stack
# Time Memory Function Location
1 0.0007 252760 {main}( ) ..\montlyconcludesioninvoi
2 0.0300 272376 mysql_query ( ) ..\montlyconcludesioninvoi
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\asian\stockadj
Call Stack
# Time Memory Function Location
1 0.0007 252760 {main}( ) ..\montlyconcludesioninvoi
2 0.0304 272608 mysql_fetch_array ( ) ..\montlyconcludesioninvoi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://php.net/manual/en/function.mysql-connect.php
PHP 5.5 is the current release. In other words, MySQL is already deprecated and on the way out. So it's time to make the switch, which is not hard at all if you follow the directions in this article.