Jump to content

Really confused!


lrk89

Recommended Posts

Hi all im trying to create a simple user registration page using php and mysql i created the database and tables locally and tested it and it works great so I did the same for on my sever and in the my mysqli connection script I changed the database name/passwords etc to match the hosting.

 

when i tested the script I get:

 

Notice: Constant DB_USER already defined in /home/lkennet1/public_html/xxx.co.uk/mysqli_connect.php on line 3

 

Notice: Constant DB_PASSWORD already defined in /home/lkennet1/public_html/xxx.co.uk/mysqli_connect.php on line 5

 

Notice: Constant DB_HOST already defined in /home/lkennet1/public_html/xxx.co.uk/mysqli_connect.php on line 7

 

Notice: Constant DB_NAME already defined in /home/lkennet1/public_html/xxx.co.uk/mysqli_connect.php on line 9

 

Easy to fix right. dont definine it twice. but im not defining it anywhere but my registration page and the only call i make to it is whne i use

require_once("mysqli_connect.php");

 

next mind boggling error is this:

 

Table 'example_wrdp2.users' doesn't exist

 

ok so to fix this I create the database right. well I have and it still dont work and I dont know why its choosing example_wrdp2

 

on my server i have 5 databases:

 

example_wrdp1

example_wrdp2

example_wrdp3

example_wrdp4

example_myNewDatabase

 

I don't understand why its not using example_myNewDatabase which i am specifying in my db connect script. Im totally lost and stuck with this.

 

Link to comment
https://forums.phpfreaks.com/topic/246462-really-confused/
Share on other sites

haha not my cup of tea ;-)

 

yeah sure the code all looks ok to me

 

<?php
if (isset($_POST['submitted'])) {

include_once "mysqli_connect.php";

$errors = array(); //check all fields for errors when form is submitted

if (empty($_POST['FirstName'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$FirstName = mysqli_real_escape_string($dbc, trim($_POST['FirstName']));

} //end of fist name


if (empty($_POST['LastName'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$LastName = mysqli_real_escape_string($dbc, trim($_POST['LastName']));
} // end of last name


if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$email = mysqli_real_escape_string($dbc, trim($_POST['email']));
}// end of emial


if (!empty($_POST['pass'])) {
if ($_POST['pass'] != $_POST['pass2']) {
	$errors[] = 'Your password did not match the confirmed password.'; // check if passwords match
} else {
	$pass = mysqli_escape_string($dbc, trim($_POST['pass']));
}
} else {
$errors[] = 'You forgot to enter your password.';
// end of password
}
if (empty($errors)) {


$query = "INSERT INTO users (first_name, last_name, email, pass, registration_date)
VALUES ('$FirstName', '$LastName', '$email', SHA1('$pass'), NOW())";

$result = @mysqli_query ($dbc, $query);


if ($result) {
	echo '<h5>Thank you!</h5>

	<p>You are now registered.</p><p><br /></p>';
} else {
	echo '<h1>System Error</h1>

	<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';

	echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $query . '</p>';
}


exit();


} else {
echo '<h1>Error!</h1>

<p class="error">The following >>error(s) occurred:<br />';

foreach ($errors as $msg) {
	echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
	}
	mysqli_close($dbc);
}

 

I cant see anything wrong with the above and my connection script is this:

 

 

<?php 

DEFINE ('DB_USER','username');

DEFINE ('DB_PASSWORD','pass');

DEFINE('DB_HOST','localhost');

DEFINE('DB_NAME','databasename');

$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to Mysql database: ' . mysqli_connect_error() );

?>

Link to comment
https://forums.phpfreaks.com/topic/246462-really-confused/#findComment-1265605
Share on other sites

That solved the DEFINE issue but im seriously not defining it anywhere else,

 

still says it cant find the right database. its trying to use a database that im using for wordpress could somehow that be conflicting it? its for a different domain but i host all my sites on one hosting.

Link to comment
https://forums.phpfreaks.com/topic/246462-really-confused/#findComment-1265609
Share on other sites

Iv done that several times and have given up after some research i have just added

print_r(get_defined_constants(true));

before the defines and i got loads of jargon but its alreading defining a connection that relates to one of my wordpress installs.

 

how do i make it choose the one for my new database and site?

Link to comment
https://forums.phpfreaks.com/topic/246462-really-confused/#findComment-1265613
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.