Notice: Undefined variable: ek_yuk in

Hello,
Notice: Undefined variable: ek_yuk in

$ek_yuk += $table['DATA_FREE'];

How do I fix this error?

By making sure the variable exists before you try and use it.

have you tried php isset() function to check.

or coalesce operator.

I try this way but it gives the same error

	   $result = $mysqli->query("
                                    SELECT TABLE_SCHEMA, 
                                    TABLE_NAME, 
                                    (INDEX_LENGTH+DATA_LENGTH) AS SIZE_KB, 
                                    TABLE_ROWS, DATA_FREE
                                    FROM INFORMATION_SCHEMA.TABLES
                                    WHERE TABLE_SCHEMA = '$db_name'
                                    ORDER BY $sort");
                                    
                                    
     while($table = $result->fetch_array()) {

     if(isset($table['DATA_FREE'])){
     @$ek_yuk += $table['DATA_FREE'];
     $ekyuk = showSize($ek_yuk);
     }
     $boyutu = showSize($table['SIZE_KB']);
     @$satir += $table['TABLE_ROWS'];
     $satirlar = number_format($satir, 0, ',', '.');
     @$boyut += $table['SIZE_KB'];
     $toplam = showSize($boyut);
     
     }

initialize that variable before making operations on it.

I’m a beginner, You can explain a little more

You set a value to the variable before using it the first time.

What is the real problem you are trying to solve with this? It seems rather odd that a beginner is going to query the information schema.

this is the same as

$ek_yuk = $ek_yuk + $table['DATA_FREE'];

The left $ek_yuk will be assigned with a new calculated value which is fine.
The right $ek_yuk (after the =) should be an existing variable while it is not (on the first time).

Wrong:
<?php
while($i < 10) { // you want to compare a non existing variable
    $i++;
}
?>

Right:
<?php
$i = 0; // add a new variabele $i with a initial value of 0.
while($i < 10) { // you compare an existing variable now
    $i++;
}
?>

Thank you so much
The “Notice: Undefined variable” issue has improved as follows

 $ek_yuk = 0;
 $satir = 0;
 $boyut = 0;
 while($table = $result->fetch_array()) {

 $ek_yuk = $ek_yuk += $table['DATA_FREE'];
 $ekyuk = showSize($ek_yuk);
 $boyutu = showSize($table['SIZE_KB']);
 $satir = $satir += $table['TABLE_ROWS'];
 $satirlar = number_format($satir, 0, ',', '.');
 $boyut = $boyut += $table['SIZE_KB'];
 $toplam = showSize($boyut);

According to option “error2” gives the “Notice: Undefined variable: error2” error
if (!$error && !$error2 && $optimize)
How can I fix this error?
NOTE: I received this code from the internet immemorial, I can not write such a code,

	// Loop Tables
	foreach ($tables AS $table){
		$error = 0;
		$optimize = 1;

		// Check Table
		$check = $mysqli->query("CHECK TABLE `$table`");
		while ($status = $check->fetch_array()){
			// Status
			if ($status[2] == 'error')
			{
				if ($status[3] == 'The handler for the table doesn\'t support check/repair')
				{
					$optimize = 0;
				}
				else
				{
					$error = 1;
				}
			}
		}

		// Check Table Error
		if ($error)
		{
			// Repair Table
			$repair = $mysqli->query("REPAIR TABLE `$table`");

			// Status
			if ($repair[3] != 'OK')
			{
				$error2 = 1;
			}
			else
			{
				$error2 = 0;
				$error = 0;
			}
		}

		// Check Optimize
		if (!$error && !$error2 && $optimize)
		{
			// Optimize Table
			$optimize = $mysqli->query("OPTIMIZE TABLE `$table`");
			while ($status = $optimize->fetch_array())
			{
				// Status
				if ($status[2] == 'error')
				{
					$error = 1;
				}
			}
		}
	}

define that variable before using it?

I could not understand, Can you give sample?

$error = ‘Some strange error’; // define or initializing the variable
echo $error; // use the variable

Above goes well Adem but if you forget the first line and just do:

echo $error; // use the variable

What should the variable contain for content? you will get a Notice: Undefined variable: error

Thank you, problem is improved

foreach ($tables AS $table){
		$error = 0;
                $error2 = 1;
		$optimize = 1;

		// Check Table
Sponsor our Newsletter | Privacy Policy | Terms of Service