tjhilder Posted November 5, 2005 Share Posted November 5, 2005 I've been fiddling around with some code but it doesn't seem to work right, I been trying several things but to no success, anyone able to help me on this one? <?php $username = $_POST['username']; $password = $_POST['password']; $fullname = $_POST['full_name']; $email = $_POST['email']; $url = $_SERVER['PHP_SELF']; ini_set('display_errors',1); error_reporting(E_ALL & ~E_NOTICE); if (isset ($_POST['submit'])) { DEFINE (DB_USER, "username"); DEFINE (DB_PASSWORD, "password"); DEFINE (DB_HOST, "localhost"); DEFINE (DB_NAME, "database"); if ($dbc = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)) { if (@mysql_select_db(DB_NAME)) { die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>'); } } else { die ('<p>Could not connect to MySQL because: <b>' . mysql_error() . '</b></p>'); } $query = "INSERT INTO members (member_userid, member_username, member_password, member_fullname, member_email, member_rank) VALUES ( 0, '$username', '$password', '$fullname', '$email', '3' )"; if (@mysql_query($query)) { print '<p>The blog entry has been added.</p>'; } else { print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; } } mysql_close(); ?> <form action="<? echo $url ?>" method="post"> <input type="text" name="full_name" cols="60" /><br /> <input type="text" name="username" cols="60" /><br /> <input type="text" name="password" cols="60" /><br /> <input type="text" name="email" cols="60" /><br /> <input type="submit" name="submit" value="Add Member!" /><br /> everytime i enter information it brings up the database error but nothing appears with mysql_error(), this is what I get: Could not select the database because: if I knew what the error was maybe I'd know what I'm meant to be doing but it doesn't seem to want to show up. any suggestions? Quote Link to comment Share on other sites More sharing options...
azuka Posted November 5, 2005 Share Posted November 5, 2005 The problem seems to come from the line where you wrote [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--] if ($dbc = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)) { if (@mysql_select_db(DB_NAME)) { die (\'<p>Could not select the database because: <b>\' . mysql_error() . \'</b></p>\'); } } else { die (\'<p>Could not connect to MySQL because: <b>\' . mysql_error() . \'</b></p>\'); } [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] What actually occurs is like this - If DB_NAMe is selected you throw an error. So change that line to [!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--] if (!@mysql_select_db(DB_NAME)) { die (\'<p>Could not select the database because: <b>\' . mysql_error() . \'</b></p>\'); } [/span][!--PHP-Foot--][/div][!--PHP-EFoot--] Your code should work just fine Quote Link to comment Share on other sites More sharing options...
tjhilder Posted November 5, 2005 Author Share Posted November 5, 2005 thanks very much, sometimes seems to take someone elses point of view to figure out the error and correct it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.