Solved

Getting an Error  TDNUMBER message working with php  MySql

Posted on 2011-03-22
25
592 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:imagekrazy
  • 13
  • 12
25 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Put all the mysqli_connect data into ""
mysqli_connect("...","...","...","...");
0
 

Author Comment

by:imagekrazy
Comment Utility
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');
?>
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
If you define them as this, you have to use this syntax:
mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
0
 

Author Comment

by:imagekrazy
Comment Utility
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
0
 

Author Comment

by:imagekrazy
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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.
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
... on the second thought - mysql_error may not work - if not, try mysqli_error()
0
 

Author Comment

by:imagekrazy
Comment Utility
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
0
 

Author Comment

by:imagekrazy
Comment Utility
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`
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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) ?
0
 

Author Comment

by:imagekrazy
Comment Utility
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?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
Try to change mysqli_* to mysql_
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:imagekrazy
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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.
0
 

Author Comment

by:imagekrazy
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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']));
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
the same for login.php lines 20-22 - delete "$dbc," part of mysql_real_escape_string
0
 

Author Comment

by:imagekrazy
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
No, this part:

$username = mysql_real_escape_string($dbc, trim($_POST['user_name']));
...etc.
0
 

Author Comment

by:imagekrazy
Comment Utility
hello again,
Okay i did everything,
 there is no error  but it is not acknowledging, that the information was stored .
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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

0
 

Author Comment

by:imagekrazy
Comment Utility
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):
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
Comment Utility
can you post your database structure ?
0
 

Author Comment

by:imagekrazy
Comment Utility
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
0
 

Author Closing Comment

by:imagekrazy
Comment Utility
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
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now