Forum Moderators: coopster

Message Too Old, No Replies

HTML forms adding selected values

         

paul161

8:54 pm on Jul 2, 2005 (gmt 0)

10+ Year Member



I wrote the script to SELECT two
values email and password from my database a display/echo them in fields in an HTML From. But when I try the fields in the HTML form always remain blank.
Any ideas what wrong with the script?

<?php
$username=ass;
?>
<?php
//Database Information

$dbhost = "******";
$dbname = "****";
$dbuser = "****";
$dbpass = "****";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$result = mysql_query( "SELECT email,password FROM login1 where username='$username'"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); }
while ( $row = mysql_fetch_array($result) )

?>
<from>
<INPUT TYPE="text" NAME="email" VALUE="<?php echo($row["email"] );?>">
<INPUT TYPE="text" NAME="email" VALUE="<?php echo($row["password"] );?>">
</form>

mrnoisy

11:19 am on Jul 3, 2005 (gmt 0)

10+ Year Member



You could try this:


$result="select * from login1 where username='$username'";
$result=mysql_query($result) or die(mysql_error());
$result=mysql_fetch_array($result);

<input type="text" name="email" value="<?php $result[username];?>">
<input type="text" name="email" value="<?php $result[password];?>">

Also check that the database fields actually have entries in them.

And make sure that the variable $username is set.

paul161

11:32 am on Jul 3, 2005 (gmt 0)

10+ Year Member



Added the echo statements to your script and its working fine now thanks.

paul161

12:43 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



I added a new piece of script to UPDATE SQL database using the HTML from but i keep on geting this error message
Error updating: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ';()' at line 1
The new script is
<?php

if ("SUBMIT" == $SUBMIT)
{ $sql = "update Login1 SET " . "password='$password', " . "email='$email' WHERE username='$username';()"; if (mysql_query($sql)) { echo("<P>Info updated.</P>"); } else { echo("<P>Error updating: " . mysql_error() . "</P>"); }}

?>

<?php
$username=ass;
?>
<?php
//Database Information

$dbhost = "localhost";
$dbname = "*******";
$dbuser = "********8";
$dbpass = "****";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$result="select * from login1 where username='$username'";
$result=mysql_query($result) or die(mysql_error());
$result=mysql_fetch_array($result);
?>
<FORM ACTION="<?php echo($PHP_SELF);?>" METHOD=POST>
<input type="text" name="password" value="<?php echo $result[password];?>">
<input type="text" name="email" value="<?php echo $result[email];?>">
<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="SUBMIT"></FORM>

<?php

if ("SUBMIT" == $SUBMIT)
{ $sql = "update Login1 SET " . "password='$password', " . "email='$email' WHERE username='$username';()"; if (mysql_query($sql)) { echo("<P>Info updated.</P>"); } else { echo("<P>Error updating: " . mysql_error() . "</P>"); }}

?>

mrnoisy

1:21 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



Try this

if ("SUBMIT" == $SUBMIT)
{
$sql = "update Login1 SET password='$password', email='$email' WHERE username='$username'";
if (mysql_query($sql))
{
echo("<P>Info updated.</P>");
}
else
{
echo("<P>Error updating: " . mysql_error() . "</P>");
}
}

paul161

3:02 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



Thank again working now.