Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Gabriel José

Formulário de exc. PHP (Comentário)

Recommended Posts

Alguém poderia por favor comentar todas as linhas de código php e suas funções. Estou com algumas dificuldades para entender o código.



<?php require_once('Connections/conexao.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

if (PHP_VERSION < 6) { // se a versao do php for menor que 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;

}

}


if ((isset($_GET['idLivro'])) && ($_GET['idLivro'] != "")) {

$deleteSQL = sprintf("DELETE FROM livros WHERE idLivro=%s", GetSQLValueString($_GET['idLivro'], "int"));


mysql_select_db($database_conexao, $conexao);

$Result1 = mysql_query($deleteSQL, $conexao) or die(mysql_error()); // Verifica se o comando foi executado com sucesso


$deleteGoTo = "pagina1.php";

if (isset($_SERVER['QUERY_STRING'])) {

$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";

$deleteGoTo .= $_SERVER['QUERY_STRING'];

}

header(sprintf("Location: %s", $deleteGoTo));

}


mysql_select_db($database_conexao, $conexao);

$query_livros3 = "SELECT * FROM livros";

$livros3 = mysql_query($query_livros3, $conexao) or die(mysql_error());

$row_livros3 = mysql_fetch_assoc($livros3);

$totalRows_livros3 = mysql_num_rows($livros3);

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Documento sem título</title>

</head>


<body>

</body>

</html>

<?php

mysql_free_result($livros3);

?>


Compartilhar este post


Link para o post
Compartilhar em outros sites

da onde vc pegou esse codigo?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara, comentar código e funções é muito a se pedir, o que vc pode fazer é pegar as funções ir em php.net e procurar o que não conhece, lá tem todos os detalhes.

 

Quando copiar algo vc deve entender a lógica, mesmo não entendendo de PHP, pela lógica vc deveria entender o que esta acontecendo. Esse código esta super simples, procura o que não entende e ve o que faz.

 

Não entenda meu comentário da pior forma, mas sim como uma forma de te ajudar a aprender.

 

Abraço

 

 

 

 

Alguém poderia por favor comentar todas as linhas de código php e suas funções. Estou com algumas dificuldades para entender o código.
<?php require_once('Connections/conexao.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) { // se a versao do php for menor que 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;
}
}
if ((isset($_GET['idLivro'])) && ($_GET['idLivro'] != "")) {
$deleteSQL = sprintf("DELETE FROM livros WHERE idLivro=%s", GetSQLValueString($_GET['idLivro'], "int"));
mysql_select_db($database_conexao, $conexao);
$Result1 = mysql_query($deleteSQL, $conexao) or die(mysql_error()); // Verifica se o comando foi executado com sucesso
$deleteGoTo = "pagina1.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
mysql_select_db($database_conexao, $conexao);
$query_livros3 = "SELECT * FROM livros";
$livros3 = mysql_query($query_livros3, $conexao) or die(mysql_error());
$row_livros3 = mysql_fetch_assoc($livros3);
$totalRows_livros3 = mysql_num_rows($livros3);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sem título</title>
</head>
<body>
</body>
</html>
<?php
mysql_free_result($livros3);
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.