I can not display the value of SQL

5

I'm trying to start a MySQL database connection and it works, but when I request that PHP display what it has there nothing appears. It's as if the connection to the BD had failed.

<?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");
while($exibe = mysql_fetch_assoc($conexao));
?><?php echo $exibe["name"]; ?>
<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>

Keep in mind that the connection information is correct, if there was not an error, right? Why can not I see the value within the respective fields?

    
asked by anonymous 25.12.2014 / 21:44

1 answer

3

I have changed something that is obviously wrong. I do not know if it will produce the result you expect but at least it shows you where the error is.

You have closed while with ; . He will not keep repeating this way. This command expects a block of other commands to be repeated until the condition is false. You have to define this block with keys. In fact when it's a line does not need to but every good programmer does not care about this and always uses keys to make it easier to catch errors and avoid future maintenance problems.

You probably thought that the line below while with echo was running repeatedly but not.

There may be more errors but I could not find it because I can not test this code.

I hope select in the database is returning something and has a field called name , otherwise we have another problem but this time in the database. Actually by the way the HTML code is, I hope it only returns one line. If you return several, the page will be chaotic.

Can I consider that there will only be one row in the database, or at least that the first one will be relevant in this case? So I think it makes more sense in what seems to be what you want to do. I will change the code considering this and then do not need while more. while would only be necessary if you wanted to read several lines that I do not think is the case.

<?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);
?>

<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>

Then you can create validations for the data and you can update the new data in the database with update .

    
25.12.2014 / 22:07