0

I tried to search for an answer, but I don't really know what my question is. I have been getting Error 504, gateway timeout. This is the code that is giving me the problem.

$query = mysqli_query($dbc,"SELECT 
CertificateNumber,Lang,InsuredId FROM policy WHERE Lang = ''"); //rows without Lang
if($query){
    while($row = mysqli_fetch_array($query)){
        $get_lang = mysqli_query($dbc, "SELECT Lang FROM policy WHERE 
        CertificateNumber='".$row['CertificateNumber']."'"); //other rows with same certificate number
        while($i = mysqli_fetch_array($get_lang)){
            if($i['Lang']!=""){ // update lang if any rows with the same certificate number has lang
                mysqli_query($dbc, "UPDATE policy SET Lang='". $i['Lang'] ."' WHERE InsuredId='".$row['InsuredId']."'");
            }
        }
    }
}

I am trying to find all the rows without Lang, get lang from other rows with same CertificateNumber and update the original row. This works on smaller tables.(InsuredId is unique for each row, not primary key)

Any help appreciated!

Thanks!

Found solution from (guess I should've searched harder before posting a question): Update row with data from another row in the same table

PenPen
  • 58
  • 5
  • 4
    [Little Bobby](http://bobby-tables.com/) says **[you are at risk for SQL Injection Attacks](https://stackoverflow.com/q/60174/)**. Learn about [Prepared Statements](https://en.wikipedia.org/wiki/Prepared_statement) for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even **[escaping the string](https://stackoverflow.com/q/5741187)** is not safe! I recommend `PDO`, which I [wrote a function for](https://stackoverflow.com/a/45514591) to make it extremely **easy**, very **clean**, and way more **secure** than using non-parameterized queries. – GrumpyCrouton Aug 08 '17 at 18:54
  • Thanks for your suggestion. However, it doesn't answer my question. – PenPen Aug 08 '17 at 19:15
  • 1
    precisely why I didn't post it as an answer. – GrumpyCrouton Aug 08 '17 at 19:38
  • Should all policies with the same CertificateNumber have the same Lang? – Don't Panic Aug 08 '17 at 19:43

0 Answers0