Horrockz Posted June 21, 2013 Share Posted June 21, 2013 (edited) Hello all, I'm having some difficult with an ASP to PHP conversion. The objective of this block of code is: The code will recognize that the user has picked a province from a previously coded drop down list (which is working), and load up a page with information from the DB regarding the province chosen. I'm getting errors all over the place and I'm pretty lost with this... Can anyone give me a hand? Here is the ASP block of code in question: <% Else province = Request.QueryString("Province") 'Get the full name of the province (using the abbreviation) SQL = "SELECT * FROM PROVINCE WHERE PK_PROVINCE = " & "'" & province & "'" Set RSPLANT = PlantConn.Execute(SQL) provinceFullName = RSPLANT("PROVINCE_ENGLISH") Response.Write "<p class=heading>Learn about the Plants of " & provinceFullName & "</p>" SQL = "SELECT * FROM PLANT, MONITORED WHERE PK_PLANT = FK_PLANT AND FK_PROVINCE = " & "'" & province & "'" & " ORDER BY COMMON_NAME_ENGLISH" Set RSPLANT = PlantConn.Execute(SQL) If RSPLANT.BOF And RSPLANT.EOF Then 'no records found errorString = errorString & "<li>No records were found" Else Response.Write "<table cellpadding=2 cellspacing=2 border=0 width=""100%"">" Do While Not RSPLANT.EOF Response.Write "<tr>" & vbCrlf Response.Write " <td align=right>" & vbCrlf Response.Write " <a href=/english/xxx/species_details.asp?species=" & RSPLANT("PK_PLANT") & "><img src=/databases/plants/images/small/" & RSPLANT("IMAGE_FILE") & " border=0 alt=""Click for more information""></a>" & vbCrlf Response.Write " </td>" & vbCrlf Response.Write " <td>" & vbCrlf Response.Write " Common name: " & RSPLANT("COMMON_NAME_ENGLISH") & vbCrlf Response.Write " <br>Scientfic name: <i>" & RSPLANT("SCIENTIFIC_NAME") & "</i>" & vbCrlf If RSPLANT("AKA_ENGLISH") <> "" Then Response.Write "<br>Also known as: " & RSPLANT("AKA_ENGLISH") Response.Write " <br> <br><a href=/english/xxx/species_details.asp?species=" & RSPLANT("PK_PLANT") & ">Click here for more information</a>" & vbCrlf Response.Write " </td>" & vbCrlf Response.Write "</tr>" & vbCrlf RSPLANT.Movenext If Not RSPLANT.EOF Then Response.Write "<tr>" & vbCrlf Response.Write " <td colspan=2>" & vbCrlf Response.Write " <hr size=1>" & vbCrlf Response.Write " </td>" & vbCrlf Response.Write "</tr>" & vbCrlf End If Loop Response.Write "</table>" End If RSPLANT.Close Set RSPLANT = Nothing End If If errorString <> "" Then Response.Write "<p><b>The following errors occurred:</b></p>" Response.Write "<p><ul>" & errorString & "</ul></p>" End If Here is my attempt at the PHP: /* This is where the errors are occurring */ <? } else { $province = @$_GET["Province"]; $strSQL = "SELECT * FROM province WHERE pk_province = $province"; $objQuery = mysql_query($strSQL); $objResult = mysql_fetch_array($objQuery) $provinceFullName = $strSQL["province_english"]; echo "<p class=heading>Learn about the Plants of $provinceFullName</p>"; ?> <? $strSQL = "SELECT * FROM plant, monitored WHERE pk_plant = fk_plant AND fk_province = "."'".$province."'"." ORDER BY common_name_english"; $objQuery = mysql_query($strSQL); while($objResult = mysql_fetch_array($objQuery)) { echo '<table cellpadding=2 cellspacing=2 border=0 width="100%">'; echo "<tr>"."\n"; echo " <td align=right>"."\n"; echo " <a href=/english/xxx/species_details.php?species=".$strSQL["pk_plant"]."><img src=/databases/plants/images/small/".$strSQL["image_file"].' border=0 alt="Click for more information"></a>'."\n"; echo " </td>"."\n"; echo " <td>"."\n"; echo " Common name: ".$strSQL["common_name_english"]."\n"; echo " <br>Scientfic name: <i>".$strSQL["scientific_name"]."</i>"."\n"; if ($strSQL["aka_english"] != "") {echo "<br>Also known as: ".$strSQL["aka_english"];} echo " <br> <br><a href=/english/xxx/species_details.php?species=".$strSQL["pk_plant"].">Click here for more information</a>"."\n"; echo " </td>"."\n"; echo "</tr>"."\n"; } echo "</table>"; ?> <? mysql_close(); ?> Edited June 21, 2013 by Horrockz Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/ Share on other sites More sharing options...
Csharp Posted June 21, 2013 Share Posted June 21, 2013 What errors are you getting? It's pretty hard to 'just guess' Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437283 Share on other sites More sharing options...
Horrockz Posted June 21, 2013 Author Share Posted June 21, 2013 (edited) Sorry, off the bat I am getting this: Parse error: syntax error, unexpected T_VARIABLE in [/size]/home/nwdev/domain/web/english/dir/learn_plants.php on line [/size]121 Edited June 21, 2013 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437285 Share on other sites More sharing options...
boompa Posted June 21, 2013 Share Posted June 21, 2013 (edited) That error usually means you're missing something on the line right before the reported line. I don't know what comes before your else but this is generally bad form. $province = @$_GET["Province"]; Suppressing the error notice is a bad idea. You should be using isset($_GET['province']), and only running the code you've given if that is true. You also have no SQL error checking, another bad idea. And you're open to SQL injection because $_GET is easily manipulated by users and you're not sanitizing it prior to using it in your query. Edited June 21, 2013 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437286 Share on other sites More sharing options...
Barand Posted June 21, 2013 Share Posted June 21, 2013 line 118 is missing ; at end of statement and you are using the wrong variable on line 121 $objResult = mysql_fetch_array($objQuery); $provinceFullName = $objResult["province_english"]; Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437289 Share on other sites More sharing options...
Horrockz Posted June 21, 2013 Author Share Posted June 21, 2013 That error usually means you're missing something on the line right before the reported line. I don't know what comes before your else but this is generally bad form. $province = @$_GET["Province"]; Suppressing the error notice is a bad idea. You should be using isset($_GET['province']), and only running the code you've given if that is true. You also have no SQL error checking, another bad idea. And you're open to SQL injection because $_GET is easily manipulated by users and you're not sanitizing it prior to using it in your query. Thanks for your response. The code will be gone over in the next while to patch up potential vulnerabilities. I will definitely follow your suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437291 Share on other sites More sharing options...
Horrockz Posted June 21, 2013 Author Share Posted June 21, 2013 (edited) line 118 is missing ; at end of statement and you are using the wrong variable on line 121 $objResult = mysql_fetch_array($objQuery); $provinceFullName = $objResult["province_english"]; Thanks for this! With this changed, I am now getting the error: Parse error: syntax error, unexpected $end in /home/nwdev/dev.x.ca/web/english/x/learn_plants.php on line 156 Edited June 21, 2013 by Horrockz Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437292 Share on other sites More sharing options...
Solution boompa Posted June 21, 2013 Solution Share Posted June 21, 2013 Unexpected end: usually means you've forgotten a } In other words, the parser, reading from top-to-bottom, encountered an opening { but never found the matching } to close it. Hence...unexpected end. Quote Link to comment https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/#findComment-1437293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.