Results 1 to 9 of 9

Thread: variable problem

  1. #1

    Thread Starter
    Hyperactive Member samsyl's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    338

    variable problem

    can anyone tell me why $btnSubmit doesnt show any value?
    it works wen i run in my pc
    but wen i upload to my server it doesnt show any value

    thanks

    <?php
    echo("Hi");
    echo($btnSubmit);
    ?>

    <html>
    <body>
    <form name="frm1">
    <table border='0' align='center'>
    <tr>
    <td align='centre'>Enter Admin Password</td>
    </tr>
    <tr>
    <td><input type="password" name="txtpass"></td>
    </tr>
    <tr>
    <td align='center'><input type="submit" value="Enter" name="btnSubmit"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: variable problem

    Several things are wrong with your code.

    #1 You have no method on your form. It should be either POST or GET or else the server has no idea what kind of data it is dealing with.

    #2 You're echoing a variable that has never been set. I'm not sure how it ever worked for you.

    What exactly are you attempting to do with this?

    Here is what I think you're attempting to do.

    Code:
    <?php
    echo("Hi," . $_POST['name']);
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>POST Example</title>
    </head>
    <body>
      <form name="frm1" method="post" action="">
        <table border='0' align='center'>
          <tr>
           <td align='center'>Enter Admin Password</td>
          </tr>
          <tr>
            <td><input type="text" name="name" id="name" /><input type="password" name="txtpass" id="txtpass" /></td>
          </tr>
          <tr>
            <td align='center'><input type="submit" value="Enter" name="btnSubmit" /></td>
         </tr>
       </table>
      </form>
    </body>
    </html>
    Now the above code works as I think you intended, but the code still needs a lot of work.

    I would recommend following the tutorials below for some help.

    XHTML: http://www.w3schools.com/xhtml/default.asp
    PHP: http://www.w3schools.com/php/default.asp
    Last edited by kfcSmitty; May 21st, 2009 at 08:59 AM.

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: variable problem

    $btnSubmit would be defined, it just means that register_globals is on on his local installation. however, this is bad practice, and I would definitely follow the advice above. and also, try putting [php][/php] or [code][/code] tags around your code in the future!

  4. #4

    Thread Starter
    Hyperactive Member samsyl's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    338

    [RESOLVED] Re: variable problem

    thanks both of u for ur help

  5. #5

    Thread Starter
    Hyperactive Member samsyl's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    338

    Re: variable problem

    now following code working in server but not in my pc.
    i m using Apache 1.3 and PHP4
    anything wrong with software versions?

    Code:
    <?php
    if ($_POST['btnSubmit'])
    	{
    	$logpass = $_POST['txtpass'];
    
    	mysql_connect ("127.0.0.1");
    	mysql_select_db("huntandblake");
    
    	$res=mysql_query("select * from logid where logincode='$logpass'");
    
    	$row=mysql_fetch_array($res);
    	if(!($row))
    		{
    		header("location:index.html");
    		}
    	else
    		{
    		header("location:AdminHome.PHP");
    		}
    	}
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>POST Example</title>
    </head>
    <body>
      <form name="frm1" method="post" action="">
        <table border='0' align='center'>
          <tr>
           <td align='center'>Enter Admin Password</td>
          </tr>
          <tr>
            <td><input type="password" name="txtpass" id="txtpass" /></td>
          </tr>
          <tr>
            <td align='center'><input type="submit" value="Enter" name="btnSubmit" /></td>
         </tr>
       </table>
      </form>
    </body>
    </html>

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: variable problem

    Where is it failing?

    Also, you should not do

    Code:
    if ($_POST['btnSubmit'])
    Because if a user is in IE and hits enter rather than clicking on the button to submit your form, that field will be blank.

    See the below post for more detail.

    http://www.vbforums.com/showthread.php?t=562749



    *edit* I just checked it and it does not send it through properly from what I can tell.

    If you use the PHP function str_split, you can split it on a # of characters though.

    Code:
    $textLineByLine = str_split($_POST["area"],13);
    Last edited by kfcSmitty; May 22nd, 2009 at 08:03 AM.

  7. #7

    Thread Starter
    Hyperactive Member samsyl's Avatar
    Join Date
    Jun 2001
    Location
    London
    Posts
    338

    Re: variable problem

    its failing to understand this condition

    if ($_POST['btnSubmit'])

    i dont know y? its working in server but my pc its always false.

    thanks for reply

  8. #8
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: variable problem

    The link in my previous post should point you in the right direction.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: variable problem

    You should use isset instead.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width