Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Disable a button using php

    PHP Code:
    $query "SELECT * FROM accdtl where icnumber = 123456-00-0012"
    $result mysql_query($query) or die(mysql_error()); 
    $ic=$row->icnumber
    if (
    $ic == 123456-00-0012) { 
         
    $disabled 'disabled = "disabled"'
         } 
    else{ 
         
    $disabled ""
         } 
    PHP Code:
    <form> 
    <input type="button"  onClick="window.print()" value="Print" <?php echo $disabled ?> > 

    </form>
    I am confused bcoz still the button works on click.
    Can i use javascript, but i dont want to use it.
    Any help will be appreciated
    Thanks.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try
    PHP Code:
    $query "SELECT * FROM accdtl where icnumber = 123456-00-0012"
    $result mysql_query($query) or die(mysql_error()); 
    $ic=$row->icnumber
    if (
    $ic == '123456-00-0012') { 
         
    $disabled 'disabled = "disabled"'
         } 
    else{ 
         
    $disabled ""
         } 
    you need to put the string in quotes. Without them the if condition is never true. You probably learn to view the source of your pages. If it isn't as expected then its obvious the condition was met.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the whole code:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","root","adil");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("db"$con);

    $query "SELECT * FROM accdtl where icnumber='123456-00-0012'";
    $result mysql_query($query) or die(mysql_error());
    $ic=$row->icnumber;
    if (
    $ic == '123456-00-0012') {
         
    $disabled 'disabled="disabled"';
         }
    else{
         
    $disabled "";
         }

    echo 
    "<table class='text' align=Center CELLSPACING='0'BORDERCOLOR='#007FFF' BGCOLOR='cornsilk' border='1'>
    <tr><th colspan=12><Font face='Verdana'size='3'>Official Receipt</th></Font>
    <tr>
    <th><Font size='1'>Customer IC</th></Font>
    <th><Font size='1'>Acc Code</th></Font>
    <th><Font size='1'>Active</th></Font>
    <th><Font size='1'>Date</th></Font>

    </tr></tr>"
    ;while($row mysql_fetch_array($result))
      {    
      echo 
    "<tr>";
      echo
    "<td>" $row['icnumber'] . "</td></font>";
      echo 
    "<td>" $row['acccode'] . "</td></font>";
      echo 
    "<td>" $row['active'] . "</td></font>";
      echo 
    "<td>"$row['date'] . "</td></font>";      
      echo 
    "</tr>";
      }
    echo 
    "</table>";mysql_close($con);
    echo 
    '
    <form>
    <input type="button"  onClick="window.print()" value="Selection by Set"  <?php echo $disabled?> >
    </form> 
    '

    ?></strong></a>
           </p>
        </body>
        </html>
    The page is working but the button is still enable.
    Any idea.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yeah you tried running php inside of the echo. You need to do this instead.
    PHP Code:
    echo '
    <form>
    <input type="button"  onClick="window.print()" value="Selection by Set" '
    .$disabled.'>
    </form> 
    '

    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try changing this:
    Code:
    $disabled = 'disabled = "disabled"';
    to this
    Code:
    $disabled = "disabled";

  • #6
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeh i try that but still the problem is,
    I dont know why its not working.

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I'm guessing you missed my post. Its about 3 posts up. Read it.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No i apply both posts change
    Its this now:
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","root","********");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("db"$con);

    $query "SELECT * FROM accdtl where icnumber='123456-00-0012'";
    $result mysql_query($query) or die(mysql_error());
    $ic=$row->icnumber;
    if (
    $ic == '123456-00-0012') {
         
    $disabled "disabled";
         }
    else{
        
    $disabled "";
       }

    echo 
    "<table class='text' align=Center CELLSPACING='0'BORDERCOLOR='#007FFF' BGCOLOR='cornsilk' border='1'>
    <tr><th colspan=12><Font face='Verdana'size='3'>Official Receipt</th></Font>
    <tr>
    <th><Font size='1'>Customer IC</th></Font>
    <th><Font size='1'>Acc Code</th></Font>
    <th><Font size='1'>Active</th></Font>
    <th><Font size='1'>Date</th></Font>

    </tr></tr>"
    ;while($row mysql_fetch_array($result))
      {    
      echo 
    "<tr>";
      echo
    "<td>" $row['icnumber'] . "</td></font>";
      echo 
    "<td>" $row['acccode'] . "</td></font>";
      echo 
    "<td>" $row['active'] . "</td></font>";
      echo 
    "<td>"$row['date'] . "</td></font>";      
      echo 
    "</tr>";
      }
    echo 
    "</table>";mysql_close($con);
    echo 
    '
    <form>
    <input type="button"  onClick="window.print()" value="Selection by Set"  '
    .$disabled.' >
    </form> 
    '

    ?>
    Last edited by firepages; 03-06-2007 at 12:58 AM. Reason: removed db password

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Please post the html that gets generated on that page. Also its probably not wise to post your database connection info on the forums.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for reply.
    1st i dont have more code this is the complete code,may u will
    help how to make it working.
    2nd this connection details is not for server this is just for my local
    pc.For the server i have different.
    First i check my pages on my pc when ok then i upload it to server.
    Hope for help.
    Thanks.

  • #11
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Any suggestions guys?

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Sighs what I meant was I need to see the html that is generated when it gets to the client. I don't want to see all of the php stuff.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    $disabled is empty for whatever reason. First guess would be if ($ic == '123456-00-0012') is false.

  • #14
    New Coder
    Join Date
    Jan 2007
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys for ur time and help.
    I make some changes in the script and its works.

  • #15
    New Coder
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    can u show us the correct script for our reference pls?


  •  

    Posting Permissions

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