Jump to content

Trouble with ASP to PHP - Please help!


Go to solution Solved by boompa,

Recommended Posts

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 by Horrockz
Link to comment
https://forums.phpfreaks.com/topic/279433-trouble-with-asp-to-php-please-help/
Share on other sites

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 by boompa

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.

 

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 by Horrockz
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.