0
<?php
include 'menu.php';
echo "<br>";
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include "config.php";

// Get values from form
$IDTrabalho = (isset($_GET['idtrabalho']))? $_GET['idtrabalho'] : '';
$IDCliente = (isset($_GET['idcliente']))? $_GET['idcliente'] : '';
$Descricao=$_POST['Descricao'];
$Quantidade=$_POST['Quantidade'];
$Preço=$_POST['Preço'];
echo"$IDTrabalho"."<br>"."$IDCliente"."<br>"."$Descricao"."<br>"."$Quantidade"."<br>"."$Preço"."<br>";

// Insert data into mysql
$sql="INSERT INTO materiais(IDTrabalho, IDCliente, Descricao, Quantidade,Preço)VALUES('$IDTrabalho', '$IDCliente', '$Descricao', '$Quantidade', '$Preço')";
$result=mysql_query($sql) or die ("<img src='imagens/erro.gif' width='32' height='32' alt=''/>Não foi possível realizar a consulta ao banco de dados");
echo "<img src='imagens/sucesso.gif' width='32' height='32' alt=''/>";
echo "<br>O trabalho foi inserido com sucesso!<br>";
?>
</body>
</html>
echo"$IDTrabalho"."<br>"."$IDCliente"."<br>"."$Descricao"."<br>"."$Quantidade"."<br>"."$Preço"."<br>";

This echo gives me all the variables, just to make sure that they are coming to this page and they are, I tested it and they are correct.
My problem is at

$result=mysql_query($sql) or die ("<img src='imagens/erro.gif' width='32' height='32' alt=''/>Não foi possível realizar a consulta ao banco de dados");

It always dies on this query and I can't seem to understand why, the database stuff seems to be alright. I am using WAMPSERVER 2.0 if that is of any help.
Any advice would be much appreciated, thanks :)

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by haoth
0

or die ? what ? and what is this after or die ? .... What is the concept do you want an image to be displayed if you can't connect to database?

1

Even though the encoding is utf-8, your form field contains a cedilla, which may cause a problem:

$_POST['Preço']

Try changing this to $_POST. ALso your variables may benefit from using non-accented characters.

I really don't know whether this would cause a problem. My first language also involves a lot of accented chars, but I try to avoid using them in variable/constant and function names. As these names aren't displayed, it shouldn't make any difference to your site.

0

or die ? what ? and what is this after or die ? .... What is the concept do you want an image to be displayed if you can't connect to database?

Yes that was the idea :P But I got it to work ! :D

Even though the encoding is utf-8, your form field contains a cedilla, which may cause a problem:

PHP Syntax (Toggle Plain Text)

1.
$_POST

$_POST

Try changing this to $_POST. ALso your variables may benefit from using non-accented characters.

I really don't know whether this would cause a problem. My first language also involves a lot of accented chars, but I try to avoid using them in variable/constant and function names. As these names aren't displayed, it shouldn't make any difference to your site.

Thanks a lot for the help, that was really the problem, both in the database and the form. Now it's working wonders :D

Thank you for all the support :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.