← Desenvolvimento

Problema com script

Lida 2396 vezes

Offline

HotFoX 
Membro
Mensagens 8 Gostos 0
Troféus totais: 19
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 4 Level 3 Level 2 Level 1 First Post Karma Tenth year Anniversary

Boas pessoal, eu tenho um problema com um script que estou a traduzir e a aperfeiçoar!

Quando tento adicionar um ficheiro, dá-me o seguinte erro:

Parse error: syntax error, unexpected T_CATCH, expecting T_STRING in C:\xampp\htdocs\filecabinet\admin\add_file.php on line 5


E A Aqui vai o ficheiro add_file.php
Código: [Seleccione]

<?php
session_start
&#40;&#41;;
include &#40;"check.php"&#41;;

function catch&#40;$pvar&#41; &#123;
$x stripslashes&#40;$_POST[$pvar&#93;&#41;;
$x str_replace&#40;"'",''',$x&#41;;
$x str_replace&#40;"\"",'&quot;',$x&#41;;
return $x;
&
#125;

$name = catch&#40;name&#41;;
$cat = catch&#40;category&#41;;
$author = catch&#40;author&#41;;
$version = catch&#40;version&#41;;
$short = catch&#40;short_description&#41;;
$long = catch&#40;long_description&#41;;
$screen = catch&#40;screenshot&#41;;
$file = catch&#40;download&#41;;

if &#40;!$name&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a name!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;!$cat&#41; &#123;
echo "<html><head><script>alert&#40;'You did not select a category!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;!$author&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter an author!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;!$short&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a short description!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;!$long&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a long description!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;!$file&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a file download URL!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;$file == "http&#58;//"&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a file download URL!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;

if &#40;!$version&#41; &#123; $version = "Not Available"; &#125;
if &#40;!$screen&#41; &#123; $screen = "na"; &#125;
if &#40;$screen == "http&#58;//"&#41; &#123; $screen = "na"; &#125;
$date date&#40;"d/m/y"&#41;;

include &#40;"../db.php"&#41;;
$sql_name_check mysql_query&#40;"SELECT name FROM downloads WHERE name='$name'"&#41; or die &#40;mysql_error&#40;&#41;&#41;;
$name_check mysql_num_rows&#40;$sql_name_check&#41;;

if &#40;$name_check == 1&#41; &#123;
echo "<html><head><script>alert&#40;'File name is already in use!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
else &#123;
mysql_query&#40;"INSERT INTO downloads &#40;cat, name, author, version, short_description, long_description, url_screenshot, url_download, date&#41; VALUES&#40;'$cat', '$name', '$author', '$version', '$short', '$long', '$screen', '$file', '$date'&#41;"&#41; or die &#40;mysql_error&#40;&#41;&#41;;
echo "<script>alert&#40;'File $name added!'&#41;</script>";
include &
#40;"addfile.php"&#41;;
&#125;
?>



Preciso de Ajuda urgentemente!

Obrigado desde Já!

Cumrpimentos ;)
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Bem, tem vário erros...
Não podes utilizar uma função chamada catch, essa "função" está reservada para programação orientada por objectos em PHP 5.

Tenta assim
Código: [Seleccione]
<?php 
session_start
&#40;&#41;; 
include &#40;"check.php"&#41;; 

function filtrar&#40;$pvar&#41; &#123; 
$x stripslashes&#40;$pvar&#41;; 
$x str_replace&#40;"'",'"',$x&#41;; 
$x str_replace&#40;"\"",'&quot;',$x&#41;; 
return $x
&
#125; 

$name filtrar&#40;$_POST['name'&#93;&#41;; 
$cat filtrar&#40;$_POST['category'&#93;&#41;; 
$author filtrar&#40;$_POST['author'&#93;&#41;; 
$version filtrar&#40;$_POST['version'&#93;&#41;; 
$short filtrar&#40;$_POST['short_description'&#93;&#41;; 
$long filtrar&#40;$_POST['long_description'&#93;&#41;; 
$screen filtrar&#40;$_POST['screenshot'&#93;&#41;; 
$file filtrar&#40;$_POST['download'&#93;&#41;; 

if &#40;!$name&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not enter a name!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
if &#40;!$cat&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not select a category!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
if &#40;!$author&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not enter an author!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
if &#40;!$short&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not enter a short description!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
if &#40;!$long&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not enter a long description!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
if &#40;!$file&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not enter a file download URL!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
if &#40;$file == "http&#58;//"&#41; &#123; 
echo "<html><head><script>alert&#40;'You did not enter a file download URL!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 

if &#40;!$version&#41; &#123; $version = "Not Available"; &#125; 
if &#40;!$screen&#41; &#123; $screen = "na"; &#125; 
if &#40;$screen == "http&#58;//"&#41; &#123; $screen = "na"; &#125; 
$date date&#40;"d/m/y"&#41;; 

include &#40;"../db.php"&#41;; 
$sql_name_check mysql_query&#40;"SELECT name FROM downloads WHERE name='$name'"&#41; or die &#40;mysql_error&#40;&#41;&#41;; 
$name_check mysql_num_rows&#40;$sql_name_check&#41;; 

if &#40;$name_check == 1&#41; &#123; 
echo "<html><head><script>alert&#40;'File name is already in use!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>"
exit&
#40;&#41;; 
&#125; 
else &#123; 
mysql_query&#40;"INSERT INTO downloads &#40;cat, name, author, version, short_description, long_description, url_screenshot, url_download, date&#41; VALUES&#40;'$cat', '$name', '$author', '$version', '$short', '$long', '$screen', '$file', '$date'&#41;"&#41; or die &#40;mysql_error&#40;&#41;&#41;; 
echo "<script>alert&#40;'File $name added!'&#41;</script>"
include &
#40;"addfile.php"&#41;; 
&#125; 
?>


Nota: o que postei vai resolver os erros, nada mais... em termos de segurança, isso já será outra história...
Offline

HotFoX 
Membro
Mensagens 8 Gostos 0
Troféus totais: 19
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 4 Level 3 Level 2 Level 1 First Post Karma Tenth year Anniversary

Obrigado! Ja resolvi o Problema!

Muito obrigado pela dica!
;)
Offline

HotFoX 
Membro
Mensagens 8 Gostos 0
Troféus totais: 19
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Level 4 Level 3 Level 2 Level 1 First Post Karma Tenth year Anniversary

Tenho mais uma Duvida, ja estive a ver o codigo, mas isto vai mecher com mysql, e como eu nao pesco muito de PHP + MySQL, gostava que me dessem aqui uma ajudinha.....

eu tenho o ficheiro addfile.php, que é simplesmente um formulário:

Código: [Seleccione]

<?php
session_start
&#40;&#41;;
include &#40;"check.php"&#41;;
?>

<html>
<head>
<title>BadBlue</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<b>Adicionar Categoria</b>
<br><form name="adcat" action="add_cat.php" method="post">
Nome: <input type="text" name="name" size="30" maxlength="50">
<br><br>
Descrição: <input type="text" name="descricao" size="30" maxlength="150">
<br><br>
<input type="submit" value="Adicionar Categoria">
</form>
</body>
</html>


e depois tenho o ficheiro que este form trabalha, e o que faz realmente a função de adicionar um categoria...

Código: [Seleccione]

<?php
session_start
&#40;&#41;;
include &#40;"check.php"&#41;;
include &#40;"../db.php"&#41;;

$name $_POST['name'&#93;;
$name stripslashes&#40;$name&#41;;
$des $_POST['description'&#93;;
$des stripslashes&#40;$des&#41;;

if &#40;!$name&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a category name!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
if &#40;!$des&#41; &#123;
echo "<html><head><script>alert&#40;'You did not enter a category description!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;

$sql_cat_check mysql_query&#40;"SELECT name FROM categories WHERE name='$name'"&#41; or die &#40;mysql_error&#40;&#41;&#41;;
$cat_check mysql_num_rows&#40;$sql_cat_check&#41;;

if &#40;$cat_check == 1&#41; &#123;
echo "<html><head><script>alert&#40;'Category name is already in use!'&#41;</script></head><body onload=javascript&#58;history.go&#40;-1&#41;> </body></html>";
exit&
#40;&#41;;
&#125;
else &#123;
$sql mysql_query&#40;"INSERT INTO categories &#40;name, description&#41; VALUES&#40;'$name', '$des'&#41;"&#41;;
echo "<script>alert&#40;'Category $name added!'&#41;</script>";
include &
#40;"addcat.php"&#41;;
&#125;
mysql_close&#40;&#41;;
?>




A questão é: Este pequeno script apenas adiciona CATEGORIAS, e eu queria saber, se é possível fazer uma Alteração para que crie tambem SUB-CATEGORIAS!


Desde Já Obrigado!

Espero Resposta :)

Cumprimentos ;)
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Respondento à tua questão.... sim é.