[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting an Error  TDNUMBER message working with php  MySql

Posted on 2011-03-22
25
Medium Priority
?
601 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 12
25 Comments
 
LVL 27

Expert Comment

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

Author Comment

by:imagekrazy
ID: 35192888
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
ID: 35192937
If you define them as this, you have to use this syntax:
mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:imagekrazy
ID: 35194219
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
ID: 35194330
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
ID: 35196247
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
ID: 35196252
... on the second thought - mysql_error may not work - if not, try mysqli_error()
0
 

Author Comment

by:imagekrazy
ID: 35199960
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
ID: 35200012
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
ID: 35200040
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
ID: 35200120
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
ID: 35200370
Try to change mysqli_* to mysql_
0
 

Author Comment

by:imagekrazy
ID: 35201927
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
ID: 35202040
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
ID: 35202111
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
ID: 35202142
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
ID: 35202151
the same for login.php lines 20-22 - delete "$dbc," part of mysql_real_escape_string
0
 

Author Comment

by:imagekrazy
ID: 35202158
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
ID: 35202194
No, this part:

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

Author Comment

by:imagekrazy
ID: 35203520
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
ID: 35204786
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
ID: 35208402
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 2000 total points
ID: 35209033
can you post your database structure ?
0
 

Author Comment

by:imagekrazy
ID: 35234753
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
ID: 35237204
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

649 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