PDA

View Full Version : Something wrong...but where?


deathseeker25
02-27-2006, 12:53 AM
Hi, i'm new here in the community and also in PHP programming. I'm enjoying PHP but i have some difficulties on the development of my website.

I hope you can help me.

I may say i have two folders in the ftp server:

- folder 'css' where the css style file is;
- folder 'images' where images are placed;

Then i have index.html file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Revista PROGRAMAR - Portugal-a-Programar</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-color: #006633;
}
-->
</style>
<link href="css/programar.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #006633}
a:link {
color: #006633;
font-weight: bold;
text-decoration: none;
}
a:visited {
color: #006633;
text-decoration: none;
}
a:hover {
color: #009933;
text-decoration: none;
}
a:active {
color: #006633;
text-decoration: none;
}
-->
</style>
</head>

<body>
<table width="753" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td width="9" rowspan="5" valign="top" class="sombra_esquerda"><!--DWLayoutEmptyCell-->&nbsp;</td>
<td height="156" colspan="3" valign="top" bgcolor="#FFFFFF"><img src="images/banner.jpg" width="732" height="156" /></td>
<td width="66" rowspan="5" valign="top" class="sombra_direita"><!--DWLayoutEmptyCell-->&nbsp;</td>
</tr>
<tr>
<td width="208" height="218" valign="top" class="edicoes"><p>&nbsp;</p>
<p><br />
Mar&ccedil;o 2006 </p>
</td>
<td width="11">&nbsp;</td>
<td width="550" rowspan="2" align="left" valign="top" bgcolor="#FFFFFF" class="corpo_ultima"><h3 class="style1">Mar&ccedil;o 2006</h3>
<p><img src="" alt="" width="92" height="112" align="left" style="background-color: #993300" />&nbsp;&nbsp;<strong>Conte&uacute;dos desta edi&ccedil;&atilde;o:</strong></p>
<p>&nbsp;&nbsp;conte&uacute;dos aqui!<br />
<br />
<br />
<br />
<br />
</p>
<h3 class="style1">Download</h3>
<span class="style1"><a href="linkpdf.pdf">.PDF</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="linkzip.zip">.ZIP</a></span><span class="style1"><strong>&nbsp;&nbsp;&nbsp;</strong>&nbsp;<a href="linkrar.rar">.RAR</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="linkgzip.gzip">.GZIP</a><strong><br />
<br />
Total de Downloads:</strong> 11.125<br />
</span><span class="style1"><strong>Media di&aacute;ria:</strong> 129</span></td>
</tr>
<tr>
<td height="185" valign="top" class="pap"><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="9"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="53" colspan="3" valign="middle" bgcolor="#FFFFFF" class="rodape"><p align="left" class="style1">Copyright Portugal-a-Programar 2006</p></td>
</tr>
</table>
</body>
</html>


adicionar_edicao.html is the file that contains the main form:


function mostrar_formulário()
{
global $PHP_SELF;

?>
<form action="edicao_adicionada.php" method=POST>
Edição: <input type="text" name="edição" /><br /><p>
Link:
<input type="text" name="link" /><br /><p>
Comentários:
<textarea name="coment&aacute;rio"></textarea>

<br />
<br />
Url da imagem: <input type="text" name="url_imagem" />
<p>
<input type="hidden" name="etapa" value="resultados"/>
<br /><p>
<input type="submit" value="Submeter dados" />
</form>
<?php
}
?>

<?php

if(empty($_POST['edição'])){
mostrar_formulário();
} else {
include("edicao_adicionada.php");
processar_formulário();
}

?>



edicao_adicionada.php is the file where the output options are programmed (or supposedly):

<?php
function processar_formulário()
{
global $edição;
global $link;
global $comentário;
global $url_imagem;
/* Este ficheiro tem como objectivo inserir registo na base de dados
sobre a edição e o link para a revista*/
if(empty($_POST['edição'])){
echo "<br>Introduza o nome da edição da revista!<br>";
}
if(empty($_POST['link'])){
echo "<br> Introduza o link para o utilizador poder fazer download!<br>!";
}
if(empty($_POST['comentário'])){
echo "<br> Introduza um comentário com as frases de capa!<br>";
}
else{
require("dados_login.php"); //ficheiro com os dados de login

//ligar a base de dados
$ligação= mysql_connect("$server","$utilizador","$password") or die(mysql_error());

//seleccionar a base de dados
mysql_select_db($base_dados,$ligação);

/*estas variaveis guardam os dados inseridos pelo ficheiro principal de registo*/
$edicao = $_POST['edição'];
$link = $_POST['link'];
$comentário=$_POST['comentátio'];
//faz a query a base de dados
$inserção_table_revista = "INSERT INTO revista(edição,link,comentário,url_imagem) values($edicao,$link,$comentário,$url_imagem)";

//armazena o resultado
$resultado = mysql_db_query($base_dados,$inserção_table_revista);

//conta o numero de registos inseridos em principio
$registo_inserido = mysql_affected_rows();

mysql_close($ligação);

echo "Edição adicionada com sucesso!";
}
}
?>

criar_tabelas.php is the file that creates the tables where posts will be placed:

<?php
/*A grande função deste ficheiro é criar as bases de dados necessárias
Em breve adicionarei mensagens no caso de sucesso, etc..*/


//requere o login.php porque é lá que estao armazenados os dados de login
require('dados_login.php');

//ligaçao a base de dados com os dados armazenados no login.php
$ligação = mysql_connect("$server","$utilizador", "$password")
or die("Impossivel ligar á base de dados. Tente mais tarde.");

//seleciona a base de dados
mysql_select_db($base_dados,$ligação);


//cria a tabela revista onde ficarão informaçoes sobre as ediçoes da revista
$cria_tabela_revista = mysql_query("CREATE TABLE revista(
id INT not null AUTO_INCREMENT,
edicao VARCHAR(50),
link VARCHAR(150),
comentário VARCHAR(400),
url_imagem VARCHAR(150),
PRIMARY KEY (id)",$ligação);


//cria a tabela utilizador onde ficará informação sobre os utilizadores com acesso á edição da página
//ou ao back-office da pagina
$cria_tabela_utilizador = mysql_query("CREATE TABLE utilizador(
id INT not null AUTO_INCREMENT,
nome_utilizador VARCHAR(100),
password VARCHAR(15),
PRIMARY KEY(id)",$ligação);

//fecha a base de dados porque aqui ja nao se faz mais nada.
$fechar_base_dados= mysql_close($ligação);

?>

And finally, i have the dados_login.php where the login data is placed:

<?php
$server="localhost";
$utilizador="root";
$password="";
$base_dados="revista_v2";
?>

Where the hell is the problem? <_<

StupidRalph
02-27-2006, 05:48 AM
I see your problem. You didn't ask a question.:thumbsup: Where is the problem you ask? WHAT is the problem I ask. We don't have magic computers that find your problem (except maybe Marek_Mar and fci). I sold mine so I can go to Spring Break.
All jokes aside. It would help you get responses if you were to explain what was going on with the code. How is it behaving is it not creating tables in the database? is it not parsing correctly? etc?

marek_mar
02-27-2006, 08:00 AM
I dunno what doesn't work but if you have PHP in "adicionar_edicao.html" shouldn't it have the extension ".php"?
Also you use some non-standard characters in your function and variable names
mostrar_formulário()
global $edição;
which may or may not be allowed.
The regex for a variable or function name is (and no PHP doesn't use regex to parse the variables :p ):

[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

and I'm not sure if these characters fit.

deathseeker25
02-27-2006, 12:01 PM
I see your problem. You didn't ask a question.:thumbsup: Where is the problem you ask? WHAT is the problem I ask. We don't have magic computers that find your problem (except maybe Marek_Mar and fci). I sold mine so I can go to Spring Break.
All jokes aside. It would help you get responses if you were to explain what was going on with the code. How is it behaving is it not creating tables in the database? is it not parsing correctly? etc?

I'm sorry for omiting the real problem. The problem is that, when i submit the form nothing happens i mean, it is supposed to insert data in the db and it doesn't; it is supposed to echo something in edicao_adicionada.php but it doesn't.

What the hell is wrong there?

I also changed all the variables and the problem is still there...

marek_mar
02-27-2006, 03:44 PM
Do you get any errors?
add

error_reporting(E_ALL);

at the beginning of the code. It will print all errors that occour.

deathseeker25
02-27-2006, 05:34 PM
Do you get any errors?
add

error_reporting(E_ALL);

at the beginning of the code. It will print all errors that occour.

I added and nothing happens again. I tried to withdraw the PHP code from the html code and i've put them into separated files. Then i tried again and it gives me some strange result:

http://www.portugal-a-programar.org/revista/teste_form/adicionar_edicao.php

Just give it a try and see what the result is. :confused:

deathseeker25
02-28-2006, 12:49 PM
Well i changed some things in the code, but it is still not functioning: the echo is outputed in japanese or something and the query to the database does nothing..

edicao_adicionada.php
<?php
function processar_formulário()
{
global $edição;
global $link;
global $comentário;
global $url_imagem;
/* Este ficheiro tem como objectivo inserir registo na base de dados
sobre a edição e o link para a revista*/
if(empty($_POST['edição'])){
echo "<br>Introduza o nome da edição da revista!<br>";
}
if(empty($_POST['link'])){
echo "<br> Introduza o link para o utilizador poder fazer download!<br>!";
}
if(empty($_POST['comentário'])){
echo "<br> Introduza um comentário com as frases de capa!<br>";
}
else{
require("dados_login.php"); //ficheiro com os dados de login

//ligar a base de dados
mysql_connect("localhost","root","") or die(mysql_error());

echo "Ligou-se á base de dados! A identificar a base de dados...";

//seleccionar a base de dados
mysql_select_db($base_dados);

echo "<p>Base de dados selecionada com sucesso!A inserir dados na BD...</p>";

/*estas variaveis guardam os dados inseridos pelo ficheiro principal de registo*/
$edicao = $_POST['edição'];
$link = $_POST['link'];
$comentário=$_POST['comentário'];
$url_imagem=$_POST['url_imagem'];
//faz a query a base de dados

$query=mysql_query("INSERT INTO revista(edicao,link,comentário,url_imagem) VALUES('$edicao','$link','$comentário','$url_imagem')") or die("MySQL login error:".mysql_error());

echo $query;
//conta o numero de registos inseridos em principio
$registo_inserido = mysql_affected_rows();

mysql_close();

echo "Edição adicionada com sucesso!";

}
}
processar_formulário();
?>

adicionar_edicao.php:

<?
function mostrar_formulário()
{
global $PHP_SELF;

?>
<form action="edicao_adicionada.php" method=POST>
Edição: <input type="text" name="edição" /><br /><p>
Link:
<input type="text" name="link" /><br /><p>
Comentários:
<textarea name="comentário"></textarea>

<br />
<br />
Url da imagem: <input type="text" name="url_imagem" />
<p>
<input type="hidden" name="etapa" value="resultados"/>
<br /><p>
<input type="submit" value="Submeter dados" />
</form>
<?php
}
?>

<?php

if(empty($_POST['edição'])){
mostrar_formulário();
} else {
include("edicao_adicionada.php");
processar_formulário();
}

You can see the result right here:

www.portugal-a-programar.org/revista/teste_form/adicionar_edicao.php

StupidRalph
03-01-2006, 06:45 AM
Your link is broken. Have you tried sectioning your code off so you can determine what parts work and what parts do not? And actually, from what I read and can make out of it. edicao_adicionada.php looks okay I THINK. Have you tried the basic troubleshooting yet? Have you tested your server to make sure it will run PHP scripts?