Jump to content

Migrading from PHP 4+ TO 5.4+


rcampos39
 Share

Recommended Posts

I am fairly new to PHP and I was tasked with migrading an app that runs on php 4+ enviroment into a 5.4 enviroment and I am getting warnings becasue its very old code, but I also would lie to know if there is a better way of writing the fallowing script of php code.

 

It checks weather a member has attended a course and if so it charges a price if not its a different price and so on.

 

Any help would be very appriciated.

<?phpif ($semattend == 'MEMBER-ATTENDED') {$total = "<tr>              <td height="30" align="right"><p><font color="#FF9900">*</font><font size="2">Total: </font></p></td>              <td height="30" colspan="3" align="left"><font size="2"><input type="hidden" id = "amount" value="1299"      name="amount" size="28">$1,299</font></td>            </tr>            <tr>              <td colspan="3" align="left"><p>Search results indicate that you belong to a member instituion and have completed the Essentials of SEM course</p></td>            </tr>            <input type="hidden" id = "semstatus" value="MEMBER-ATTENDED" name=semstatus">            <input type="hidden" id = "attended" value="Attended Course" name="attended">            <input type="hidden" id = "member" value="Member" name="member">";} elseif ($semattend == 'MEMBER-NOTATTENDED') {$total = "<tr>              <td height="30" align="right"><p><font color="#FF9900">*</font><font size="2">Total: </font></p></td>              <td height="30" colspan="3" align="left"><font size="2"><input type="hidden" id = "amount" value="1799"      name="amount" size="28">$1,799</font></td>            </tr>            <tr>              <td colspan="3" align="left"><p>Search results indicate that you belong to a member instituion and have not completed the Essentials of SEM course</p></td>            </tr>            <input type="hidden" id = "semstatus" value="MEMBER-NOTATTENDED" name=semstatus">            <input type="hidden" id = "attended" value="Not Attended Course" name="attended">            <input type="hidden" id = "member" value="Member" name="member">";            } elseif ($semattend == 'NONMEMBER-ATTENDED') {$total = "<tr>              <td height="30" align="right"><p><font color="#FF9900">*</font><font size="2">Total: </font></p></td>              <td height="30" colspan="3" align="left"><font size="2"><input type="hidden" id = "amount" value="1599"      name="amount" size="28">$1,599</font></td>            </tr>            <tr>              <td colspan="3" align="left"><p>Search results indicate that you do not belong to a member instituion and have completed the Essentials of SEM course</p></td>            </tr>            <input type="hidden" id = "semstatus" value="NONMEMBER-ATTENDED" name=semstatus">            <input type="hidden" id = "attended" value="Attended Course" name="attended">            <input type="hidden" id = "member" value="Non Member" name="member">";            } elseif ($semattend == 'NONMEMBER-NOTATTENDED') {$total = "<tr>              <td height="30" align="right"><p><font color="#FF9900">*</font><font size="2">Total: </font></p></td>              <td height="30" colspan="3" align="left"><font size="2"><input type="hidden" id = "amount" value="2099"      name="amount" size="28">$2,099</font></td>            </tr>            <tr>              <td colspan="3" align="left"><p>Search results indicate that you do not belong to a member instituion and have not completed the Essentials of SEM course</p></td>            </tr>            <input type="hidden" id = "semstatus" value="NONMEMBER-NOTATTENDED" name=semstatus">            <input type="hidden" id = "attended" value="Not Attended Course" name="attended">            <input type="hidden" id = "member" value="Non Member" name="member">";            }echo $total;?>
Link to comment
Share on other sites

That code looks fine. You could also use a switch() to do it, but I wouldn't be fussed about that.

 

What warnings are you getting?

 

If the registrant is not a member, the total wont show up and I get undefined variable for $total and $semattend.

Link to comment
Share on other sites

I don't know where $semattend is being set. You should show the section of code where the warnings are given, warnings always give a line number and a filename.

 

You must always give a value to your variables. Make sure $total and $semattend are always given a value no matter what the situation is.

 

Your if() statement should take into account whether the registrant is a member or not. You could add a final else statement for that:

} else {   $total = "<tr><td colspan="2"><p>Member not registered</p></td></tr>";}

I would recommend relearning HTML and CSS, your code looks really outdated and would be considered invalid by the W3C validator.

Link to comment
Share on other sites

I don't know where $semattend is being set. You should show the section of code where the warnings are given, warnings always give a line number and a filename.

 

You must always give a value to your variables. Make sure $total and $semattend are always given a value no matter what the situation is.

 

Your if() statement should take into account whether the registrant is a member or not. You could add a final else statement for that:

} else {   $total = "<tr><td colspan="2"><p>Member not registered</p></td></tr>";}

I would recommend relearning HTML and CSS, your code looks really outdated and would be considered invalid by the W3C validator.

This app was created over 4 years ago and its not my code. I inhareted this app when I came into a new position with the company im working with and I just want to make it work, then I will revamp the look and feel as well.

Link to comment
Share on other sites

This app was created over 4 years ago and its not my code. I inhareted this app when I came into a new position with the company im working with and I just want to make it work, then I will revamp the look and feel as well.

Here are the notices that I get.

 

Notice: Undefined variable: semattend in /var/www/html/www4.aacrao.org/sem-ep/fees.php on line 3Notice: Undefined variable: semattend in /var/www/html/www4.aacrao.org/sem-ep/fees.php on line 17Notice: Undefined variable: semattend in /var/www/html/www4.aacrao.org/sem-ep/fees.php on line 31Notice: Undefined variable: semattend in /var/www/html/www4.aacrao.org/sem-ep/fees.php on line 45Notice: Undefined variable: total in /var/www/html/www4.aacrao.org/sem-ep/fees.php on line 61

Link to comment
Share on other sites

Is that the entire PHP file? If so, it looks like the code relies on register_globals, which is definitely bad practice. You'll need to figure out where it is supposed to get the value of $semattend. It might be a post variable, or a get variable, or in a cookie, or a session.

Link to comment
Share on other sites

Is that the entire PHP file? If so, it looks like the code relies on register_globals, which is definitely bad practice. You'll need to figure out where it is supposed to get the value of $semattend. It might be a post variable, or a get variable, or in a cookie, or a session.

 

It Queries the database for the email the the registrant used, if th eemail exists they get discounted prices if it doesnt they get full price. Then $semattend uses that query result to be used in the code above. I think the queary may be wrong. this is what that looks like.

$query1 = "SELECT 'email' FROM management WHERE 'email' LIKE '$email'"; $total1 = mysqli_num_rows(connection, $query1);$semattend = ($total1 > 0)?'MEMBER-ATTENDED':'MEMBER-NOTATTENDED'; //member found or not found
Edited by rcampos39
Link to comment
Share on other sites

You probably need to post all of the code. If it is saying that $semattend is undefined, then it's not defined. Maybe that code is inside of an if statement that only gets executed in certain situations, I can't tell by just what you're posting. How is the code in post 9 connected to the code in post 1?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...