[AJUDA] Alguem q saiba programar em PHP?

Tens que mostrar a pag "produtos.php" aqui a malta para o pesssoal perceber o que se passa na linha 47.. xD
 
Tens que mostrar a pag "produtos.php" aqui a malta para o pesssoal perceber o que se passa na linha 47.. xD


<?php require_once('../Connections/local.php');
include 'var.php';


if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}





$lista = $_GET['lista'];
$ad = $_GET['ad'];
$del = $_GET['del'];
$id = $_GET['id'];
$ed = $_GET['ed'];
$preco = $_GET['preco'];
$descricao = $_GET['descricao'];
$detalhes = $_GET['detalhes'];
$precompra = $_GET['precompra'];
$quantidade = $_GET['quantidade'];
$tipo = $_GET['tipo'];
$outras = $_GET['outras'];
$test = $_GET['test'];

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Car Tuning</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
a:link {
color: #BEBAB7;
}
a:visited {
color: #BEBAB7;
}
a:hover {
color: #BEBAB7;
}
a:active {
color: #BEBAB7;
}
-->
</style></head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">&nbsp;</td>
<td width="766" valign="top">
<table width="766" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" class="top" height="69" valign="top">
<div class="menu">
<img src="../images/q1.jpg" alt="" align="middle" /><a href="clientes.php">Clientes</a>
<img src="../images/q1.jpg" alt="" align="middle" /><a href="fornecedores.php">Fornecedores</a>
<img src="../images/q1.jpg" alt="" align="middle" /><a href="produtos.php">Produtos</a>
<img src="../images/q1.jpg" alt="" align="middle" /><a href="../index.php">Sair</a>
</div>
</td>
</tr>
<tr>
<td>

<div class="left">
<img src="../images/welcome2.jpg" alt="" />

<table width="10" border="0" cellspacing="0" cellpadding="0" style="margin-top:2px; ">
<tr>
<td >
<a href="produtos.php?lista=1">Listar</a></td>
</tr>
<tr>
<td >
<a href="produtos.php?ad=1">Adicionar</a></td>
</tr>
<tr>
<td >
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></td>
</tr>
<tr>
<td >
<?php if($test== 'Alteração efectuada com sucesso.' || $test== 'Eliminado com sucesso.' || $test == 'Dados inseridos.') { echo $test; }?>
</td>
</tr>
</table>
</div>

</td>
<td >
<table width="500" border="0" cellspacing="0" cellpadding="0" style="margin-top:30px; ">
<tr>
<td valign="top" width="260" class="link2">
<?php
if( $lista == 1){ //if lista
mysql_select_db($database_local, $local);
$query_Recordset1 = "SELECT * FROM produtos ORDER BY descricao ASC";
$Recordset1 = mysql_query($query_Recordset1, $local) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>

<table width="1000" border="0" align="center">
<tr>
<td>Tipo de Produto:</td>
<td>Descrição:</td>
<td>Preço de Venda:</td>
<td>Preço de Compra:</td>
<td>Quantidade:</td>
<td>Detalhes:</td>
<td>Outras:</td>
<td>Apagar:</td>
<td>Editar:</td>
</tr>
<?php do{?>
<tr>
<td><?php echo $row_Recordset1['descricao'];?></td>
<td><?php echo $row_Recordset1['preco'];?></td>
<td><?php echo $row_Recordset1['detalhes'];?></td>
<td><?php echo $row_Recordset1['precompra'];?></td>
<td><?php echo $row_Recordset1['quantidade'];?></td>
<td><?php echo $row_Recordset1['tipo'];?></td>
<td><?php echo $row_Recordset1['outras'];?></td>

<td><a href="<?php echo "produtos.php?del=1&id=".$row_Recordset1['id'];?>">X</a></td>
<td><a href="<?php echo "produtos.php?ed=1&id=".$row_Recordset1['id']."&descricao=".$row_Recordset1['descricao']."&preco=".$row_Recordset1['preco']."&detalhes=".$row_Recordset1['detalhes']."&precompra=".$row_Recordset1['precompra']."&quantidade=".$row_Recordset1['quantidade']."&tipo=".$row_Recordset1['tipo']."&outras=".$row_Recordset1['outras'];?>">X</a></td>
</tr>

<?php } while($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
</table>

<?php mysql_free_result($Recordset1);} //fim if
if( $ed == 1){ //if editar

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "f_ed")) {
$updateSQL = sprintf("UPDATE produtos SET descricao=%s, preco=%s, detalhes=%s, precompra=%s, quantidade=%s, tipo=%s, outras=%s WHERE id=%s",
GetSQLValueString($_POST['ed_descricao'], "text"),
GetSQLValueString($_POST['ed_preco'], "int"),
GetSQLValueString($_POST['ed_detalhes'], "text"),
GetSQLValueString($_POST['ed_precompra'], "int"),
GetSQLValueString($_POST['ed_quantidade'], "int"),
GetSQLValueString($_POST['ed_tipo'], "text"),
GetSQLValueString($_POST['ed_outras'], "text"),

GetSQLValueString($_POST['ed_id'], "int"));

mysql_select_db($database_local, $local);
$Result1 = mysql_query($updateSQL, $local) or die(mysql_error());
AbrirURL('produtos.php?lista=1&test=Alteração efectuada com sucesso.');
}
?>
<form name="f_ed" id = "f_ed" action="<?php echo $editFormAction; ?>" method="POST">

<table width="500" border="0">

<tr>
<td>Nº Produto:</td>
<td><input name="ed_id" type="text" id="ed_id" value="<?php echo $id;?>" ></td>
</tr>
<tr>
<td>Tipo de Produto:</td>
<td><input name="ed_tipo" type="text" id="ed_tipo" value="<?php echo $tipo;?>"></td>
</tr>
<tr>
<td>Descrição:</td>
<td><input name="ed_descricao" type="text" id="ed_descricao" value="<?php echo $descricao;?>"></td>
</tr>
<tr>
<td>Preço de Venda:</td>
<td><input name="ed_preco" type="text" id="ed_preco" value="<?php echo $preco;?>" size="5"></td>
</tr>
<tr>
<td>Preço de Compra:</td>
<td><input name="ed_precompra" type="text" id="ed_precompra" value="<?php echo $precompra;?>" size="5"></td>
</tr>
<tr>
<td>Quantidade:</td>
<td><input name="ed_quantidade" type="text" id="ed_quantidade" value="<?php echo $quantidade;?>" size="3"></td>
</tr>
<tr>
<td>Detalhes:</td>
<td><textarea name="ed_detalhes" id="ed_detalhes"><?php echo $detalhes;?></textarea></td>
</tr>
<tr>
<td>Outras:</td>
<td><textarea name="ed_outras" id="ed_outras"><?php echo $outras;?></textarea></td>
</tr>



<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" value="Editar"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="f_ed">
</form>


<?php }?>
<?php if( $del == 1){
$del_id = $_GET['id'];
mysql_query("DELETE FROM produtos WHERE id ='".$del_id."'");
AbrirURL('produtos.php?lista=1&test=Eliminado com sucesso.');
}?>

<?php if( $ad == 1){


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "f_ad")) {
$insertSQL = sprintf("INSERT INTO produtos (descricao, preco, detalhes, precompra, quantidade, tipo, outras) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ad_descricao'], "text"),
GetSQLValueString($_POST['ad_preco'], "int"),
GetSQLValueString($_POST['ad_detalhes'], "text"),
GetSQLValueString($_POST['ad_precompra'], "int"),
GetSQLValueString($_POST['ad_quantidade'], "int"),
GetSQLValueString($_POST['ad_tipo'], "text"),
GetSQLValueString($_POST['ad_outras'], "text"));

mysql_select_db($database_local, $local);
$Result1 = mysql_query($insertSQL, $local) or die(mysql_error());

AbrirURL('produtos.php?lista=1&test=Dados inseridos.');

}


?>
<form name="f_ad" id = "f_ad" action="<?php echo $editFormAction; ?>" method="POST">

<table width="500" border="0">


<tr>
<td>Tipo de Produto:</td>
<td><input name="ad_tipo" type="text" id="ad_tipo"></td>
</tr>
<tr>
<td>Descrição:</td>
<td><input name="ad_descricao" type="text" id="ad_descricao" ></td>
</tr>
<tr>
<td>Preço de Venda:</td>
<td><input name="ad_preco" type="text" id="ad_preco" size="5"></td>
</tr>
<tr>
<td>Preço de Compra:</td>
<td><input name="ad_precompra" type="text" id="ad_precompra" size="5"></td>
</tr>
<tr>
<td>Quantidade:</td>
<td><input name="ad_quantidade" type="text" id="ad_quantidade" size="3"></td>
</tr>
<tr>
<td>Detalhes:</td>
<td><textarea name="ad_detalhes" id="ad_detalhes"></textarea></td>
</tr>
<tr>
<td>Outras:</td>
<td><textarea name="ad_outras" id="ad_outras"></textarea></td>
</tr>


<tr>
<td>&nbsp;</td>
<td><input name="Submit" type="submit" value="Guardar"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="f_ad">
</form>
<?php

}?>
</td>

</tr>
</table><br />

</td>
</tr>


</table>
</td>
<td width="50%">&nbsp;</td>
</tr>
</table>
</body>
</html>

É esta a pagina dos produtos :D
Mas da.me os mesmos erros nas pagina de clientes e fornecedores :s
 
basicamente ele esta a tentar obter o valor que tens no campo "ad" e n esta a conseguir. Tens na base de dados escrito dessa maneira? o campo da tabela tem exactamente esse nome?
Outra possibilidade é ele estar vazio e da conflito...a que se refere o "ad"?

se o campo na tabela estiver vazio experimenta atribuir um valor qq por defeito e ve o que acontece
 
Last edited:
Pessoal muito obrigado a todos, felizmente já não vou precisar de ajuda! :D

Se quiserem podem apagar o topico*

Mais uma vez obrigado.

Abraço :)
 
Back
Top