#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    69
    Rep Power
    28

    Php 5.3 to PHP 7.0 Help


    They upgraded our server today and I have some old php code that no longer works in PHP 7.0
    I get no results back, just a blank page. What do I need to fix:

    <table width="900" border="1" cellspacing="0" cellpadding="4">
    <tr>
    <td>First Name</td>
    <td>E-Mail</td>
    <td>Token</td>
    <td>Completed</td>
    <td>Type</td>
    <td>Credits</td>
    <td>Certificate</td>
    </tr>
    <?
    $sql="Select * from surv_tokens_555 ORDER BY firstname";
    $result=mysqli_query($sql);
    while($row=mysqli_fetch_assoc($result)):

    if ($row['completed'] != "N") {

    $sqlcredit="Select * from surv_survey_555 WHERE token='".$row['token']."'";
    $resultcredit=mysqli_query($sqlcredit) or die(mysql_error());
    $credit = 0;
    $rowcredit=mysqli_fetch_assoc($resultcredit);

    if ($rowcredit['555X1127X14221'] != 'N'){
    $credit++;
    }
    if (($rowcredit['555X1126X14216'] != '') && ($rowcredit['555X1126X14216'] != '4')){
    $credit++;
    }
    if (($rowcredit['555X1129X14229'] != '') && ($rowcredit['555X1129X14229'] != '4')){
    $credit++;
    }
    if ($rowcredit['555X1128X14223'] != 'N'){
    $credit++;
    }

    $sql2="Select * from surv_tokens_555 WHERE token='".$row['token']."'";
    $result2=mysqli_query($sql2) or die(mysql_error());

    while($row2=mysqli_fetch_assoc($result2)):

    if ($row['attribute_1']=='Nurse') {
    $type= "NurseDay1_2017";
    }

    if ($row['attribute_1']=='Physician') {
    $type= "PhysicianDay1_2017";
    }

    if (($row['attribute_1']=='Respiratory Therapist') || ($row['attribute_1']=='Respiratory')) {
    $type= "RespiratoryDay1_2017";
    }

    if ($row['attribute_1']=='ALS') {
    $type= "ALSDay1_2017";
    }

    if ($row['attribute_1']=='ALS-PA') {
    $type= "ALS-PADay1_2017";
    }

    if ($row['attribute_1']=='Non-Physician') {
    $type= "PADay1_2017";
    }

    endwhile;
    $name=$row['lastname']." ".$row['firstname'];
    $email = $row['email'];
    $link = "http://cab321.org/cme/Default.aspx?name=$name&credit=$credit&type=$type&email=$email";
    }
    else {
    $name=$row['lastname']." ".$row['firstname'];
    $credit = 0;
    $token = $row['token'];
    $link = "http://www.abc123.org/survey/index.php/sid/555/token/$token/lang/en/newtest/Y";
    }

    ?>

    <tr>
    <td><? echo $name; ?></td>
    <td><? echo $row['email']; ?></td>
    <td><? echo $row['token']; ?></td>
    <td><? echo $row['completed']; ?></td>
    <td><? echo $row['attribute_1']; ?></td>
    <td><? echo $credit; ?></td>
    <td><? if ($credit != "0") { ?><a href="<? echo $link; ?>" target="_blank">Print Certificate</a><? } else { ?> <a href="<? echo $link; ?>" target="_blank">Take Survey</a> <? } ?></td>
    </tr>
    <? endwhile; ?>


    </table>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    69
    Rep Power
    28
    I fixed all the $result=mysqli_query($sql); to say $result=mysqli_query($connect,$sql);
    and also fixed the mysql_error

    Now it runs, but only pulls up one result.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    69
    Rep Power
    28
    Found the last error, had to remove the die statement
  6. #4
  7. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,110
    Rep Power
    9644
    5.3 to 7.0 is a big jump and just fixing errors as they happen isn't a good idea.

    php.net has upgrade guides you can look at. Get familiar with each guide between 5.3 and 7.0, then set aside time to look through your codebase for anything that may have been affected.
  8. #5
  9. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,447
    Rep Power
    70
    Just a note/suggestion for some of your scripting. Since your if()'s are referencing options for the same item, a switch may be an option...
    Original code:
    PHP Code:
    if ($row['attribute_1']=='Nurse') { 
    $type"NurseDay1_2017";


    if (
    $row['attribute_1']=='Physician') { 
    $type"PhysicianDay1_2017";


    if ((
    $row['attribute_1']=='Respiratory Therapist') || ($row['attribute_1']=='Respiratory')) { 
    $type"RespiratoryDay1_2017";


    if (
    $row['attribute_1']=='ALS') { 
    $type"ALSDay1_2017";


    if (
    $row['attribute_1']=='ALS-PA') { 
    $type"ALS-PADay1_2017";


    if (
    $row['attribute_1']=='Non-Physician') { 
    $type"PADay1_2017";

    Switch: (Line by line w/ optional 'default' added.)
    PHP Code:
    switch($row['attribute_1']) {
      case 
    'Nurse':
        
    $type 'NurseDay1_2017';
        break;
      case 
    'Physician':
        
    $type 'PhysicianDay1_2017';
        break;
      case 
    'Respiratory Therapist':
        
    $type 'RespiratoryDay1_2017';
        break;
      case 
    'Respiratory':
        
    $type 'RespiratoryDay1_2017';
        break;
      case 
    'ALS':
        
    $type 'ALSDay1_2017';
        break;
      case 
    'ALS-PA':
        
    $type 'ALS-PADay1_2017';
        break;
      case 
    'Non-Physician':
        
    $type 'PADay1_2017';
        break;
      case default:
        
    $type 'This is optional in case $row['attribute_1'] does not equal anything prior.';

    Switch: (Shortened w/ optional 'default' added.)
    PHP Code:
    switch($row['attribute_1']) {
      case 
    'Nurse'$type 'NurseDay1_2017'; break;
      case 
    'Physician'$type 'PhysicianDay1_2017'; break;
      case 
    'Respiratory Therapist'$type 'RespiratoryDay1_2017'; break;
      case 
    'Respiratory'$type 'RespiratoryDay1_2017'; break;
      case 
    'ALS'$type 'ALSDay1_2017'; break;
      case 
    'ALS-PA'$type 'ALS-PADay1_2017'; break;
      case 
    'Non-Physician'$type 'PADay1_2017'; break;
      case default: 
    $type 'This is optional in case $row['attribute_1'] does not equal anything prior.';

    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.

IMN logo majestic logo threadwatch logo seochat tools logo