I have a problem with my CRUD. My code looks in the DB and returns the data to the screen correctly, the problem that when I save it, it does not update the DB and it also does not display any error messages.
Here is the code for the data page:
<?php
ini_set( 'display_errors', true );
error_reporting( E_ALL );
$conexao = mysql_connect("localhost","root","usbw");
if (!$conexao) die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());
mysql_select_db('sistemas para internet', $conexao);
$cod_time = $_GET["cod_time"];
$sql = "SELECT * FROM time where cod_time=$cod_time";
$q = mysql_query($sql);
while ($resultado = mysql_fetch_array($q))
{
$logo = $resultado["logo"];
$nome = $resultado["nome"];
$estadio = $resultado["estadio"];
$presidente = $resultado["presidente"];
$endereco = $resultado["endereco"];
$cod_cidade = $resultado["cod_cidade"];
$telefone = $resultado["telefone"];
$email = $resultado["email"];
$site = $resultado["site"];
}
?>
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="utf-8">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="span10 offset1">
<div class="row">
<h3>Atualiza Cadastro do Time</h3>
</div>
<form class="form-horizontal" action="recebeupdatetime.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="txtid" value="<?=$cod_time;?>">
<div class="controls">
Logo:<input type="file" name="logo" id="logo" accept="image/*" required="1" value="<?=$logo;?>"><br>
</div>
<div class="controls">
Nome do Time:<input type="text" name="nome" maxlength="40" size="30" required="1" pattern="[A-Z a-z]+$" placeholder="Nome do Time" value="<?=$nome;?>"><br>
</div>
<div class="controls">
Endereço:<input type="text" name="end" maxlength="40" size="30" required="1" placeholder="Endereço" value="<?=$endereco;?>"><br>
</div>
<div class="controls">
Telefone:
<input type="tel" required="required" maxlength="15" name="phone" pattern="\([0-9]{2}\) [0-9]{4,6}-[0-9]{3,4}$" required="1" value="<?=$telefone;?>" placeholder="Telefone"/><br>
</div>
<div class="controls">
Presidente do Time:<input type="text" name="pres" maxlength="40" size="30" required="1" pattern="[A-Z a-z]+$" value="<?=$presidente;?>" placeholder="Presidente do Time"><br>
</div>
<div class="controls">
Site:<input type="text" name="site" maxlength="40" size="30" required="1" placeholder="Site" value="<?=$site;?>"><br>
</div>
<div class="controls">
Email:<input type="email" required="required" class="input-text" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$" value="<?=$email;?>" placeholder="E-mail" /><br>
</div>
<div class="controls">
Estadio:<input type="text" name="est" maxlength="40" size="30" required="1" pattern="[A-Z a-z]+$" value="<?=$estadio;?>" placeholder="Nome do Estadio"><br>
</div>
<div class="controls">
Cidade:<SELECT NAME="cidade" required="1">
<option>Selecione...</option>
<?php
$conexao = mysql_connect("localhost","root","usbw");
if (!$conexao) die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());
mysql_select_db('sistemas para internet', $conexao);
$query1 = "SELECT * FROM cidade ORDER BY cod_cidade, nomecid ASC";
$q1 = mysql_query($query1);
while($dados = mysql_fetch_array($q1))
{
?>
<option value="<?=$dados['cod_cidade'] ?>">
<?=$dados['nomecid'] ?>
</option>
<?php
}
?>
</SELECT><br><br>
</div>
<div class="form-actions">
<input type="submit" name="btnOK" class="btn btn-success" value="Atualizar" >
<a class="btn btn-danger" href="menutime.php">Voltar</a>
</div>
</form>
</div>
</body>
</html>
Where you send the data
$ cod_time = $ _GET ["cod_time"];
$ logo = $ _POST ["logo"]; $ name = $ _POST ["name"]; $ stadium = $ _POST ["stadium"]; $ president = $ _POST ["president"]; $ address = $ _POST ["address"]; $ cod_city = $ _POST ["cod_city"]; $ phone = $ _POST ["phone"]; $ email = $ _POST ["email"]; $ site = $ _POST ["site"];
ini_set ('display_errors', true); error_reporting (E_ALL);
$ connection = mysql_connect ("localhost", "root", "usbw"); if (! $ connection) die ("Error connecting to localhost, the following error occurred ->" .mysql_error ()); mysql_select_db ('internet systems', $ connection);
mysql_query ("update time set logo = '$ logo', name = '$ name', stadium = '$ stadium', president = '$ president', address = '$ address', cod_city = $ cod_time ', phone =' $ phone ', email =' $ email ', site =' $ site 'where cod_time = $ cod_time ");if ($ res) {// echo "Given updated successfully."; } else { echo "Failed to try to update data."; } ? >