1
I’m having trouble with my CRUD. My code searches in BD and returns me the data on the screen correctly, the problem that when I saved, it does not update the BD and also does not display any error message.
Follow the code of the page of displays the data:
<?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>
Page where you send the data
$cod_time = $_GET["cod_time"];
$logo = $_POST["logo"]; $name = $_POST["name"]; $estadio = $_POST["estadio"]; $presidente = $_POST["presidente"]; $endereco = $_POST["address"]; $cod_city = $_POST["cod_city"]; $phone = $_POST["phone"]; $email = $_POST["email"]; $site = $_POST["website"];
ini_set( 'display_errors', true ); error_reporting( E_ALL );
$connection = mysql_connect("localhost","root","usbw"); if (!$connected) die ("Connection error with localhost, the following error occurred -> ".mysql_error()); mysql_select_db('internet systems', $connection);
$res= mysql_query ("update time set logo='$logo',name='$name',stadium='$stadium',president='$president',address='$address',cod_city='$cod_town',phone='$phone',email='$email',site='$site' Where cod_time=$cod_time");
if($res)ģ //
echo "Data updated successfully." ;
}These{
echo "Failed to update data.";
}
?>
Have extra quotes at the end of the query.
– Jorge B.
@Pedro Luzio I, unfortunately at the moment I have no way to test because I am at work, I will only be able to test the night. Thanks
– user46438
And it’s got nothing to do with it, how it’s supposed to work.
– Jorge B.
@Jorgeb. Thank you I will pay more attention
– user46438
@Malfus is not at the end of your query is in this answer.
– Jorge B.
It has nothing to do with why? I didn’t understand
– Pedro Luzio
@Pedroluzio as the Malfus has works. Only they are doing an update with the same data that already has in the table. So do not notice anything.
– Jorge B.