Fejl i script
Hej jeg får denne fejl frem når jeg prøver at køre et script:Notice: Undefined index: id in C:\wamp\www\imagevoting\index.php on line 10 Call Stack: 0.0013 736584 1. {main}() C:\wamp\www\imagevoting\index.php:0 Notice: Undefined index: vote in C:\wamp\www\imagevoting\index.php on line 11 Call Stack: 0.0013 736584 1. {main}() C:\wamp\www\imagevoting\index.php:0 Notice: Undefined index: comment_name in C:\wamp\www\imagevoting\index.php on line 18 Call Stack: 0.0013 736584 1. {main}() C:\wamp\www\imagevoting\index.php:0 Notice: Undefined index: comment_text in C:\wamp\www\imagevoting\index.php on line 19 Call Stack: 0.0013 736584 1. {main}() C:\wamp\www\imagevoting\index.php:0 Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\imagevoting\index.php on line 44 Call Stack: 0.0013 736584 1. {main}() C:\wamp\www\imagevoting\index.php:0
Jeg har indsat liner nummer der hvor fejlen er i koden:
<?php
//load configuration
require("config.php");
//connect to database
@mysql_connect($db_server,$db_user) or die("Database server connection failed. Check variables \$db_server, \$db_user and in config.php");
@mysql_select_db($db_name) or die("Selecting database failed. Check variable \$db_name in config.php");
//update votes
(line 10 ) $id = $_POST["id"];
(line 11) $vote = $_POST["vote"];
if(isset($id) && isset($vote)){
@mysql_query("UPDATE $db_table_pictures SET points=points+$vote,votes=votes+1 WHERE id=$id;");
}
//store comment
(line 18) $comment_name = $_POST["comment_name"];
(line 19) $comment_text = $_POST["comment_text"];
if(isset($comment_name) && isset($comment_text) && strlen($comment_name)>2 && strlen($comment_text)>2){
$comment_name = str_replace("<","<",$comment_name);
$comment_name = str_replace(">",">",$comment_name);
$comment_name = stripslashes($comment_name);
$comment_text = str_replace("<","<",$comment_text);
$comment_text = str_replace(">",">",$comment_text);
$comment_text = stripslashes($comment_text);
@mysql_query("INSERT INTO com (id_pic,name,text,date) VALUES({$_POST["show"]},'$comment_name','$comment_text',".time().");");
}
//image to be displayed
if(!isset($_GET["show"]) && !isset($_POST["show"])){
//random image
$ids = array();
$result = @mysql_query("SELECT id FROM $db_table_pictures;");
list($min) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>1 ORDER BY id ASC;"));
list($max) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>1 ORDER BY id DESC;"));
while(list($ids[]) = @mysql_fetch_row($result));
while(true){
( line 44 ) srand((double)microtime()*1000000);
$show = rand($min,$max);
if(array_search($show,$ids)){
break;
}
}
}else{
//specific image
$show = isset($_GET["show"]) ? $_GET["show"] : $_POST["show"];
}
$row = @mysql_fetch_array(@mysql_query("SELECT * FROM $db_table_pictures WHERE id=$show;"));
list($next) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>$show ORDER BY id ASC LIMIT 0,1;"));
//calculate points
if($row["points"] != 0){
$row["points"] = number_format($row["points"]/$row["votes"],2,".","");
}
//next image
if(!$next){
list($next) = @mysql_fetch_row(@mysql_query("SELECT id FROM $db_table_pictures WHERE id>1 ORDER BY id ASC LIMIT 0,1;"));
}
//print header
echo $header;
//print html
?><form action="index.php" method="post">
<table align="center" border="0" cellpadding="2" cellspacing="0">
<tr>
<td rowspan="2">awful</td>
<td rowspan="2" width="10"> </td><?php
//voting form
for($i=1;$i<=$max_points;$i++){
?><td align="center"><?php echo $i; ?></td><?php
}
?><td rowspan="2" width="10"> </td>
<td rowspan="2">awesome</td>
</tr>
<tr><?php
for($i=1;$i<=$max_points;$i++){
?><td align="center"><input type="radio" name="vote" value="<?php echo $i; ?>" onclick="submit();"></td><?php
}
?></tr>
</table>
<input name="show" type="hidden" value="<?php echo $next; ?>">
<input name="id" type="hidden" value="<?php echo $row["id"]; ?>">
</form>
</td>
</tr>
<tr>
<td colspan="2" height="8"> </td>
</tr>
<tr>
<td align="center" colspan="2" height="<?php echo $img_height; ?>"><img alt="" border="0" src="<?php echo $img.$show.$img_format_info; ?>"></td>
</tr>
<tr>
<td colspan="2" height="10"> </td>
</tr>
<tr>
<td valign="top" width="50%">Image from <b><?php echo $row["creator"]; ?></b><br><br><?php echo $row["comment"]; ?><br><br></td>
<td align="right" valign="top" width="50%">Points: <b><?php echo $row["points"]; ?></b> (<?php echo $row["votes"]; ?> votes)<br><br></td>
</tr>
<td colspan="2">
<hr><?php
$result = @mysql_query("SELECT * FROM com WHERE id_pic={$row["id"]} ORDER BY date DESC;");
if(@mysql_num_rows($result) == 0){
?>No comments<?php
}else{
while($row = @mysql_fetch_array($result)){
?><b><?php echo $row["name"]; ?></b> wrote on <?php echo date("m/d/Y",$row["date"]); ?> at <?php echo date("h:i a",$row["date"]); ?>:<br>
<?php echo $row["text"]; ?>
<br><br><?php
}
}
?><hr>
<b>Write a comment:</b>
<form action="index.php" method="post">
<table align="center" border="0" cellpadding="5" cellspacing="0">
<tr>
<td>Your name:</td>
<td><input maxlength="50" name="comment_name" size="30" type="text"></td>
</tr>
<tr>
<td valign="top">Comment:</td>
<td><textarea cols="70" name="comment_text" onkeyup="this.value=this.value.slice(0,<?php echo $comment_size; ?>);" rows="6"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
<input name="show" type="hidden" value="<?php echo $show; ?>">
</form><?php
//print footer
echo $footer;
//close database connection
@mysql_close();
?>
