Page 1 of 1

MySQL not running queries locally

PostPosted: 25. April 2007 22:03
by Kacedawg21
I installed the latest version of XAMPP to my Windows system, and am using it locally for testing script.

In phpMyAdmin I am able to create databases and tables, and insert information in the tables, but for some reason when I code in PHP and try to use a form to insert information into tables, it won't do it.

Here's the code, please ignore the simplicity, it's for testing only:

Code: Select all
<?

// Site Admin - Create Admin

if ( isset($HTTP_GET_VARS['pid']) || isset($HTTP_POST_VARS['pid']) )
{
   $pid = ( isset($HTTP_GET_VARS['pid']) ) ? $HTTP_GET_VARS['pid'] : $HTTP_POST_VARS['pid'];
   
   if ($pid == 'submit')
   {
      if ( ($admin_name == "") || ($admin_user == "") || ($admin_pass == "") || ($admin_email == "") )
      {
         $error .= "<b>ERROR!</b>";
         $error .= "<br></br>";
         $error .= "<b>ALL FIELDS MUST BE ENTERED IN</b>";
         $error .= "<br></br>";
         
         include('admin_create.tpl');
      }
      else if ($admin_pass != $confirm_admin_pass)
      {
         $error .= "<b>ERROR!</b>";
         $error .= "<br></br>";
         $error .= "<b>YOUR PASSWORD AND CONFIRMATION PASSWORD DO NOT MATCH</b>";
         $error .= "<br></br>";
      }
      else
      {
         $sql = "SELECT * FROM admin_info
               WHERE admin_user = '$admin_user'
               AND admin_email = '$admin_email'";
         $result = mysql_query($sql);
         $number = mysql_num_rows($result);
         $row = mysql_fetch_array($result);
         
         if ($number == 1)
         {
            $error .= "<b>ERROR!</b>";
            $error .= "<br></br>";
            $error .= "<b>EITHER THE USERNAME OR EMAIL ENTERED IS ALREADY IN USE</b>";
            $error .= "<br></br>";
            
            include('admin_create.tpl');
         }
         else
         {
            $admin_pass = md5($user_pass);
            $admin_since = date("F j, Y");
            $admin_date = date("F j, Y");

            $sql = "INSERT INTO admin_info (admin_id, admin_name, admin_user, admin_pass, admin_email, admin_since, admin_date, admin_title, admin_logins, admin_auth, admin_active, admin_deactive)
                  VALUES ('', '$admin_name', '$admin_user', '$admin_pass', '$admin_email', '$admin_since', '$admin_date', 'Admin', '$admin_logins', 1, '', '');";
            mysql_query($sql);
            
            $sql = "SELECT * FROM admin_info
                  WHERE admin_name = '$admin_name'";
            $result = mysql_query($sql);
            $number = mysql_num_rows($result);
            $row = mysql_fetch_array($result);
            
            $admin_id = $row['admin_id'];
            $admin_title = "User Created Successfully!";
            $admin_message .= "The following user has been created successfully:";
            $admin_message .= "<br></br>";
            $admin_message .= "Name: $admin_name</br>";
            $admin_message .= "Username: $admin_user</br>";
            $admin_message .= "Email: $admin_email</br>";
            
            include('admin_created.tpl');
         }
      }
   }
}
else
{
   include('admin_create.tpl');
}

?>


When I go into localhost and into phpMyAdmin I have one error toward the bottom that says:

Cannot load mcrypt extension. Please check your PHP configuration.


I'm not sure if that is what the problem with the SQL is, so if not then you can ignore that statement. But please help with the other!

...

PostPosted: 26. April 2007 05:20
by stabby
Is mysql installed as a service?

PostPosted: 27. April 2007 07:48
by Kacedawg21
I'm assuming MySQL is installed as a serive, because my XAMPP Control Panel says it is, and if I simply put in direct information for the fields it will insert it through the webpage, such as:

Code: Select all
$sql = "INSERT INTO admin_info (admin_id, admin_name, admin_user, admin_pass, admin_email, admin_since, admin_date, admin_title)
VALUES ('1', 'Kacey', 'Admin', '12345', 'me@email.com', 'Jan 1, 2007', 'Jan 2, 2007', 'Ruler')";


That works if I put that into a PHP page and run the script, but when I use a form and insert it this way:

Code: Select all
$sql = "INSERT INTO admin_info (admin_id, admin_name, admin_user, admin_pass, admin_email, admin_since, admin_date, admin_title)
VALUES ('', '$admin_name', '$admin_user', '$admin_pass', '$admin_email', '$admin_since', '$admin_date', '$admin_title')";


It won't work! The form doesn't even remember the information I put in if anything is left blank like it's supposed to. I'm gonna keep trying though!

PostPosted: 27. April 2007 10:28
by Wiedmann
Please put this as first line of your script:
Code: Select all
error_reporting(E_ALL);

Any output?

PostPosted: 21. May 2007 18:08
by irene
When I go into localhost and into phpMyAdmin I have one error toward the bottom that says:
Quote:
Cannot load mcrypt extension. Please check your PHP configuration.


For my Xampp installation un-commenting extension=php_mcrypt.dll in c:\xampp\apache\bin\php.ini did the trick. (Refresh the phpMyAdmin page after you restarted the Apache-server.)