FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


HTML + PHP problem





abhinav_shah
Code:
$r2 = mysql_db_query("abhinavs_mav","select *from book where no='$no'");
    while($array = mysql_fetch_row($r2) ) {
        $name = $array[0];
        $email = $array[1];
        $hphone = $array[2];
        $mphone = $array[3];
        $dob = $array[4];
        $dobt = ereg_replace("-","",$dob);
        $website = $array[5];
        $address = $array[6];
        $cname = $array[7];
    }
   ?>
     <h2>MAV 2002 DATABASE (BETA)</h2><hr>
    <h3>Enter your details</h3><br>
    <form action ="http://www.abhinav.frih.net/mav/success_edit.php" method="POST">
    <b>Name&nbsp;<input type="text" name="name" value=<? echo "$name"; ?> size="20" /><br />
    E-mail&nbsp;<input type="text" name="email" value=<? echo "$email"; ?> size="30" /><br />
    Home Phone&nbsp;<input type="text" name="hphone" value=<? echo "$hphone"; ?> size="10" />
    Mobile Phone&nbsp;<input type="text" name="mphone" value=<? echo "$mphone"; ?> size="13" /><br />
    D.O.B(yyyymmdd)&nbsp;<input type="text" name="dob" value=<? echo "$dobt"; ?> size="10" /><br />
    Web-Site&nbsp;<input type="text" size="40" name="website" value=<? echo "$website"; ?> maxlength="100" /><br />
    Current Address&nbsp;<input type="text" name="address" value=<? echo "$address"; ?> size="60" /><br />
    College Name or Work Details&nbsp;<input type="text" name="cname" value=<? echo "$cname"; ?> size="50" maxlength="100" /><br /><br />
    <p align="center"><input type="submit" value="Submit"/><input type="reset"/></p><br /></b>
    </form><hr>


This is a html page for editing one's phonebook entry. Now, what I have done is when some one visit's this page , the previously entered values are automatically entered in the form fields.
But here is the problem. If there is a space in the name field, for eg: $name = "Abhinav Shah", then only Abhinav appears in the form field "Name". Similarly for other fields also.
Can somebody please help.
mathiaus
I think its your HTML personally. The value should be surrounded by double quote marks which at current it isnt
eg. value="<?php echo $name; ?>"
Dont need quotes round the variable and its better and safer to use <?php rather than <?
you could echo that whole bit to make it shorter!

Code:
echo <<<HTML
<b>Name&nbsp;<input type="text" name="name" value="$name"> size="20" /><br />
    E-mail&nbsp;<input type="text" name="email" value="$email" size="30" /><br />
HTML;
etc
Stubru Freak
abhinav_shah wrote:
Code:
$r2 = mysql_db_query("abhinavs_mav","select *from book where no='$no'");
    while($array = mysql_fetch_row($r2) ) {
        $name = $array[0];
        $email = $array[1];
        $hphone = $array[2];
        $mphone = $array[3];
        $dob = $array[4];
        $dobt = ereg_replace("-","",$dob);
        $website = $array[5];
        $address = $array[6];
        $cname = $array[7];
    }
   ?>
     <h2>MAV 2002 DATABASE (BETA)</h2><hr>
    <h3>Enter your details</h3><br>
    <form action ="http://www.abhinav.frih.net/mav/success_edit.php" method="POST">
    <b>Name&nbsp;<input type="text" name="name" value=<? echo "$name"; ?> size="20" /><br />
    E-mail&nbsp;<input type="text" name="email" value=<? echo "$email"; ?> size="30" /><br />
    Home Phone&nbsp;<input type="text" name="hphone" value=<? echo "$hphone"; ?> size="10" />
    Mobile Phone&nbsp;<input type="text" name="mphone" value=<? echo "$mphone"; ?> size="13" /><br />
    D.O.B(yyyymmdd)&nbsp;<input type="text" name="dob" value=<? echo "$dobt"; ?> size="10" /><br />
    Web-Site&nbsp;<input type="text" size="40" name="website" value=<? echo "$website"; ?> maxlength="100" /><br />
    Current Address&nbsp;<input type="text" name="address" value=<? echo "$address"; ?> size="60" /><br />
    College Name or Work Details&nbsp;<input type="text" name="cname" value=<? echo "$cname"; ?> size="50" maxlength="100" /><br /><br />
    <p align="center"><input type="submit" value="Submit"/><input type="reset"/></p><br /></b>
    </form><hr>


This is a html page for editing one's phonebook entry. Now, what I have done is when some one visit's this page , the previously entered values are automatically entered in the form fields.
But here is the problem. If there is a space in the name field, for eg: $name = "Abhinav Shah", then only Abhinav appears in the form field "Name". Similarly for other fields also.
Can somebody please help.


Poster above is right, if you use:
value=<? echo "$name"; ?>
You will get:
value=Abhinav Shah
Abhinav is treated as the value, but Shah is treated as another argument.
So this is treated like:
value="Abhinav" Shah="Shah"

So just change your code into:
value="<? echo "$name"; ?>"
dandelion
Stubru Freak wrote:
[...]
So just change your code into:
value="<? echo "$name"; ?>"

Sure.
And in this context you can use the "=" shorthand for the echo command to make your code more readable.
Code:
value="<?=$name?>"
Related topics
A PHP problem !
A php problem
PHP problem...
PHP Problem: Unable to execute ext. commands
HTML Forms Problem
PHP Problem
PHP Problem...
how did you learn about html, php or other languages???
wierd php problem with sendmail
Need a Contact form from HTML/PHP
PHP imagecreate + CSS problem.
PHP imagecreate + CSS problem.
PHP inside HTML tags?
Could there be a PhP problem on the server?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.