Can someone help me with finding bug in this piece of PHP code? | Sololearn: Learn to code for FREE!

+1

Can someone help me with finding bug in this piece of PHP code?

Hi, can you someone help me find a bug in this code? : [code] $file = fopen('profile/'.$identita.".php","x"); fwrite($file , " <html><head></head> <body> <h1>Profil uzivatele <?php echo $_SESSION['u_name']; ?></h1> <?php $sql = \"SELECT * FROM videos WHERE id = '$identita' \"; $result = mysqli_query($conn , $sql); $pocet = mysqli_num_rows($result); if ($pocet > 0){ echo \"Uzivatel nahral \"; echo $pocet; echo \" videi.\"; echo \"<hr><hr>\"; while ($row = mysqli_fetch_assoc($result)){ echo \" <p>NAZEV: \".$row['nazev'].\"</p> <p>ODKAZ: \".$row['odkaz'].\"</p> <p>ZHLEDNUTI: \".$row['views'].\"</p> <video width='400' height = '400' id = \".$row['cislo'].\" onended = \"intro\".$row['cislo'].\"()\" controlsList='nodownload' controls> <source src='testing.mp4' type=\"video/mp4\"> </video> <script type='text/javascript' > var cislo = 0; function intro\".$row['cislo'].\"() { var vidd\".$row['cislo'].\" = document.getElementById(\"\".$row['cislo'].\"z"); cislo = cislo + 1; var dalsi\".$row['cislo'].\" = '\".$row['cesta'].\"'; vidd\".$row['cislo'].\".src = dalsi\".$row['cislo'].\"; vidd\".$row['cislo'].\".play(); if (cislo == 2){ url: 'ajax.php', //This is the current doc type: \"POST\", data: ({video:\".$row['cislo'].\"}), success: function(data){ console.log(data); } }); } } </script> <hr>\"; } } ?> "); fclose($file); [end of the code] It just shows server error 500, so I guess, theres a bug somewhere in it

1/27/2018 8:59:38 PM

Radek Horáček

3 Answers

New Answer

+5

Create and check a php info file and see if allow_url_fopen & allow_url_include are enabled. Is mysqli/mysqlnd and pdo php modules installed? Can you also use either the php.ini or .htaccess to enable php error logging? Which one you use will depend on what php handler you use. You may try both if you are unsure of the php handler. Be sure to remember to clear all site and browser caching after each change/check to ensure you aren’t loading cached content. I hope this helps! ;)

+5

Forget to mention that allow_url_fopen is sometimes listed in php.ini’s disabled_functions, so you’ll want to also check that

+1

check ur localhost connection then check your file location