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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.