Getting an Error TDNUMBER message working with php MySql

I am getting an error  message I am  working with PHP & MySql Head firs text book, and I am using there codes
for login page and sign up, I added my info for my databse , and  i went to test the page and I am getting this message
Parse error: syntax error, unexpected T_DNUMBER in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/index.php on line 40
 index.php
 appvars.php
 connectvars.php
imagekrazyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lukasz ChmielewskiCommented:
Put all the mysqli_connect data into ""
mysqli_connect("...","...","...","...");
imagekrazyAuthor Commented:
Why do i need to do that? i thought  it had to read where my info is stored and put,
and what about the  the file connectvars.php  which i changed to my database info?

<?php
  // Define database connection constants
  define('DB_HOST', 'myvebsite.db.2150637.hostedresource.com');
  define('DB_USER', 'myvebsite');
  define('DB_PASSWORD', 'Jeep123');
  define('DB_NAME', 'myvebsite');
?>
Lukasz ChmielewskiCommented:
If you define them as this, you have to use this syntax:
mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

imagekrazyAuthor Commented:
wow!!,  almost there:)

i did what you stated and I am getting  this error message

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/signup.php on line 29
imagekrazyAuthor Commented:
can you please check out the files    i redid  of what you said , and it kinda worked,
  and tell me what mistake I am making
 signup.php
 index.php
 login.php
 connectvars.php
Lukasz ChmielewskiCommented:
Just switch the line 29 with error to this:
$query = "SELECT * FROM myvebsite WHERE username = '$username'" or die mysql_error();
That error means that the query is wrong - like a wrong field name (username ?) or myvebsite is the wrong table name. But if you switch that to above you should see what is the error exactly.
Lukasz ChmielewskiCommented:
... on the second thought - mysql_error may not work - if not, try mysqli_error()
imagekrazyAuthor Commented:
hello again,
my table name is:  user_login
database name is: myvebsite

i made those changes but  it didn't work so i changed it back and removed the or die statement
and i got to the page and then i tested it and it gave me  this error again

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/signup.php on line 29

Here is my update on my  file that i changed

 signup.php
imagekrazyAuthor Commented:
oh these are my fields
SELECT * FROM `user_login` WHERE `user_id`, `user_name`, `password`, `join_date`, `first_name`, `last_name`, `gender`, `birthdate`, `city`, `state`, `picture`
Lukasz ChmielewskiCommented:
What happens when you add echo between these lines like this:

      $query = "SELECT * FROM user_login WHERE username = '$username'" ;
      echo"$query";
      $data = mysqli_query($dbc, $query);

Can you run the query directly on  the database without errors (for example with phpmyadmin) ?
imagekrazyAuthor Commented:
I get this

SELECT * FROM user_login WHERE username = 'hat123'
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/signup.php on line 30
INSERT INTO myvebsite (username, password, join_date) VALUES ('hat123', SHA('hat567'), NOW())

and can you check my fields  is that not matching up?
Lukasz ChmielewskiCommented:
Try to change mysqli_* to mysql_
imagekrazyAuthor Commented:
hi, its giving me this error

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/signup.php on line 21

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/signup.php on line 22

Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/content/c/i/r/circleimage/html/myvebsite/coolpeople/signup.php on line 23


and i rearranged the three files like you said here are the files that i updated
 index.php
 login.php
 signup.php
Lukasz ChmielewskiCommented:
signup.php

    $username = mysql_real_escape_string(trim($_POST['user_name']));
    $password1 = mysql_real_escape_string(trim($_POST['password1']));
    $password2 = mysql_real_escape_string(trim($_POST['password2']));

The same in login.php. Basicaly you need to remove the $dbc argument for the mysql_ functions as they do not need the additional parameter for the connection to database.
imagekrazyAuthor Commented:
Okay i re -worked it I don't get an error but it isn't running, i put in my infomation but
i get this
(You must enter all of the sign-up data, including the desired password twice.)

so i am assuming its not reading something and again here is my files  that i reworked
 signup.php
 login.php
 index.php
Lukasz ChmielewskiCommented:
signup.php, change lines 21-23 to

    $username = mysqli_real_escape_string(trim($_POST['user_name']));
    $password1 = mysqli_real_escape_string(trim($_POST['password1']));
    $password2 = mysqli_real_escape_string(trim($_POST['password2']));
Lukasz ChmielewskiCommented:
the same for login.php lines 20-22 - delete "$dbc," part of mysql_real_escape_string
imagekrazyAuthor Commented:
signup.php

    $username = mysql_real_escape_string(trim($_POST['user_name']));
    $password1 = mysql_real_escape_string(trim($_POST['password1']));
    $password2 = mysql_real_escape_string(trim($_POST['password2']));

The same in login.php. Basicaly you need to remove the $dbc argument for the mysql_ functions as they do not need the additional parameter for the connection to database.

Are you saying i have to remove  the above statements; $username $pasword1 $password2
Lukasz ChmielewskiCommented:
No, this part:

$username = mysql_real_escape_string($dbc, trim($_POST['user_name']));
...etc.
imagekrazyAuthor Commented:
hello again,
Okay i did everything,
 there is no error  but it is not acknowledging, that the information was stored .
Lukasz ChmielewskiCommented:
Try with this code of signup.php, it works for me, maybe you missed something.
Also, there is something wrong with this query:
"INSERT INTO user_login (user_name, password1,password2, join_date) VALUES ('$username', SHA('$password1'), NOW())";

Do you have two fields (password1, password2) in your table ? This is not necessary, because you store only one sha(password1) value.

Well, just try this one signup.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Cool people - fun stuffp</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h3>cool people - fun stuff</h3>

<?php
  error_reporting(E_ERROR);
  require_once('appvars.php');
  require_once('connectvars.php');

  // Connect to the database
  $dbc = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
                            //host  username   password  database name
  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST
    $username = mysql_real_escape_string(trim($_POST['username']));
    $password1 = mysql_real_escape_string(trim($_POST['password1']));
    $password2 = mysql_real_escape_string(trim($_POST['password2']));

    if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {
      // Make sure someone isn't already registered using this username
      $query = "SELECT * FROM user_login WHERE user_name = '$username'" ;
	  //echo"$query";
      $data = mysql_query($query);
      if (mysql_num_rows($data) == 0) {
        // The username is unique, so insert the data into the database
        $query = "INSERT INTO user_login (user_name, password1,password2, join_date) VALUES ('$username', SHA('$password1'), NOW())";
		echo"$query";
        mysql_query($query);

        // Confirm success with the user
        echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';

        exit();
      }
      else {
        // An account already exists for this username, so display an error message
        echo '<p class="error">An account already exists for this username. Please use a different address.</p>';
        $username = "";
      }
    }
    else {
      echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
    }
  }

  mysql_close($dbc);
?>

  <p>Please enter your username and desired password to sign up to Mismatch.</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend>Registration Info</legend>
      <label for="username">Username:</label>
      <input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br />
      <label for="password1">Password:</label>
      <input type="password" id="password1" name="password1" /><br />
      <label for="password2">Password (retype):</label>
      <input type="password" id="password2" name="password2" /><br />
    </fieldset>
    <input type="submit" value="Sign Up" name="submit" />
  </form>
</body> 
</html>

Open in new window

imagekrazyAuthor Commented:
I don't know what i am doing wrong, it don't give me any errors, but its not acknowledging that it accepted the password and  the user can sign up it is spitting this page out after i type the password
you said it worked for you is it acknowleding that you signed up? or is spitting the info at the bottom?

cool people - fun stuff

You must enter all of the sign-up data, including the desired password twice.

Please enter your username and desired password to sign up to Mismatch.
Registration Info Username:
Password:
Password (retype):
Lukasz ChmielewskiCommented:
can you post your database structure ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
imagekrazyAuthor Commented:
user_id       varchar(40)       utf8_general_ci             Yes       NULL             Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      userName       varchar(40)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      password       varchar(55)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      joinDate       datetime                   No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      firstname       varchar(55)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      lastname       varchar(55)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      gender       varchar(20)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      birthdate       datetime                   No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      state       varchar(20)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      county       varchar(35)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      town       varchar(45)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
      picture       varchar(55)       utf8_general_ci             No                   Browse distinct values       Change       Drop       Primary       Unique       Index       Fulltext
imagekrazyAuthor Commented:
Thanks for your help , i am going to post this question again to see if any one has different opinion  on the matter and again thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.