Jump to content

need help displaying a message


Reaper0167

Recommended Posts

i had a post a few days ago about a register script and we finally got that all figured out.  but right now when the user doesn't fill in all three of the fields it directs them to another page with a message saying that the field was not filled in.  and well, it just doesn't look professional. what i am hoping we can do is get the message to appear next to the field that was not filled in. i was told that this can not be done using PHP and javascript must be used. is that true?  can anyone help me out here? thanks, Reaper.

 

Oh yeh, here is what i got so far

<?php

//connection to your database
include ("connection.php");

// define variables from register form
$username = mysql_real_escape_string($_POST["username"]);
$password = mysql_real_escape_string($_POST["password"]);
$email = mysql_real_escape_string($_POST["email"]);
$encrypted_password = md5($password);

// display message if field is empty
if (empty($username)) {
    echo "Please enter a username.";
} elseif (empty($password)) {
    echo "Please enter a password.";
} elseif (empty($email)) {
    echo "Please enter a valid email.";
} else {

    // take user to a page after registration
    header("location:thanks.php");
}

if (isset($_POST['submit'])) {

    // inserting data into your database
    $sql = "INSERT INTO $tbl_name(username, password, email)VALUES('$username','$encrypted_password','$email')";

    $res = mysql_query($sql) or die(mysql_error());

    // closes your connection
    mysql_close();
}
?>

Link to comment
Share on other sites

oh yeh,, here is my form

<?php
<form id="register" name="register" method="post" action="register.php">
  <table width="100%" border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td width="30%"><div align="right">
          <label for="label3">Username</label>
      </div></td>
      <td width="70%"><input name="username" type="text" id="label3" size="35" maxlength="20" /></td>
    </tr>
    <tr>
      <td><div align="right">Password</div></td>
      <td><input name="password" type="password" id="label4" size="35" maxlength="20" /></td>
    </tr>
    <tr>
      <td height="22"><div align="right">
          <label for="label4"></label>
        Email</div></td>
      <td><input name="email" type="text" id="label5" size="35" maxlength="65" /></td>
    </tr>
    <tr>
      <td height="22"> </td>
      <td><label for="submit"></label>
          <input type="submit" name="submit" id="submit" value="Register" /></td>
    </tr>
  </table>
  </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.