Jump to content

Recommended Posts

Posted

Boas pessoal tenho uma query onde faz a criação de uma tabela com as colunas.

$query = "CREATE TABLE ['$ProjPais'] (IdLang int NOT NULL AUTO_INCREMENT ,Lang CHAR(30),Pais CHAR(30),PRIMARY KEY (IdLang));";
mysql_query($query) or die('Query "' . $query . '" failed: ' . mysql_error());
header('Location:content.php');

Mas quando a variavel guarda um valor tipo pt-PT não cria a tabela e mostra me a query no form

Cumpz

Posted (edited)

Boas. 1º identa o codigo. [ CODE = PHP] code code code [/code] Tenta assim:

$query = mysql_query("CREATE TABLE `$ProjPais`(
IdLang INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(IdLang),
Lang CHAR(30),
Pais CHAR(30))")  or die('Query "' . $query . '" failed: ' . mysql_error());
header("Location: content.php");

Vê se isto te ajuda.

Cumps.

Edited by joaocasta
  • Vote 1
Posted

O código de criar a tabela e isso ja esta mas a query de apagar uma tabela ainda me esta a dar erro por causa do - .

$query = mysql_query('DROP TABLE IF EXISTS `projetos`.`$ProjPais`') or die(mysql_error());
Posted

Usem a estencao do mysqli*, e' mais segura do que o mysql* que ja' esta' desactualizado e fora de desenvolvimento...

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Posted

Sim é verdade pikax. Eu agora estou a usar PDO, mas como ela estava a usar mysql deixei estar.

projetos é a base de dados?

faz assim:

$query = mysql_query('DROP TABLE IF EXISTS $ProjPais') or die(mysql_error());
Posted

e' um update normal....

UPDATE login SET username = '$name', passw = '$sPass' WHERE id = $id

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Posted (edited)

Aparece este erro:

Query "UPDATE tbLang SET Lang=Portu, Pais=Port, SiglaLang=pt-PTT;" failed: Unknown column 'Portu' in 'field list'

Minha Query:

$id=$_POST['id'];
$query = mysql_query("UPDATE tbLang SET Lang = '$Lang', SiglaLang = '$SiglaLang', Pais='$Pais' WHERE id = $id") or die(mysql_error());
Edited by xhpotterx
Posted

o erro que te esta' a dar e' devido o sql pensar que o Portu e' um campo da coluna em vez de uma string, para isso falta-te as plicas(').

O erro que da' e' da query que postaste?

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Posted

porque que nao comecas a ganhar umas boas praticas de seguranca, entre outros. E comecas a usar o mysqli*, com os Prepared statement

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Posted (edited)

podes submeter a tua solucao, para caso alguem futuramente tenha uma duvida parecida com a tua, ficar mais esclarecido.

Edited by pikax

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Posted

A solução é a do João Casta.

$query = mysql_query("CREATE TABLE `$ProjPais`(

IdLang INT NOT NULL AUTO_INCREMENT,

PRIMARY KEY(IdLang),

Lang CHAR(30),

Pais CHAR(30))") or die('Query "' . $query . '" failed: ' . mysql_error());

header("Location: content.php");

Posted

dizes que tens este erro:

Aparece este erro:

Query "UPDATE tbLang SET Lang=Portu, Pais=Port, SiglaLang=pt-PTT;" failed: Unknown column 'Portu' in 'field list'

Minha Query:

$id=$_POST['id'];
$query = mysql_query("UPDATE tbLang SET Lang = '$Lang', SiglaLang = '$SiglaLang', Pais='$Pais' WHERE id = $id") or die(mysql_error());

depois dizes que a solução é um SQL que não tem nada haver ???

A solução é a do João Casta.

$query = mysql_query("CREATE TABLE `$ProjPais`(
IdLang INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(IdLang),
Lang CHAR(30),
Pais CHAR(30))")  or die('Query "' . $query . '" failed: ' . mysql_error());
header("Location: content.php");

não admira que estivesse complicado ...

IRC : sim, é algo que ainda existe >> #p@p

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.