Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Urgent help needed on my codings

    I have a problem with my php coding and some how i can't retain my attributes when i submit the wrong infomation into form and the only thing it retains is the name form whereas the rest is blank. Please any help would be much appreciated.

    The following codes are:

    <html>
    <head>
    <title>Sign My GuestBook</title>
    </head>

    <body background="" bgcolor="9999FF" text="000000">
    <h1>Feel free to sign our Guest Book</h1>

    <?php

    $db = mysql_connect("localhost", "", "");
    mysql_select_db("guestbook", $db);




    if ($submit) {

    $errmsg1="";
    $errmsg2="";
    $errmsg3="";

    $name1 .= "$name";
    $location1 .= "$location";
    $email1 .= "$email";
    $url1 .= "$url";
    $comments1 .= "$comments";

    if (empty($name))
    {
    $errmsg1 .="<li>you have to put in a name, at least!\n";
    printf($errmsg1);
    }


    if (empty($email) || !eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$",$email))
    {
    $errmsg2 .="<li>$email doesn't look like a valid email address\n";
    printf($errmsg2);
    }


    if (!empty($url) && !eregi("^http://[A-Za-z0-9\%\?\_\:\~\/\.-]+$",$url))
    {
    $errmsg3 .="<li>$url doesn't look like a valid URL\n";
    printf($errmsg3);
    }

    if ( !empty($errmsg1) || !empty($errmsg2) || !empty($errmsg3) )
    {
    ?>
    <form method="post" action="<?php echo $PHP_SELF?>">

    <table border=0>

    <tr>
    <td align="right">Name:</td>
    <td><input type= "text" name= "name" value="<?php echo "$name1" ?>" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right">Location:</td>
    <td><input type= "text" name= "location" value="<?php "$location1" ?>" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right">E-mail:</td>
    <td><input type= "text" name= "email" value="<?php "$email1" ?>" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right">URL:</td>
    <td><input type= "text" name= "url" value="<?php "$url1" ?>" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right" valign="top">Comments:</td>
    <td><textarea wrap=virtual rows=5 cols=45 name="comments" value= "<?php "$comments1" ?>" ></textarea><br /></td>
    </tr>

    <tr>
    <td>
    <input type="Submit" name="submit" value="Submit"></td>
    <td><input type=reset value="Reset form">
    </td>
    </tr>

    </table>
    </form>

    <?php
    exit();
    }





    if (empty($errmsg1) && empty($errmsg2) && empty($errmsg3))
    {
    $sql = "INSERT INTO guestbook (name,location,email,url,comments)
    VALUES ('$name','$location','$email','$url','$comments')";
    $result = mysql_query($sql);
    echo "Thank you! Information entered.\n";
    }

    } else{
    //?>

    printf("" <form method="post" action="<?php echo $PHP_SELF?>">

    <table border=0>

    <tr>
    <td align="right">Name:</td>
    <td><input type= "text" name= "name" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right">Location:</td>
    <td><input type= "text" name= "location" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right">E-mail:</td>
    <td><input type= "text" name= "email" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right">URL:</td>
    <td><input type= "text" name= "url" value= "http://" size= "40"><br /></td>
    </tr>

    <tr>
    <td align="right" valign="top">Comments:</td>
    <td><textarea wrap=virtual rows=5 cols=45 name="comments" ></textarea><br /></td>
    </tr>

    <tr>
    <td>
    <input type="Submit" name="submit" value="Submit"></td>
    <td><input type=reset value="Reset form">
    </td>
    </tr>

    </table>
    </form>


    //<?php
    }
    ?>


    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    You forgot to put echo into the other fileds
    Code:
    <tr>
    <td align="right">Name:</td>
    <td><input type= "text" name= "name" value="<?php echo $name1; ?>" size= "40"><br /></td>
    </tr>
    
    <tr>
    <td align="right">Location:</td>
    <td><input type= "text" name= "location" value="<?php echo $location1; ?>" size= "40"><br /></td>
    </tr>
    
    <tr>
    <td align="right">E-mail:</td>
    <td><input type= "text" name= "email" value="<?php echo $email1; ?>" size= "40"><br /></td>
    </tr>
    
    <tr>
    <td align="right">URL:</td>
    <td><input type= "text" name= "url" value="<?php echo $url1; ?>" size= "40"><br /></td>
    </tr>
    
    <tr>
    <td align="right" valign="top">Comments:</td>
    <td><textarea wrap=virtual rows=5 cols=45 name="comments" value= "<?php echo $comments1; ?>" ></textarea><br /></td>
    </tr>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •