PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 16, 2022

[FIXED] Php code not working

 March 16, 2022     lamp, mysql, php     No comments   

Issue

Here is my php code

<?php
try
{   
    $mysqlConnection = mysqli_connect('localhost', 'root', 'root');
    if($mysqlConnection)
    {
        echo "Connected"."\n";
        mysqli_select_db('test',$mysqlConnection);
        $result = mysqli_query("SELECT * from tbl_details");
        $row = mysqli_fetch_array($result);
        echo strlen($row);
    }
    else
    {
        echo "Not connected";
    }
}
catch(Exception $exp)
{
    echo $exp;
}   
?>

i have verified the credentials and also there is data in the table but still i'm getting no records. Any any point out why??

Update::

Working piece of code

<?php
try
{   
    $mysqlConnection = mysqli_connect('localhost', 'root', 'root','test');
    if($mysqlConnection)
    {
        echo "Connected"."\n";
        $result = $mysqlConnection->query("SELECT NAME,State FROM tbl_details");
        echo $result->num_rows."\n";
    }
    else
    {
        echo "Not connected";
    }
}
catch(Exception $exp)
{
    echo $exp;
}   
?>

Solution

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
$resultaat = $mysqli->query("SELECT * FROM tabel");
while ($record = $resultaat->fetch_assoc())
{
  print_r($record);
}


Answered By - Jurgo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing