Jump to content

small problem still.


Reaper0167

Recommended Posts

still having a small problem. even with all three fields filled out i am still getting the message "Please enter a username" I'm stumped. oh yeh, how do you get the code to be color coded when you paste it in here for a post.

 

 

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

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

// 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 {
    $result = mysql_query($sql);

    // take user back to a page
    header("location:register.php");
}

// closes your connection
mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/
Share on other sites

try this to see if it helps, intead of using empty :

<?php
// display message if field is empty
if ($username == '') {
    echo "Please enter a username.";
} elseif ($password == '') {
    echo "Please enter a password.";
} elseif ($email == '') {
    echo "Please enter a valid email.";
} else {
    $result = mysql_query($sql);
?>

 

and you need to put php tags for your code if you want it to be displayed by colors like the way i did.

 

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720591
Share on other sites

still having the same problem

 

 

<?php

// connects to server and database

mysql_connect("$host", "$username", "$password") or die("Could not connect.");

mysql_select_db("$db_name") or die("Could not find database");

 

// define variables from form

$username = $_POST["username"];

$password = $_POST["password"];

$email = $_POST["email"];

$encrypted_password = md5($password);

 

// inserting data into your database

$sql = "INSERT INTO $tbl_name(username, password, email)VALUES('$username','$encrypted_password','$email')";

 

// display message if field is empty

if ($username == '') {

    echo "Please enter a username.";

} elseif ($password == '') {

    echo "Please enter a password.";

} elseif ($email == '') {

    echo "Please enter a valid email.";

} else {

    $result = mysql_query($sql);

 

// take user back to a page

    header("location:register.php");

}

 

// closes your connection

mysql_close();

 

?>

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720593
Share on other sites

Try separating the conditions.

 

<?php

// display message if field is empty

if (empty($username)) {
    echo "Please enter a username.";
}

if (empty($password)) {
    echo "Please enter a password.";

} 

if (empty($email)) {
    echo "Please enter a valid email.";
} 


?>

 

another way.

 

<?php

if( (empty($username)) || (empty($password))|| (empty($email))) {
    echo "Please enter all fields";
} 

?>

 

last one for fun

 

<?php

// display message if field is empty

if (empty($username)) {

$error="Please enter a username.";
}

if (empty($password)) {
    $error= "Please enter a password.";

} 

if (empty($email)) {
    $error= "Please enter a valid email.";
} 

if($error){
echo $error;
}

?>

 

there plenty more just ask.

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720639
Share on other sites

Another way just posted to another user.

 

<?php

// display message if field is empty

if (empty($username)) {

$error="Please enter a username.<br><br>

<a href='whatever.com/start_agin.php'>Try agin</s>";

echo $error;
exit;
}

if (empty($password)) {
    $error= "Please enter a password.<br><br>

<a href='whatever.com/start_agin.php'>Try agin</s>";
echo $error;
    exit;
} 

if (empty($email)) {
    $error= "Please enter a valid email<br><br>

<a href='whatever.com/start_agin.php'>Try agin</s>";
echo $error;
    exit;
} 



?>

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720643
Share on other sites

I took your code only, and made some cosmetic changes ( with respect to your basic

requiremnt ) and it works. I say, your code does work. Whats the problem then?

<?php
$username = "root";
$password = "asdf";
$email       = "zxcv";

mysql_connect("localhost", "$username", "$password") or die("Could not connect.");
mysql_select_db("test") or die("Could not find database");

$sql = "INSERT INTO users
		(first_name, last_name, email, pass, registration_date)
		VALUES('$username','qwerty','$email', '$password', now())";

// display message if field is empty
if ($username == '') {
    echo "Please enter a username.";
} elseif ($password == '') {
    echo "Please enter a password.";
} elseif ($email == '') {
    echo "Please enter a valid email.";
} else {
    $result = mysql_query($sql) or die("Query failed: " . mysql_error());
}
?>

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720678
Share on other sites

still, nothing works. keeps saying to enter a username even when all fields are filled in. i haven't tried setting it up using an array yet. i will use that as my last resource. this way just seems a little more simple for being a beginner to PHP.

 

<?php

// server and database variable information
$host = "-----------";
$username = "----------";
$password = "----------";
$db_name = "-----------";
$tbl_name = "------------";

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

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

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

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

    // take user back to a page
    header("location:register.php");
}
// closes your connection
mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720848
Share on other sites

how about something like

 

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 {
    $result = mysql_query($sql);

 

EDIT - I see redarrow has already posted this, Sorry.

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720858
Share on other sites

this is driving me crazy. still, all three fields filled out, and its saying to enter a username

 

<?php

// server and database variable information
$host = "--------";
$username = "--------";
$password = "---------";
$db_name = "-----------";
$tbl_name = "------------";

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

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

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

// 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 {
    $result = mysql_query($sql);

    // take user back to a page
    header("location:register.php");
}
// closes your connection
mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720890
Share on other sites

name your submit button name="submit"

 

know post your form every think in order now.

 

<?php

// server and database variable information
$host = "--------";
$username = "--------";
$password = "---------";
$db_name = "-----------";
$tbl_name = "------------";

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

// define variables from 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 back to a page
    header("location:register.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
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720895
Share on other sites

here is the form

 

<?php
<style type="text/css">
<!--
.style1 {font-size: 24px}
.underline {
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #666666;
}
.style2 {
color: #0000FF;
font-weight: bold;
font-style: italic;
}
.style3 {color: #FF0000}
-->
</style>
<table width="100%" height="28" border="0" cellpadding="0" cellspacing="0" class="underline">
  <tr>
    <td height="26" bgcolor="#CCCCCC"><div align="center"><strong><span class="style1">Justin's Simple Registration Script</span></strong></div></td>
  </tr>
</table>

<p align="center">
  <label for="username"></label>
</p>
<form id="register" name="register" method="post" action="register.php">
  <table width="100%" border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td width="45%"><div align="right">
          <label for="label3">Username</label>
      </div></td>
      <td width="55%"><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
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720918
Share on other sites

keeping my form the way it was,,, this worked

thanks redarrow

<?php

// server and database variable information
$host = "10.6.186.33";
$username = "mylahstone";
$password = "******";
$db_name = "mylahstone";
$tbl_name = "members";

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

// define variables from 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
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720928
Share on other sites

Lol

keeping my form the way it was,,, this worked

thanks redarrow

<?php

// server and database variable information
$host = "10.6.186.33";
$username = "mylahstone";
$password = "******";
$db_name = "mylahstone";
$tbl_name = "members";

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

// define variables from 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();
}
?>

 

Lol, Nice db password

(pwd removed...)

Link to comment
https://forums.phpfreaks.com/topic/137881-small-problem-still/#findComment-720939
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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