3
In summary through PHP below I can send the specific information already recorded in the column in the BD, only that, in addition to just "sending" the data there, I would like a function that changes such information without the page being changed. I have an idea how to do this using the following code:
if ($action == 'okay') {
$conexao = mysql_query("update settingsMDP set name='$name', version='$version', startacp='$startacp' WHERE id='1'") or die ("Eita.. Deu errado!");
}
If they go to see, if the form action
is "okay" then, it runs the UPDATE, but... This does not occur I don’t know why.
This is the PHP.
<?php
// definições de host, database, usuário e senha
$server = "";
$usuario = "";
$banco = "";
$senha = "";
// conecta ao banco de dados
$conexao = mysql_connect($server, $usuario, $senha);
$conexao = mysql_select_db("$banco",$conexao);
if(!$conexao) {
echo mysql_error();
exit;
}
$conexao = mysql_query("select * from settingsMDP");
//********************************************mudei aqui*****************************
$exibe = mysql_fetch_assoc($conexao);
if (empty($_REQUEST['action'])) $action = ''; else $action = $_REQUEST['action'];
if ($action == 'okay') {
$conexao = mysql_query("update settingsMDP set name='$name', version='$version', startacp='$startacp' WHERE id='1'") or die(mysql_error());
}
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Nome do MDP: </td>
<td><input name="name" type="text" id="name" value="<?php echo $exibe["name"]; ?>"></td>
</tr>
<tr>
<td width="100">Versão: </td>
<td><input name="name" type="text" id="name" value="<?php echo $exibe["version"]; ?>"></td>
</tr>
<tr>
<td width="100">Abertura do painel:</td>
<td><input name="start_acp" type="text" id="startacp" value="<?php echo $exibe["startacp"]; ?>"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td><input name="update" type="submit" id="update" value="Salvar"></td>
</tr>
</table>
</form>
When you are developing avoid putting custom errors, change:
or die ("Eita.. Deu errado!");
for :or die(mysql_error());
. Where it comes from$action
? in your form there are 2 fields the same name(name
) I believe one of them should beversion
.– rray
Give a var_dump($action) there, I think the problem is in $action.
– Inkeliz
var_dump? I just edited the code. Is this what you mentioned @Inkeliz? @rray I already modified the custom term. But why is it advisable not to use?
– Robson
Another additional that will not interfere much in the problem. I recommend putting "{" keys out of the variables in the string, thus:
set name='{$name}',
. To help PHP identify them.– KaduAmaral
It would be to see what’s in the $action.
– Inkeliz
With
mysql_error()
you receive the error message from the bank, something likeYou have a syntax error at ......
which is much better than aDeu erro!
that gives you no clue about the mistake.– rray
mysql_* functions have been obsolete since PHP 5.5. Use PDO or mysqli. See http://www.ultimatephp.com.br/php-por-que-nao-utilizar-funcoes-mysql
– Beraldo