imagekrazy
asked on
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/circle image/html /myvebsite /coolpeopl e/index.ph p on line 40
index.php
appvars.php
connectvars.php
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/circle
index.php
appvars.php
connectvars.php
ASKER
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.host edresource .com');
define('DB_USER', 'myvebsite');
define('DB_PASSWORD', 'Jeep123');
define('DB_NAME', 'myvebsite');
?>
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.host
define('DB_USER', 'myvebsite');
define('DB_PASSWORD', 'Jeep123');
define('DB_NAME', 'myvebsite');
?>
If you define them as this, you have to use this syntax:
mysqli_connect(DB_HOST,DB_ USER,DB_PA SSWORD,DB_ NAME);
mysqli_connect(DB_HOST,DB_
ASKER
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/circle image/html /myvebsite /coolpeopl e/signup.p hp on line 29
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/circle
ASKER
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
and tell me what mistake I am making
signup.php
index.php
login.php
connectvars.php
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.
$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.
... on the second thought - mysql_error may not work - if not, try mysqli_error()
ASKER
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/circle image/html /myvebsite /coolpeopl e/signup.p hp on line 29
Here is my update on my file that i changed
signup.php
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/circle
Here is my update on my file that i changed
signup.php
ASKER
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`
SELECT * FROM `user_login` WHERE `user_id`, `user_name`, `password`, `join_date`, `first_name`, `last_name`, `gender`, `birthdate`, `city`, `state`, `picture`
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) ?
$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) ?
ASKER
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/circle image/html /myvebsite /coolpeopl e/signup.p hp 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?
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/circle
INSERT INTO myvebsite (username, password, join_date) VALUES ('hat123', SHA('hat567'), NOW())
and can you check my fields is that not matching up?
Try to change mysqli_* to mysql_
ASKER
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/circle image/html /myvebsite /coolpeopl e/signup.p hp on line 21
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/content/c/i/r/circle image/html /myvebsite /coolpeopl e/signup.p hp on line 22
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/content/c/i/r/circle image/html /myvebsite /coolpeopl e/signup.p hp 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
Warning: mysql_real_escape_string()
Warning: mysql_real_escape_string()
Warning: mysql_real_escape_string()
and i rearranged the three files like you said here are the files that i updated
index.php
login.php
signup.php
signup.php
$username = mysql_real_escape_string(t rim($_POST ['user_nam e']));
$password1 = mysql_real_escape_string(t rim($_POST ['password 1']));
$password2 = mysql_real_escape_string(t rim($_POST ['password 2']));
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.
$username = mysql_real_escape_string(t
$password1 = mysql_real_escape_string(t
$password2 = mysql_real_escape_string(t
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.
ASKER
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
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
signup.php, change lines 21-23 to
$username = mysqli_real_escape_string( trim($_POS T['user_na me']));
$password1 = mysqli_real_escape_string( trim($_POS T['passwor d1']));
$password2 = mysqli_real_escape_string( trim($_POS T['passwor d2']));
$username = mysqli_real_escape_string(
$password1 = mysqli_real_escape_string(
$password2 = mysqli_real_escape_string(
the same for login.php lines 20-22 - delete "$dbc," part of mysql_real_escape_string
ASKER
signup.php
$username = mysql_real_escape_string(t rim($_POST ['user_nam e']));
$password1 = mysql_real_escape_string(t rim($_POST ['password 1']));
$password2 = mysql_real_escape_string(t rim($_POST ['password 2']));
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
$username = mysql_real_escape_string(t
$password1 = mysql_real_escape_string(t
$password2 = mysql_real_escape_string(t
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
No, this part:
$username = mysql_real_escape_string($dbc, trim($_POST['user_name'])) ;
...etc.
$username = mysql_real_escape_string($dbc, trim($_POST['user_name']))
...etc.
ASKER
hello again,
Okay i did everything,
there is no error but it is not acknowledging, that the information was stored .
Okay i did everything,
there is no error but it is not acknowledging, that the information was stored .
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
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>
ASKER
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):
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):
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
ASKER
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
mysqli_connect("...","..."