PHP help

Aravinthan

New Member
Messages
68
Reaction score
0
Points
0
Hi,
I am making a personal website in which I show my teams and my recent hockey scores. So I made this code, that will insert the recent games in a table and update the players points table.:
form.php:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<title>Aravinthan, Sivaneswaran</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../../style.css" media="screen" />
</head>
<body>
<div id="wrap">
<div id="header">
<h1><a href="#">Aravinthan Sivaneswaran</a></h1>
<h2>My Personal Website</h2>
</div>
<!-- Top Navigation -->
<?php include("../../include/topnav.php"); ?>
<!-- Top Navigation End -->
<!-- Conteant -->
<div id="content">
<div class="right">
<h2>Hockey</h2>
<br /><br />
<form method="post" action="formprocess.php">
 <table>
  <tr>
   <td>
    Game Number: <input type="text" name="gamenumber" maxlength="2" />
   </td>
  </tr>
  <tr>
   <td>
    Goals For: <input type="text" name="gf" maxlength="2" size="5%" />
   </td>
   <td>
    Goals Against: <input type="text" name="ga" maxlength="2" size="5%" />
   </td>
  </tr>
  <tr>
  <?php
  $link = mysql_connect ("localhost", "stmaxel_ara", "*edited*")
  or die("mysql_error()");
mysql_select_db ("stmaxel_stats", $link);
$result = mysql_query("SELECT fname, lname FROM `2008-2009` ",$link);
 echo "<th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'></font></th>
 <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>Name</font></th>
 <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>G</font></th>
 <th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>A</font></th>
<th align='center' BGCOLOR='#413326'><FONT COLOR='#FFFFFF' size='3'>P</font></th>";
echo "</tr>";
while($row = mysql_fetch_array($result))
{
 $lname = $row['lname'];
 $fname = $row['fname'];
 echo "<tr>";
 echo "<td>";
 echo "$lname, $fname:";
 echo "</td>";
 echo "<td>";
 echo "<input type='text' name='$lname' value='$lname, $fname' readonly />";
 echo "</td>";
 echo "<td>";
 echo "<input size='1%' type='text' name='$lnameg' maxlength='2'/>";
 echo "</td>";
 echo "<td>";
 echo "<input size='1%' type='text' name='$lnamea' maxlength='2' />";
 echo "</td>";
 echo "<td>";
 echo "<input size='1%' type='text' name='$lnamep' maxlength='2' />";
 echo "</td>";
 echo "</tr>";
 }
?>
<tr>
 <td>
  <input type="submit" value="Submit" />
  <input type="reset" value="Reset" />
 </td>
</tr>
</table>
</form>
<br /><br />
Thanks for visiting my site and enjoy your stay,
Ara
</div>
<!-- Content End -->
<!-- Left Navigation -->
<?php include("../../include/leftnav.php"); ?>
<!-- Left Navigation End -->
<div style="clear: both;"> </div>
</div>
<div id="bottom"> </div>
<!-- Footer -->
<?php include("../../include/footer.php"); ?>
<!-- Footer End -->
</div>
</body>
</html>
formprocess.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<title>Aravinthan, Sivaneswaran</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../../style.css" media="screen" />
</head>
<body>
<div id="wrap">
<div id="header">
<h1><a href="#">Aravinthan Sivaneswaran</a></h1>
<h2>My Personal Website</h2>
</div>
<!-- Top Navigation -->
<?php include("../../include/topnav.php"); ?>
<!-- Top Navigation End -->
<!-- Conteant -->
<div id="content">
<div class="right">
<h2>Hockey</h2>
<br /><br />
<?php
$link = mysql_connect ("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("stmaxel_stats") or die(mysql_error());
$gameid = $_POST['gamenumber'];
$gf = $_POST['gf'];
$ga = $_POST['ga'];
$lname = $_POST['lname'];
$lnameg = $_POST['lnameg'];
$lnamea = $_POST['lnamea'];
$lnamep = $_POST['lnamep'];
if (gf > ga){
  $winner = "Win";
  }
  else{
  $winner = "Loss";
  }
$sql="SELECT COUNT(*) AS count
        FROM games
        WHERE gameid='$gameid'";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
if ($row['count']>0){
   echo "There is already a game with this id.";
   }
else {
 if (lnamep > 0){
  mysql_query("INSERT INTO games (gameid, gf, ga, winner, lname, lnameg, lnameg, lnamep ) VALUES ('$gameid', '$gf', '$ga', '$winner', '$lname', '$lnameg', '$lnamea', '$lnamep')") or die(mysql_error());
  print "Game $gameid has been successfully inserted into the database. Details:
  Winner of the game: $winner<br/>
  Scorers: $lname, $lnameg, $lnamea, $lnamep ";
    $res = mysql_query("SELECT * FROM `2008-2009` WHERE lname='$lname' ",$link);
    while($row = mysql_fetch_array( $res)) {
                $goals = $lnameg + $row['goals'];
                $assists = $lnamea + $row['assists'];
                $point = $lnamep + $row['points'];
                mysql_query("UPDATE `2008-2009` SET points='$point', gp='$gp', goals='$goals', assists='$assists' WHERE lname='$lname'") or die(mysql_error());
                print " The players have been succesfuly updated. <a href='http://aravinthan.x10hosting.com/English/hockey/myteamscorers.php?sort=p'> View Scorers </a>";
               }
         }
  }

?>
</div>
<!-- Content End -->
<!-- Left Navigation -->
<?php include("../../include/leftnav.php"); ?>
<!-- Left Navigation End -->
<div style="clear: both;"> </div>
</div>
<div id="bottom"> </div>
<!-- Footer -->
<?php include("../../include/footer.php"); ?>
<!-- Footer End -->
</div>
</body>
</html>

And when I want to test it, I enter the numbers in the form.php file well but I get this error when I reach formprocess.php:
HTTP 500 Internal Server Error

Thanks for your help,
Ara
 
Last edited by a moderator:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Modify that to hide your mysql username and password in the mysql_connect() call.

I'll edit this soon to answer your question. Although a 500 error with php is unusual. I doubt the error is in your code.

***

Well, aside from several typos and some other possible low-level issues, there's nothing that should cause a 500 error. Do you use any .htaccess files? If so, post them. Most 500 errors with php are caused by an error in a .htaccess file. You don't need to post any that were there when you first got your account, though, unless you modified them.
 
Last edited:

Aravinthan

New Member
Messages
68
Reaction score
0
Points
0
No I dont use any .htaccess file....
WEll I dont get get that 500 error any more. But my formprocess.php page is blank, well the code stays blank. No php echo() gets called. But except the coding everything else is displayed.

***********
I look at the code and I know that it looks really noob, but I just cant find a way to make it better. If you can help me make it better, it would be really nice.....
***********
And there is a comment script that worked 2 days ago that isnt working anymore:
http://aravinthan.x10hosting.com/English/hockey/hockey.php
There should be a comment form which isnt being showed.....
and the rest of the page neither...
here is the code that the tutorial told me to put:
Code:
<?php
$page_id = "1"; // for example
include("comments/comments_show.php");
include("comments/comments_form.php");
?>
Of course there is the rest of the pages that has been hosted.
So the comments_show.php pages is shown, but the rest is ommited, the rest of my page too. Any one know why?
Thanks for your help,
Ara
 
Last edited:

Aravinthan

New Member
Messages
68
Reaction score
0
Points
0
Ok,
here is the page with the include in it:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<title>Aravinthan, Sivaneswaran</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../style.css" />
</head>
<body>
<div id="wrap">
<div id="header">
<h1><a href="#">Aravinthan Sivaneswaran</a></h1>
<h2>My Personal Website</h2>
</div>
<!-- Top Navigation -->
<?php include("../include/topnav.php"); ?>
<!-- Top Navigation End -->
<!-- Conteant -->
<div id="content">
<div class="right">
<h2>Hockey</h2>
<br /><br />
<h2>January 21</h2>
<hr />
<br /><br />
We just passed the mid-way season of the <a href="[URL]http://nhl.com">NHL</a[/URL]> and there has been some suprises. The biggest suprise I would say is the fact that Bruins are leading the Eastern Conference.<br /><br />
At the beginning of the year, almost all of us tought it would be a tight race for the 1st spot in the Eastern Conference between <a href="[URL="http://www.canadiens.com">Montreal"]www.canadiens.com">Montreal[/URL] Canadiens</a>, <a href="[URL]http://capitals.nhl.com/">Washington[/URL] Capitals</a> and the <a href="[URL]http://penguins.nhl.com/">Pittsburgh[/URL] Penguins</a>.<br /><br />
We were right for 2 of the 3 teams. But we complety were wrong with the Penguins. The Penguins are currently 10 in the Eastern Conference, with 50 points in 48 games which is 21 points less than the <a href="[URL]http://bruins.nhl.com/">Boston[/URL] Bruins</a> who is suprsingly in the top of the standings.<br /><br />
The Capitals are doing pretty well with 63 points in 48 games, which is worth for the 2nd place. Follwing closely is the <a href="[URL]http://rangers.nhl.com/">New[/URL] York Rangers</a> with 60 points in 48 games. <br /><br />
The Habs are ranked 4th with 60 points in 45 games.
<br /><br />
<hr />
<h2>Sources / Intersting Links</h2>
<ul>
<li><a href="[URL]http://nhl.com">National[/URL] Hockey League(NHL)</a></li>
<li><a href="[URL]http://hockeybuzz.com">HockeyBuzz[/URL]( Trade Rumors)</a></li>
<li><a href="[URL]http://rds.ca">Reseau[/URL] Des Sports(RDS in French)</a></li>
</ul>
<br /><br />
<?php
$page_id = "1"; // for example
include("comments/comments_show.php");
include("comments/comments_form.php");
?>
<br /><br />
Thanks for visiting my site and enjoy your stay,
Ara
</div>
<!-- Content End -->
<!-- Left Navigation -->
<?php include("../include/leftnav.php"); ?>
<!-- Left Navigation End -->
<div style="clear: both;"> </div>
</div>
<div id="bottom"> </div>
<!-- Footer -->
<?php include("../include/footer.php"); ?>
<!-- Footer End -->
</div>
</body>
</html>
comments_form.php:
Code:
<?php
// edit form style ONLY in the HTML section enclosed in comment tags below
include("includes/comments-config.php");
if ($commoff != 1) {
?>
<form action="comments/comments_process.php" method="post" style='margin-top:10px;'>
<?php
// get the page ID and URL and add to form as required inputs
$ret_url = "http://". $_SERVER['SERVER_NAME']. $_SERVER['REQUEST_URI'];
echo "<input type='hidden' name='ret_url' value='". $ret_url. "'/>"; 
echo "<input type='hidden' name='page_id' value='" .$page_id. "' />";
?>
<!--form style is taken from your page style - you MAY edit below here-->
<table cellpadding="3" cellspacing="1" style="border:1px dotted #666;">
<tr><td><p><?php echo $your_name;?></p></td><td align='right'><input type="text" name="name" size="24" maxlength="40" /></td></tr>
<tr><td><p><?php echo $your_location;?></p></td><td align='right'><input type="text" name="locn" size="24" maxlength="40"/></td></tr>
<?php
// this section provides the countries drop-down if 'show flags' is active
if ($show_flags == 1) { include("includes/show-countries.php"); }
?>
<?php
// this section provides a 'rating' dropdown input if 'art_rating' is active
if ($art_rating == 1) { include("includes/show-ratings.php"); }
?>
<tr><td colspan="2"><p><?php echo $your_comments;?></p></td></tr>
<tr><td colspan="2"><textarea cols="35" rows="5" name="comments"></textarea></td></tr>
<?php
// this section provides a captcha image and input if 'captchas' is active
if ($captchas == 1) {
   echo "<tr><td><p>Security check *</p><img src='comments/captcha/captcha_image.php' alt='security image' border='0'/></td>";
   echo "<td valign='top' align='right'><input type='text' name='secure_match' size='6' style='background-color:#eee;'/></td></tr>";
}
?>
<tr><td>&nbsp;</td><td align='right'>
<input style="margin:2px; background-color:#9999cc;" type="submit" name="submit" value="<?php echo $form_submit;?>" />
</td></tr></table>
</form>
<!--do not edit below here-->
<?
}
?>
 

Aravinthan

New Member
Messages
68
Reaction score
0
Points
0
comments_show.php:

Code:
<?php

/************************************************************************************

Page Comments - Written by Andy Bowers | http://www.halfadot.com | andy@halfadot.com

Version 6.0 - release date 2008-02-28 [Original Version 1 release 2003-11-28]

You are free to use this script as long as the credits and notes are not removed.  If

you intend to distribute this script, make sure to include all of the files from the

original zip package.  Your use of this script is subject to the terms of the license

included in the zipped package as license.txt, and constitutes acceptance thereto.

Please e-mail me with any questions or comments - I may even respond :)

*/

/***********************************************************************************

There is no need to edit ANYTHING below this comment.  Almost EVERYTHING you need

to edit is contained in the comments-config.php file and comments-lang.php file. 

PLEASE READ THE DOCUMENTATION FILE!

************************************************************************************/

include("includes/comments-config.php"); // configuration parameters package

include("includes/comments-lang.php"); // language/words package

$comm_page = is_numeric($_GET['comm_page']) ? $_GET['comm_page'] : 1;

if ($comm_page<1) {

 $comm_page = 1;

}

// Figure out the limit for the query based on the current page number. 

$from = $comm_page * $comment_limit - $comment_limit;

include("includes/db_conn.php"); // connect to host and select db

mysql_connect($db_host, $db_user, $db_pass) or die("Connection Error: ". mysql_error());

mysql_select_db($db_name);

// construct page query to find out how many matches

$result=mysql_db_query($db_name,"select count(*) from $db_table WHERE page_id='$page_id' AND is_approved = '1'");

$count=mysql_result($result,0,"count(*)");

$total_pages = ceil($count / $comment_limit);

// and the average rating is ...

$query = "SELECT AVG(rating) from $db_table WHERE page_id='$page_id' AND is_approved = '1' AND rating>'0'";

$result = mysql_query($query) or die("error ". mysql_error(). " with query ".$query);

$row = mysql_fetch_array($result);

$av_rating = number_format($row['AVG(rating)'],2);

// construct page query to find out how many matches

$query = "SELECT * from $db_table WHERE page_id = '$page_id' AND is_approved = '1' ORDER by dated DESC LIMIT $from, $comment_limit";// what matches THIS page?

$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); 

// skip output if no comments exist

if (!$count) {

 echo "<p style='". $num_style. "'>". $no_comments. "</p>";

} else {

 echo "<p style='". $num_style. "'>". $comments_to_date. $count. $this_is_page. $comm_page. $page_of_page. $total_pages. ". ";

 if (($av_rating>0) && ($art_rating==1)) {

    $stars = 5 * round($av_rating/0.5);

    echo $average_rating. "<img src='comments/images/stars/stars_". $stars. ".gif' alt=''/>";

 }

 echo "</p>";

 // output comments

 echo "<table cellpadding='0' cellspacing='0' width='100%' border='0' align='center'>";

 while ($myrow = mysql_fetch_array($result)) // loop through all results

 { 

  $style = $style == $ro1 ? $ro2 : $ro1; 

  echo "<tr bgcolor='". $style. "'>";

  echo "<td><p style='". $comm_style. "'><strong>";

  if (!$myrow['name']) {

   echo $unknown_poster;

  } else {

   echo $myrow['name'];

  }

  echo "&nbsp;&nbsp;&nbsp;";

  if (!$myrow['location']) {

   echo $unknown_location;

  } else {

   echo $myrow['location'];

  }

  if ($show_flags == 1) {

   $flag_image = "comments/images/flags/". $myrow['flag']. ".gif";

   if (file_exists($flag_image)) {

    $size = getimagesize($flag_image);

    echo "&nbsp;<img src='". $flag_image. "' ". $size[3]. " alt=''/>";

   }

  }

  echo "</strong></p></td>";

  echo "<td align='right'><p style='". $comm_style. "'>";

  niceday($myrow['dated']);

  if (($art_rating==1) && ($myrow['rating']>0) && ($visitor_rating==1)) {

     $star_img = "comments/images/stars/stars_". 10*$myrow['rating']. ".gif";

     $size = getimagesize($star_img);

     echo "&nbsp;<img src='". $star_img. "' ". $size[3]. " alt=''/>";

  }

  echo "</p></td></tr>";

  echo "<tr bgcolor='". $style. "'>";

  echo "<td colspan='2' style='border-bottom:1px dotted ". $space_color. ";'><p style='". $comm_style. "'>";

  $comments = stripslashes($myrow['comments']);

  if (strlen($comments)>$maxshow_comments) {

     $comments = substr($comments,0,$maxshow_comments). "... <a href='comments/showmore.php?id=". $myrow['id']. "'>". $show_more. "</a>&nbsp;<strong>&raquo;</strong>";

  }

  echo nl2br($comments);

  if ($myrow['admin_comment']) {

   echo "<br/><br/>". $admin_comment. "&nbsp;<span style='color:#c30;'><em>". $myrow['admin_comment']. "</span></em>";

  } 

  echo "</p></td></tr>\n";

 }

 // loop done

 echo "</table>\n";

}

// Pagination magic (of sorts)

if ($total_pages>1) {

   echo "<p><br/>Page:&nbsp;";

   for ($z=-5; $z<6;$z++) {

    $dapage = $comm_page+$z;

    if (($dapage>0) && ($dapage<=$total_pages)) {

     if ($dapage==$comm_page) {

      echo "-". $dapage. "-";

     } else {

      echo "<a class='pagelink' href='". $_SERVER['PHP_SELF']. "?comm_page=". $dapage. "'>&nbsp;". $dapage. "&nbsp;</a>";

     }

     echo "&nbsp;&nbsp;";

    }   

   }

   echo "</p>";

}

echo "<br/><a href='http://www.digitalmidget.com/php_noob' target='_blank'><img src='comments/images/credits.gif' border='0' alt=''/></a><br/>";

?>

Thanks for your help,

Ara
 
Top