PHP 4.2.3 problem with submit

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

Post Reply
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

PHP 4.2.3 problem with submit

Post by lloydie-t »

I am having a problem with a php script I have re-used from a linux server to a windows server. I am getting the following error:
Notice: Undefined variable: submit in c:\program files\apache group\apache\htdocs\support\desk\dlogin.php on line 17

The offending line is:

Code: Select all

<?php
session_start();
?>
<html>

    <head>
        <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
        <meta name="generator" content="Adobe">
        <title>Welcome to iTouch Europe Support</title>
    </head>
<?php

if (!$submit)
{?>

// some html stuff

<table width="689" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="10"></td>
                <td>
                    <form name="FormName" action="<?php echo $php_self; ?>" method="post">
                        <p><b><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="4">Please enter your Username and Password:</font></b></p>
                        <table border="0" cellpadding="2" cellspacing="2" width="271">
                            <tr>
                                <td colspan="2" bgcolor="#ff6600" width="275">
                                    <div align="center">
                                        <font size="2" color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>The page you have requested is available to registered user only. If you are already registered, please enter:</b></font></div>
                                </td>
                            </tr>
// more html stuff

    <?php }
        else
        {
        include('connect.php');
        $connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database");
        mysql_select_db($db) or die ("Unable to select database: $db ");
        
//etc.
//etc.
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Post by lloydie-t »

Sorry Volka you are right I should of mentioned that I had already tried the following Line:

Code: Select all

if ( ! $_REQUEST[ "submit" ] )
which gave a diffirent error again
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

which html-element did you name how submit ?
lloydie-t
Forum Commoner
Posts: 88
Joined: Thu Jun 27, 2002 3:41 am
Location: UK

Post by lloydie-t »

Hi Volka,
You won't believe the amount of work this is going to cost me. This is where I am at the moment:

Code: Select all

<?php
session_start();
?>
<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<meta name="generator" content="Adobe GoLive">
		<title>Welcome to Europe Support</title>
	</head>
<?php

$today = date("Y-m-d H-i-s");
?>
<?php

if (!isset($_REQUEST[ "submit" ]) )
{?>

//some html stuff


<form name="FormName" action="<? $_SERVER[ 'PHP_SELF' ] ?>" method="post">

//more html stuff

		<?php }
		else
		{
//this is the bit I do not like the look of 
		$username = $_POST['username'];
		$password = $_POST['password'];
		include('connect.php');
		$connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database");
		mysql_select_db($db) or die ("Unable to select database: $db ");
		
		$query = "select username, password from users where username = '$username' and password = '$password' and desk = 'Yes'";
		$result = mysql_query($query) or die ("Error in query: $query " . mysql_error() );
I tried to run the following query but came back with a syntax error from php:
$query = "select username, password from users where username = $_POST['username'] and password = $_POST['password'] and desk = 'Yes'";

Any Ideas
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try changing this:

Code: Select all

$query = "select username, password from users where username = $_POST['username'] and password = $_POST['password'] and desk = 'Yes'";
to this

Code: Select all

$query = "select username, password from users where username = $_POST[username] and password = $_POST[password] and desk = 'Yes'";
although ordinarily you need to quote array elements, it is unneccessary within a double quoted string like your SQL statement above.

Mac
Post Reply