Jump to content

Having troubles with HTML+PHP


slpctrl

Recommended Posts

First off, here is my code(it grabs stock quotes from yahoo):

 

<html>
<head>
<?php
$stock = $_GET['stock'];
//Reads stock information from symbol entered
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnx&e=.csv","r");
//Grabs information and dumps it into $stock_info
$stock_info = fgetcsv ($yahoo_file, 1000, ",")
//The arrays below tell the script where to read the data from within the .csv file
?>
<title><?php echo $stock_info[10] ?> (<?  echo $stock_info[11] ?>: <?  echo $stock_info[0] ?>) </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
      <br> <?
  if ($stock != "") {
  ?>


      <br> 

              <?php


			//Reads stock information from symbol entered
	$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnxt7p2baa2a5b6pp&e=.csv","r");
			//Grabs information and dumps it into $stock_info
	$stock_info = fgetcsv ($yahoo_file, 1000, ",")
			//The arrays below tell the script where to read the data from within the .csv file
			?>


<?php echo "<span style=\"";
   # If we gained print the Company Name in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    } # if we lost print the Company Name in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "color: #009900;";
    }
   echo "\"><font size='6'>".$stock_info[10]."</font></span></li><dt><b>(".$stock_info[11].": ".$stock_info[0].")</b>       Last Trade: <i>".$stock_info[2]." at ".$stock_info[3]."</i>\n";
?>
<dt>
<?php echo "<span style=\"";
   # If we gained print the Change in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    } # if we lost print the Change in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "font-weight: normal;";
    }
   echo "\"><font size='4'>$".$stock_info[4]." (".$stock_info[13].")</span></li></font>\n";
?>
<dt>



                                                      <table width="95%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td height="258" valign="top">
                                                                    <div align="justify">
              		<?php
			$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnxt7p2baa2a5b6pp&e=.csv","r");
			$stock_info = fgetcsv ($yahoo_file, 1000, ",")
			?>


                                                                       <table width="100%" border="0" cellspacing="2" cellpadding="2">
                                                                            <tr>
                                                                                <td width="40%" height="221" align="left" valign="top">
                                                                                    <table>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Bid (Size)</strong></td>
                                                                                            <td class="data">$<?php echo $stock_info[14] ?> (<?php echo $stock_info[17] ?>)</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Ask (Size)</strong></td>
                                                                                            <td class="data">$<?php echo $stock_info[15] ?> (<?php echo $stock_info[18] ?>)</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Last Price</strong></td>
                                                                                            <td class="data"><font size="3"><b>$<?php echo $stock_info[1] ?></b></font></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Change</strong></td>
                                                                                            <td class="data"><strong>
<?php echo "<img src=";
   # If we gained print the GREEN ARROW
   if ($stock_info[4]>0) {
      echo "http://www.nasdaq.com/images/greenarrowsmall-index.gif";
    }

# if we lost print the RED ARROW 
   elseif ($stock_info[4]<0) {
      echo "http://www.nasdaq.com/images/redarrowsmall-index.gif";
    } # No color
   else {
      echo "http://www.thenewivo.info/pixel.gif";
    }
   echo "> </span></li>\n";
?>

<?php echo "<span style=\"";
   # If we gained print the Change in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    }    # If we lost print the Change in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "color: #009900;";
    }
   echo "\">$".$stock_info[4]." (".$stock_info[13].")</span></li>\n";
?>
														</strong></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Opened 
                                                                                                @</strong></td>
                                                                                            <td class="data"><?php echo $stock_info[5] ?></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Previous Close 
                                                                                                </strong></td>
                                                                                            <td class="data"><?php echo $stock_info[20] ?></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Day Range 
                                                                                                </strong></td>
                                                                                            <td class="data"><?php echo $stock_info[9] ?></td>
                                                                                        </tr>
                                                                                    </table>
                                                                                </td>

                                                                                    

            <? 
						//Prints copyright infomation
		  		} else { 
		 		 echo "http://thenewivo.info"
		  		 } ?> <br>

                                                    </td>

                                            </table>



</body>
</html>

 

So, if $stock != "" (not equal to nothing), then search yahoo for it, otherwise print http://thenewivo.info. Ultimately I'm going to put a form there for input to search for a stock quote. But instead, it prints everything it shouldn't, and doesn't print http://thenewivo.info. I can't figure out why  >:( Can anyone help me?

Link to comment
Share on other sites

Oops, too early. Here is my code:

 

<html>
<head>
<?php
$stock = $_POST['stock'];
//Reads stock information from symbol entered
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnx&e=.csv","r");
//Grabs information and dumps it into $stock_info
$stock_info = fgetcsv ($yahoo_file, 1000, ",")
//The arrays below tell the script where to read the data from within the .csv file
?>
<title><?php echo $stock_info[10] ?> (<?  echo $stock_info[11] ?>: <?  echo $stock_info[0] ?>) </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
      <br> <?php
  if ($stock != "") {
  ?>


      <br> 

              <?php


			//Reads stock information from symbol entered
	$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnxt7p2baa2a5b6pp&e=.csv","r");
			//Grabs information and dumps it into $stock_info
	$stock_info = fgetcsv ($yahoo_file, 1000, ",")
			//The arrays below tell the script where to read the data from within the .csv file
			?>


<?php echo "<span style=\"";
   # If we gained print the Company Name in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    } # if we lost print the Company Name in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "color: #009900;";
    }
   echo "\"><font size='6'>".$stock_info[10]."</font></span></li><dt><b>(".$stock_info[11].": ".$stock_info[0].")</b>       Last Trade: <i>".$stock_info[2]." at ".$stock_info[3]."</i>\n";
?>
<dt>
<?php echo "<span style=\"";
   # If we gained print the Change in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    } # if we lost print the Change in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "font-weight: normal;";
    }
   echo "\"><font size='4'>$".$stock_info[4]." (".$stock_info[13].")</span></li></font>\n";
?>
<dt>



                                                      <table width="95%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td height="258" valign="top">
                                                                    <div align="justify">
              		<?php
			$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnxt7p2baa2a5b6pp&e=.csv","r");
			$stock_info = fgetcsv ($yahoo_file, 1000, ",")
			?>


                                                                       <table width="100%" border="0" cellspacing="2" cellpadding="2">
                                                                            <tr>
                                                                                <td width="40%" height="221" align="left" valign="top">
                                                                                    <table>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Bid (Size)</strong></td>
                                                                                            <td class="data">$<?php echo $stock_info[14] ?> (<?php echo $stock_info[17] ?>)</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Ask (Size)</strong></td>
                                                                                            <td class="data">$<?php echo $stock_info[15] ?> (<?php echo $stock_info[18] ?>)</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Last Price</strong></td>
                                                                                            <td class="data"><font size="3"><b>$<?php echo $stock_info[1] ?></b></font></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Change</strong></td>
                                                                                            <td class="data"><strong>
<?php echo "<img src=";
   # If we gained print the GREEN ARROW
   if ($stock_info[4]>0) {
      echo "http://www.nasdaq.com/images/greenarrowsmall-index.gif";
    }

# if we lost print the RED ARROW 
   elseif ($stock_info[4]<0) {
      echo "http://www.nasdaq.com/images/redarrowsmall-index.gif";
    } # No color
   else {
      echo "http://www.thenewivo.info/pixel.gif";
    }
   echo "> </span></li>\n";
?>

<?php echo "<span style=\"";
   # If we gained print the Change in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    }    # If we lost print the Change in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "color: #009900;";
    }
   echo "\">$".$stock_info[4]." (".$stock_info[13].")</span></li>\n";
?>
														</strong></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Opened 
                                                                                                @</strong></td>
                                                                                            <td class="data"><?php echo $stock_info[5] ?></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Previous Close 
                                                                                                </strong></td>
                                                                                            <td class="data"><?php echo $stock_info[20] ?></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Day Range 
                                                                                                </strong></td>
                                                                                            <td class="data"><?php echo $stock_info[9] ?></td>
                                                                                        </tr>
                                                                                    </table>
                                                                                </td>

                                                                                    

            <?php
						//Prints copyright infomation
		  		} else { 
		 		 echo "<form action=/"/" method=/"POST/">
		 		 Quote:<br />
           <input type=/"text/" name=/"quote/"><br />
           <input type=/"submit/" value=/"Find/">
           </form>";
		  		 } ?> <br>

                                                    </td>

                                            </table>



</body>
</html>

 

I'm getting this error:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\wamp\www\Stock2.php on line 148

 

That line is:

 

echo "<form action=/"/" method=/"POST/">

 

Any ideas?  ??? ??? ???

Link to comment
Share on other sites

Alright, got that out of the way. Wrong slashes :o. Now, I've got this:

 

<html>
<head>
<?php
$stock = $_POST['stock'];
//Reads stock information from symbol entered
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnx&e=.csv","r");
//Grabs information and dumps it into $stock_info
$stock_info = fgetcsv ($yahoo_file, 1000, ",")
//The arrays below tell the script where to read the data from within the .csv file
?>
<title><?php echo $stock_info[10] ?> (<?  echo $stock_info[11] ?>: <?  echo $stock_info[0] ?>) </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> 
      <br> <?php
  if ($stock != "") {
  ?>


      <br> 

              <?php


			//Reads stock information from symbol entered
	$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnxt7p2baa2a5b6pp&e=.csv","r");
			//Grabs information and dumps it into $stock_info
	$stock_info = fgetcsv ($yahoo_file, 1000, ",")
			//The arrays below tell the script where to read the data from within the .csv file
			?>


<?php echo "<span style=\"";
   # If we gained print the Company Name in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    } # if we lost print the Company Name in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "color: #009900;";
    }
   echo "\"><font size='6'>".$stock_info[10]."</font></span></li><dt><b>(".$stock_info[11].": ".$stock_info[0].")</b>       Last Trade: <i>".$stock_info[2]." at ".$stock_info[3]."</i>\n";
?>
<dt>
<?php echo "<span style=\"";
   # If we gained print the Change in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    } # if we lost print the Change in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "font-weight: normal;";
    }
   echo "\"><font size='4'>$".$stock_info[4]." (".$stock_info[13].")</span></li></font>\n";
?>
<dt>



                                                      <table width="95%" border="0" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td height="258" valign="top">
                                                                    <div align="justify">
              		<?php
			$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgvmnxt7p2baa2a5b6pp&e=.csv","r");
			$stock_info = fgetcsv ($yahoo_file, 1000, ",")
			?>


                                                                       <table width="100%" border="0" cellspacing="2" cellpadding="2">
                                                                            <tr>
                                                                                <td width="40%" height="221" align="left" valign="top">
                                                                                    <table>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Bid (Size)</strong></td>
                                                                                            <td class="data">$<?php echo $stock_info[14] ?> (<?php echo $stock_info[17] ?>)</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Ask (Size)</strong></td>
                                                                                            <td class="data">$<?php echo $stock_info[15] ?> (<?php echo $stock_info[18] ?>)</td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Last Price</strong></td>
                                                                                            <td class="data"><font size="3"><b>$<?php echo $stock_info[1] ?></b></font></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Change</strong></td>
                                                                                            <td class="data"><strong>
<?php echo "<img src=";
   # If we gained print the GREEN ARROW
   if ($stock_info[4]>0) {
      echo "http://www.nasdaq.com/images/greenarrowsmall-index.gif";
    }

# if we lost print the RED ARROW 
   elseif ($stock_info[4]<0) {
      echo "http://www.nasdaq.com/images/redarrowsmall-index.gif";
    } # No color
   else {
      echo "http://www.thenewivo.info/pixel.gif";
    }
   echo "> </span></li>\n";
?>

<?php echo "<span style=\"";
   # If we gained print the Change in GREEN
   if ($stock_info[4]>0) {
      echo "color: #009900;";
    }    # If we lost print the Change in RED
   elseif ($stock_info[4]<0) {
      echo "color: #990000;";
    } # No color
   else {
      echo "color: #009900;";
    }
   echo "\">$".$stock_info[4]." (".$stock_info[13].")</span></li>\n";
?>
														</strong></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Opened 
                                                                                                @</strong></td>
                                                                                            <td class="data"><?php echo $stock_info[5] ?></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td><strong>Previous Close 
                                                                                                </strong></td>
                                                                                            <td class="data"><?php echo $stock_info[20] ?></td>
                                                                                        </tr>
                                                                                        <tr>
                                                                                            <td bgcolor="e1e5d1"><strong>Day Range 
                                                                                                </strong></td>
                                                                                            <td class="data"><?php echo $stock_info[9] ?></td>
                                                                                        </tr>
                                                                                    </table>
                                                                                </td>

                                                                                    

            <?php
						//Prints copyright infomation
		  		} else {
		 		 echo "<form action=\"\" method=\"POST\">
		 		 Quote:<br />
           <input type=\"text\" name=\"quote\"><br />
           <input type=\"submit\" value=\"Find\">
           </form>";
		  		 } ?> <br>

                                                    </td>

                                            </table>



</body>
</html>

 

However, even when I submit something it doesn't show any of the code, only the same form no matter what. Anyone have any ideas?

Link to comment
Share on other sites

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.