samuca Posted August 19, 2006 at 01:32 PM Report #45243 Posted August 19, 2006 at 01:32 PM Ainda sou iniciante no PHP e não percebo quase nada disto, tou a fazer uma página onde são inserido vários dados numa tabela da base de dados. Já fiz isto em páginas diferentes e exatamente com a mesma sintax e funcionou mas nesta página não funciona. Depois de fazer a ligação à base de dados tenho o seguinte código: //Insere os dados na BD if(($url != "") and ($name != "")){ $insert = "INSERT INTO links (url,name,group) VALUES ('$url','$name','$group')"; $result = mysql_query($insert, $conexao); if (!$result) { die('Invalid query: ' . mysql_error()); } } A função mysql_error devolve: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group) VALUES ('http://www.sapo.pt','Portugal','Países')' at line 1" Se puder ajudar, é que eu já tentei de outras maneiras e não chego lá... samuca.freehostia.com
skin Posted August 19, 2006 at 01:51 PM Report #45246 Posted August 19, 2006 at 01:51 PM <?php $dbh=mysql_connect ("localhost", "username", "password") or die ('Não foi possível conectar a base de dados devido a: ' . mysql_error()); mysql_select_db ("basededados"); mysql_select_db ("links"); if (isset($_POST['Submit'])) { $url = $_POST['url']; $name = $_POST['name']; $group = $_POST['group']; $verificar = mysql_query("SELECT * FROM basededados.links WHERE url = '$url'") or die(mysql_error()); if (mysql_num_rows($verificar) > 0) { $mensagem = "<b>$url</b> já existe!"; } else { mysql_query("INSERT INTO links ( url , name , group ) VALUES ('$url', '$name', '$group');"); $mensagem = "<b>$url</b>, <b>$name</b> e <b>$group</b> foram inseridos com sucesso!"; } } ?> Utiliza este código que ele também verifica se tens já essa entrada na base de dados. Só tens de lhe por o nome de utilizador, a password e a base de dados em que se encontra. Se precisares de mais alguma coisa diz 😄 Our lives begin to end the day we become silent about things that matter - Martin Luther King
samuca Posted August 19, 2006 at 02:18 PM Author Report #45250 Posted August 19, 2006 at 02:18 PM Obrigado skin pela ajuda, já consegui resolver o problema, mas não sei explicar como. Sei que fui ao phpMyAdmin e mudei o nome do campo "group" da tabela. Tinha ali uma confusão com o nome do campo e uma variavel com o mesmo nome. samuca.freehostia.com
skin Posted August 19, 2006 at 02:19 PM Report #45251 Posted August 19, 2006 at 02:19 PM De nada. E o código ajudou? Our lives begin to end the day we become silent about things that matter - Martin Luther King
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now