Jump to content

echo from select query


burge124

Recommended Posts

hi, how can i echo the results of this query into the *** positions outside of the query? thanks

 

<form name="form1" method="post" action="">

  <label>username; **********<br>

  current password;

</label>

  **********<br>

<p>

    <label></label>

  current email; **********</p>

  </form>

<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("questiondb", $con);

 

$result = mysql_query("SELECT * FROM user

WHERE UserName='admin'");

 

while($row = mysql_fetch_array($result))

  {

  echo $row['UserName'];

  echo $row['Password'];

  echo $row['Email'];

  }

 

?>

Link to comment
https://forums.phpfreaks.com/topic/93333-echo-from-select-query/
Share on other sites

you can't...query has to come first:

 

<?php
$con = mysql_connect("localhost","root","")
  or die('Could not connect: ' . mysql_error());
mysql_select_db("questiondb", $con);

$result = mysql_query("SELECT * FROM user WHERE UserName='admin'");

$user= mysql_fetch_array($result)
echo $user['UserName'];
echo $user['Password'];
echo $user['Email'];
?>
<form name="form1" method="post" action="">
  <label>username; <?php echo $user['UserName']; ?>

  current password;
</label>
  <?php echo $user['Password']; ?>

<p>
    <label></label>
  current email; <?php echo $user['Email']; ?><p>
  </form>

hi, it still doesnt work, heres the code i used.... and the output is below the code thanks

 

<?php

$con = mysql_connect("localhost","root","")

  or die('Could not connect: ' . mysql_error());

mysql_select_db("questiondb", $con);

 

$result = mysql_query("SELECT * FROM user WHERE UserName='admin'");

 

while ($user= mysql_fetch_array($result))

echo $user['UserName'];

echo $user['Password'];

echo $user['Email'];

?>

<form name="form1" method="post" action="">

  <label>username; <?php echo $user['UserName']; ?>

 

  current password;

</label>

  <?php echo $user['Password']; ?>

 

<p>

    <label></label>

  current email; <?php echo $user['Email']; ?><p>

  </form>

****************************************************************************************

 

admin

username; current ;

 

current email; admin

username; current ;

 

current email;

Is UserName a unique field? So there is only one user named admin? In that case you don't need a while loop at all. Just run mysql_fetch_array once to get the first entry.

 

Also, when you post code, please use the code button on the toolbar (it's the one with the # sign on it)

use this:

 

<?php
$con = mysql_connect("localhost","root","")
  or die('Could not connect: ' . mysql_error());
mysql_select_db("questiondb", $con);

$result = mysql_query("SELECT * FROM user WHERE UserName='admin'");

$user= mysql_fetch_array($result);
?>
<form name="form1" method="post" action="">
  <lable>Username:</label> <?php echo $user['UserName']; ?><br>
  <lable>Password:</label> <?php echo $user['Password']; ?><br>
  <lable>Email:</label> <?php echo $user['Email']; ?><br>
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.