Log in

View Full Version : PHP Error



Luke
18-08-2008, 09:40 PM
Ok i have this code (I know it is very unsecure i'm just unsure about the error)


<?
ob_start(); # Allows Cookies
include("config.php");
if($logged[username] && $logged[level] == 2){
switch($_GET[action]){
default:
echo("<b><u>Add Download</b></u><br>Here you can add downloads to 1409. Please only post important news, and make sure the image url is correct, and check it once you have posted it");
echo("<form method=\"post\" action=\"add_download.php?action=add_download\">
<p>Please fill out all of the following fields:</p>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td width='117'>Download Title*:</td>
<td width='577'>
<input type='text' name='title' size='50'>
</td>
</tr>
<tr>
<td width='117'>Avatar (40x40)*:</td>
<td width='577'>
<input type='text' name='avatar' size='50'>
</td>
</tr>
<tr>
<td width='117'>Download URL*:</td>
<td width='577'>
<input type='text' name='url' size='50'>
</td>
</tr>
<tr>
<td width='117'>Category*:</td>
<td width='577'>
<select name='categorie'>
<option selected>Choose a Category</option>
<option>Games</option>
<option>Programs</option>
<option>Scripts</option>
<option>misc</option>
</select>
</td>
</tr>
<tr>
<td width='117'>Description*:</td>
<td width='577'>
<textarea name='descrip' cols='50' rows='20'></textarea>
</td>
</tr>
</table>
<p>
<input type='submit' name='Submit' value='Submit'>
</p>
</form>");
break;

case 'add_download':
$title = $_POST[title];
$avatar = $_POST[avatar];
$url = $_POST[url];
$categorie = $_POST[categorie];
$descrip = $_POST[descrip];
$author = $logged[username];
$date = date("F j, Y");//set up the date format
$date2 = mktime();
if($title==NULL||$avatar==NULL||$url==NULL||$categ orie==NULL||$descrip==NULL){
echo("<meta http-equiv=\"Refresh\" content=\"2; URL=add_download.php\"/>You have left a field blank<br><br><b>Please Wait...</b>");
}else{
$sql = "INSERT INTO downloads (title, avatar, url, categorie, descrip, date, author) VALUES ('$title','$avatar','$url', '$categorie', '$descrip', '$date', '$author')";
$result = mysql_query($sql) or die ('Error during the execution of the MySQL query : ' . mysql_error());
echo("<meta http-equiv=\"Refresh\" content=\"2; URL=add_download.php\"/>Your download has successfuly been submitted!<br><br><b>Please Wait...</b>");
}
break;
}else{
echo("You need to be an Administrator to view this!");
}
?>And i get the error
"Parse error: syntax error, unexpected T_ELSE in add_download.php on line 134"

+rep to help

Thanks
Luke

Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks :).

Invent
18-08-2008, 09:50 PM
Try:


<?php

ob_start( );
include( "config.php" );

if( $logged[ 'username' ] && $logged[ 'level' ] == 2 )
{

switch( $_GET[ 'action' ] )
{

default:

echo( "<b><u>Add Download</b></u><br>Here you can add downloads to 1409. Please only post important news, and make sure the image url is correct, and check it once you have posted it" );

echo( "<form method=\"post\" action=\"add_download.php?action=add_download\">
<p>Please fill out all of the following fields:</p>
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td width='117'>Download Title*:</td>
<td width='577'>
<input type='text' name='title' size='50'>
</td>
</tr>
<tr>
<td width='117'>Avatar (40x40)*:</td>
<td width='577'>
<input type='text' name='avatar' size='50'>
</td>
</tr>
<tr>
<td width='117'>Download URL*:</td>
<td width='577'>
<input type='text' name='url' size='50'>
</td>
</tr>
<tr>
<td width='117'>Category*:</td>
<td width='577'>
<select name='categorie'>
<option selected>Choose a Category</option>
<option>Games</option>
<option>Programs</option>
<option>Scripts</option>
<option>misc</option>
</select>
</td>
</tr>
<tr>
<td width='117'>Description*:</td>
<td width='577'>
<textarea name='descrip' cols='50' rows='20'></textarea>
</td>
</tr>
</table>
<p>
<input type='submit' name='Submit' value='Submit'>
</p>
</form>");

break;

case 'add_download':

$title = $_POST[ 'title' ];
$avatar = $_POST[ 'avatar' ];
$url = $_POST[ 'url' ];
$categorie = $_POST[ 'categorie' ];
$descrip = $_POST[ 'descrip' ];
$author = $logged[ 'username' ];

$date = date( "F j, Y" );
$date2 = mktime( );

if( $title == NULL || $avatar == NULL || $url == NULL || $categorie == NULL || $descrip == NULL )
{

echo( "<meta http-equiv=\"Refresh\" content=\"2; URL=add_download.php\"/>You have left a field blank<br><br><b>Please Wait...</b>" );

}
else
{

$sql = "INSERT INTO `downloads` ( `title`, `avatar`, `url`, `categorie`, `descrip`, `date`, `author` ) VALUES ( '". $title ."', '". $avatar ."', '". $url ."', '" $categorie ."', '". $descrip ."', '". $date ."', '". $author ."' )";

$result = mysql_query( $sql ) or die ( 'Error during the execution of the MySQL query : ' . mysql_error( ) );

echo( "<meta http-equiv=\"Refresh\" content=\"2; URL=add_download.php\"/>Your download has successfuly been submitted!<br><br><b>Please Wait...</b>" );

}

break;

}
}
else
{

echo( "You need to be an Administrator to view this!" );

}

?>

Luke
18-08-2008, 09:51 PM
the exact minute you posted i realised my mistake.

Thanks anyway :)
+rep

EDIT: gotta spread, sorry :(

Excellent1
18-08-2008, 09:51 PM
Oops delete mod, fixed.

Want to hide these adverts? Register an account for free!