-1

I am trying to build a website that would provide me with the value of Pi up to decimal places desired by the user. If the user wants to see value of pi upto 2 decimal place then he/she needs to provide input 2 and value will be displayed as 3.14. I have written a php file but while trying to host the file via xampp I am getting the following errors

This is my code:

<?php
$con=mysqli_connect("localhost","whoop_root_596","Ns4td1^9","demo_pi");

$curTime = microtime(true);
$f_val=$_POST["f_val"];

$response = array();
$statement = mysqli_query($con, "SELECT * FROM pi_value where sl='1'") or die(mysqli_error($con));
while($row=mysqli_fetch_array($statement))
{
    $pi_value = $row['vl'];
}

    $pi_value_explode = explode(",", $pi_value);

    $lv="";
    for($i=0;$i<$f_val;$i++)
    {

        $lv=$lv.$pi_value_explode[$i];
        if($i%150==0)
            if($i>150)
            {}
    }
    $timeConsumed = round(microtime(true) - $curTime,3)*1000; 
    $fsval="3.".$lv;
    $sdval="Time Consumed: ".$timeConsumed."ms";

$response = array( array('val1' => $fsval, 'val2' => $sdval) );

echo json_encode($response);

mysqli_close($con);
?> 

These are the errors getting displayed shown in the picture: enter image description here

kindly provide an effective solution. Any help will be kind enough

1 Answers1

0

There are few things that you have to note here. Firstly, you have an access a problem to your Database.This can be fixed be the below method.

In your MySQL command interface, type in

CREATE user user@localhost IDENTIFIED BY 'password_txt';

And then updae the password with

SET PASSWORD FOR 'user'@'localhost' = PASSWORD('password_txt');

That should solve your first warning.

Also, on Line 5 where you are receiving the value from the form, make sure id passed is correct. The value is not received correctly hence you are shown an error "Undefined Index". This error means that within your code, there is a variable or constant that has no value assigned to it

The last two warning are caused due to the error in the credentials. Fix your user details and that should be resolved by itself.

nXn
  • 904
  • 6
  • 13