Need professional help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, remove this portion of code:

Code: Select all

<?php

    //if there's exactly one result, the user is validated. Otherwise, he's invalid
    if(1 == mysql_num_rows($result)) {
        echo 'validated';
    }
    else {
        echo 'not valid';
    } 

?>
And replace it with:

Code: Select all

<?php

echo mysql_num_rows($result);

?>
Without the opening and closing PHP tags of course. See what that does.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

ok where getting there i got this:

Code: Select all

?php session_start(); ?> Ok, we are about to start: 07-18-2004 12:06 PM.
Fatal error: Call to undefined function: mysql_connect() in /var/www/Esgames4uweb/validate.php on line 19


I have to ask you guys about every error because im not very experienced with php
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Check your apache config file to ensure that the mysql module is enabled. You may just have to uncomment a line.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This could very well be a php.ini extension problem as well. Check to make sure the mysql (or mysqli) extension is enabled in the php.ini file.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

yes, it is enabled and how would i uncomment the line? Should i have mysql trace mode on as well?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That's really weird. If the mysql extensionis enabled in your php.ini then you shouldn't be getting the error you got. I will have to think about this one for a bit.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Excellent resource. I had no idea that mysql support did not come with RedHat. That is very interesting.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

What line exactly is that mysql extension at anyways? I think i mistaked another extension. :D and cant find it.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


THis is what my current code im trying to get to work looks like:

Code: Select all

<?php
session_start();
?>
<html>
<head>
<title>validate.php</title>
</head>
<body>
Ok, we are about to start: <?php echo date("m-d-Y g:i A"); ?>.
<?php
if (isset($_POST))
{
   $user_name = $_POST['user_name'];
   $password = $_POST['password'];
   $db_user = 'mysql_username';
   $db_pass = 'mysql_password';

   //connect to the DB and select the "dictator" database
   $connection = mysql_connect('localhost', $db_user, $db_pass) or
die(mysql_error());
   mysql_select_db('Esgames4ulogin') or die(mysql_error());

   //set up the query
   $query = "SELECT * FROM users
           WHERE user_name='$user_name' AND password='$password'";
   // Test output of something
   echo $query . "<br />\n";

   //run the query and get the number of affected rows
   $result = mysql_query($query, $connection) or die('error making
query: ' .mysql_error());

echo mysql_num_rows($result);

}
else
{
   echo 'There was nothing posted...';
}
?>
OK, finishing up: <?php echo date("m-d-Y g:i A"); ?>.
</body>
</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Cheeseboy wrote:

Code: Select all

$query = "SELECT * FROM users
           WHERE user_name='$user_name' AND password='$password'";
SQL Injection alert. Read through the security forum posts to find out how to fix that.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

How are the variables $user_name and $password defined? Are they coming through post, cookies, get or sessions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's your code, look at it. Your answer is right above the quoted code.
User avatar
Cheeseboy
Forum Commoner
Posts: 67
Joined: Thu Mar 23, 2006 2:43 pm

Post by Cheeseboy »

I found this:
Code:

Code: Select all

Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
;   extension=modulename.extension
;
; For example, on Windows:
;
;   extension=msql.dll
;
; ... or under UNIX:
;
;   extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here.  Specify the location of the extension with the
; extension_dir directive above.
;
; Load the MySQL module by default.  Comment this out if you don't use MySQL.
extension=mysql.so

; Load the gettext extension by default.  Comment this out if you don't have the
; gettext shared library installed.
extension=gettext.so
Heres my extensions:

Code: Select all

;Windows Extensions
;Note that MySQL and ODBC support is now built in, so no dll is needed for it.
;;extension=php_mbstring.dll
;extension=php_mbstring.dll                                                 
;extension=php_bz2.dll
;extension=php_cpdf.dll
;extension=php_crack.dll
;extension=php_curl.dll
;extension=php_db.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_dbx.dll
;extension=php_domxml.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_hyperwave.dll
;extension=php_iconv.dll
;extension=php_ifx.dll
;extension=php_iisfunc.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_java.dll
;extension=php_ldap.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_mssql.dll
;extension=php_msql.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_oracle.dll
;extension=php_pdf.dll
;extension=php_pgsql.dll
;extension=php_printer.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_sockets.dll
;extension=php_sybase_ct.dll
;extension=php_w32api.dll
;extension=php_xmlrpc.dll
;extension=php_xslt.dll
;extension=php_yaz.dll
;extension=php_zip.dll
Heres some more info that show my extensions and that i dont have the extension=php_mysql
Post Reply