Need help with php mysql membership system

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
Hello, I have been looking over the php mysql membership system tutorial and I made an attempt to do it on my site, however I am a total noob to php and it didn't work for me. Honestly I didn’t know what to do with the existing code as far as plugging in my own db info I also created a db and table in my cpanel but I’m not really sure I even did that right. If someone could help me out that would be great!!! (lead me through the steps for my first time) or point me to a person i can talk with to do that. Or even point me to more explanatory help so that I can teach myself and actually get it done correctly. Thank you guys very much.

---------- Post added at 05:25 PM ---------- Previous post was at 03:40 PM ----------

ok so here is the code for two php files that i am trying to use to test my database and check for a good connection. i put all the needed info into the files includeing the database name username and password but when i navigate to the php page www.pooperdoodles.ws/connect_to_mysql.php or www.pooperdoodles.ws/mysql_connect_quicktest.php i get a response that says "no database by that name" I have put the php files up in the www folder on my server. if that is the wrong place im not sure where i am suposed to put it. please help! thank you

<?php
$db_host = "localhost";
$db_username = "put_db_username_here";
$db_pass = "put_db_password_here";
$db_name = "put_db_name_here";
mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error());
mysql_select_db("$db_name") or die("no database by that name");
?>

<?php
include_once "connect_to_mysql.php";

echo "<br /><h2>You are successfully connected to your database.</h2><br /><br />
Otherwise you would see an include warning, or a mysql connection error.<br /><br />
Happy coding!
";
?>
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
What database name and username are you using? I presume your scripts are hosted on x10Hosting.
 

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
What database name and username are you using? I presume your scripts are hosted on x10Hosting.

I thought that was a dangerous thing to include but what the heck

here is the acctual code with all the "correct" info in it
<?php
$db_host = "localhost";
$db_username = "ccrowe1_allie";
$db_pass = "bedirect2002";
$db_name = "ccrowe1_member";
mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error());
mysql_select_db("$db_name") or die("no database by that name");
?>

<?php
include_once "connect_to_mysql.php";
echo "<br /><h2>You are successfully connected to your database.</h2><br /><br />
Otherwise you would see an include warning, or a mysql connection error.<br /><br />
Happy coding!
";
?>

thank you for you reply it means alot to me
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Hmm, are you sure that the 'members' database exists? As in, is it listed in MySQL Databases in your cPanel?

Btw, it's okay for you to post your username and database name, but not your password!
 

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
Hmm, are you sure that the 'members' database exists? As in, is it listed in MySQL Databases in your cPanel?

Btw, it's okay for you to post your username and database name, but not your password!

yeah it looks like its there, along with the table i created and the user name. yes im useing x10 hosting btw. and i guess ill have to go change that password lol.

---------- Post added at 06:30 PM ---------- Previous post was at 06:24 PM ----------

Hmm, are you sure that the 'members' database exists? As in, is it listed in MySQL Databases in your cPanel?

Btw, it's okay for you to post your username and database name, but not your password!

it is there although it says it is 0mb's and also I put these files in the www folder on the server could that be the wrong place becuase im not sure if it is or not?
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Hmm, that's weird. Okay, try creating a blank PHP file in public_html or www (doesn't really matter) with the following code, navigate to the file in your browser (or give me the link)

PHP:
<?php
mysql_connect('localhost', 'ccrowe1_allie', 'bedirect2002') or die ('Could Not Connect');
mysql_select_db('ccrowe1_member') or die ('Database Does Not Exist');

echo "Database connection successful. No errors detected.";


---------- Post added at 08:33 PM ---------- Previous post was at 08:32 PM ----------

PS. Yes, the www directory should be fine :)
 

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
Hmm, that's weird. Okay, try creating a blank PHP file in public_html or www (doesn't really matter) with the following code, navigate to the file in your browser (or give me the link)

PHP:
<?php
mysql_connect('localhost', 'ccrowe1_allie', 'bedirect2002') or die ('Could Not Connect');
mysql_select_db('ccrowe1_member') or die ('Database Does Not Exist');
 
echo "Database connection successful. No errors detected.";

---------- Post added at 08:33 PM ---------- Previous post was at 08:32 PM ----------

PS. Yes, the www directory should be fine :)

http://www.pooperdoodles.ws/testconnection.php

---------- Post added at 07:41 PM ---------- Previous post was at 07:38 PM ----------


I changed the password but i updated the code you sent me with the correct one!
Reply Database does not exist
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Try this: Login to your cPanel and go to 'phpMyAdmin'. On the left hand side, there should be a listing of databases (some are created automatically). Is 'members' there?
 

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
Try this: Login to your cPanel and go to 'phpMyAdmin'. On the left hand side, there should be a listing of databases (some are created automatically). Is 'members' there?


when i first go into php my admin on the left side all i see is the table called user that i created
but if i click on the databases button under database in the main content area of the page i see the ccrowe1_member listed under database but still not on the left side bar
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I thought that was a dangerous thing to include but what the heck.
The password is what's dangerous to include. If you posted your actual password, change it right now. Not only have others seen it, but search engines may have cached the page.

Please use
PHP:
, [html] or [code] tags (as appropriate) to separate and format code.

There's no advantage to placing double quotes around a variable. All it does is make PHP take extra time (admittedly, very, very little time) to evaluate the string and interpolate the variable. The value of [c]"$db_host"[/c] is equal to [c]$db_host[/c].

[URL="http://brainstormsandraves.com/articles/semantics/structure/#br"]<br/>[/URL] isn't [URL="http://webstyleguide.com/wsg3/5-site-structure/2-semantic-markup.html"]semantic[/URL]. Use paragraphs or whatever is most appropriate.

You shouldn't be using the old mysql extension, even to test DB connection settings. You won't be using it in production code, so a successful test isn't worth anything.

[php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>DB Connection test</title>
  </head>
  <body>
    <?php
    // make sure only admins see this page by e.g. using HTTP authentication

    $db_host = "localhost";
    $db_name = "ccrowe1_member";
    $db_username = "ccrowe1_allie";
    $db_pass = "****";
    try {
        $db = new PDO("mysql:host=localhost;db=$db_name", $db_username, $db_pass);
        include_once "connect_to_mysql.php";
        ?>
        <h2>DB Connection Succeeded</h2>
        <p>You are successfully connected to your database. Otherwise you would see an include warning, or a mysql connection error.</p>
        <p>Happy coding!</p>
        <?php 
    } catch (PDOException $exc) {
        ?>
        <h2>DB Connection Failed</h2>
        <pre><?php
        echo $exc;
        ?></pre><?php
    }
    ?>
  </body>
</html>

Since database connection creation (including managing the database credentials) should be the responsibility of one module, write that module and test it to see if your DB connection will work, rather than writing a script to test DB connection settings (which leads to a duplication of effort and doesn't reveal very much). This is unit testing. See "
PHP:
 MySQL and PHP[/URL]" and "[URL="http://x10hosting.com/forums/programming-help/117523-display-all-would-secret-while-mysql-broken.html#post665590"]Display all that would be secret while Mysql is broken[/URL]" for some partial examples of a class to manage local DB connections.

[quote="chriscrowe43, post: 848819"]when i first go into php my admin on the left side all i see is the table called user that i created[/QUOTE]
Table, or database? The left view should show databases, not tables. Please post a screenshot.
 
Last edited:

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
@chris - When you created your MySQL Database and MySQL User, did you assign the user to the database? Also, did you give it All Privledges?
 

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
Table, or database? The left view should show databases, not tables. Please post a screenshot.[/QUOTE] here is the screenshot of my, myphpmyadmin page. I didnt change the password already, and ill go try to correct the php code. im completely new to php so please bare with me. ill also reply with a copy of the new code without the password included ofcourse lol. thanks
phpmyadminscreenshot.jpg


---------- Post added at 08:30 PM ---------- Previous post was at 08:21 PM ----------

@chris - When you created your MySQL Database and MySQL User, did you assign the user to the database? Also, did you give it All Privledges?

yes i believe i did all that
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
From the "Create table" button, I'd guess that the reason you don't see "ccrowe1_member" on the left is that phpMyAdmin already opened it, which it might do if there's only one database you have access to. For comparison, see the attached screenshot from the pmahomme project page.

Make sure you've followed the proper steps when creating your database and user. Even though you may be sure you did, go back and do it again. You may have missed something the first time.

If all else fails, export existing tables, drop the database, recreate it then import the table data.

In the future, you should censor any security tokens (visible in the URL shown in the address bar in your screenshot), or crop the image to display only the page and not the browser toolbars. Hopefully, phpMyAdmin protects against session hijacking.
 

Attachments

  • pmahomme.jpg
    pmahomme.jpg
    46.4 KB · Views: 114
Last edited:

chriscrowe43

New Member
Messages
23
Reaction score
0
Points
0
thank you for your help, i will read up on everything, I honestly am not quite sure what i did incorrectly, but i dont want to make mistakes. im not sure what you mean by the security token thing, if you would please elaborate a little further i will be sure to not do it again, and i used your example altering the proper spots in the code and finaly got a successfull connection!!! YAY thank you so much for your help
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Sorry for not being clear: In your cPanel Home Page click on MySQL Databases and scroll near the bottom. There should be an option to assign a user to a database - you need to fill this in and press submit. You will then be asked to fill in privledges; check All Privledges then the submit button (example screenshot below).

screenshot2.jpg
 
Last edited:

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
368
Points
83
Just seen your post; congratulations! :D
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
im not sure what you mean by the security token thing, if you would please elaborate a little further i will be sure to not do it again
A security token is handed out by a service when you authenticate so you don't need to re-authenticate. If you look at the URL of a phpMyAdmin page, you'll see a "token=", followed by the token. As long as the token is valid (phpMyAdmin will expire tokens after a certain time passes where there is no activity), someone could use the token to access your MySQL account through phpMyAdmin, unless phpMyAdmin also happens to validate the HTTP request to prevent session hijacking.
 
Top