...

View Full Version : Disable a button using php



mmarif4u
03-05-2007, 07:20 AM
$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 = "";
}

<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.

_Aerospace_Eng_
03-05-2007, 07:24 AM
Try

$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.

mmarif4u
03-05-2007, 07:34 AM
This is the whole 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.

_Aerospace_Eng_
03-05-2007, 07:36 AM
Yeah you tried running php inside of the echo. You need to do this instead.

echo '
<form>
<input type="button" onClick="window.print()" value="Selection by Set" '.$disabled.'>
</form>
';

papa_face
03-05-2007, 07:38 AM
Try changing this:

$disabled = 'disabled = "disabled"';
to this

$disabled = "disabled";

mmarif4u
03-05-2007, 07:42 AM
Yeh i try that but still the problem is,
I dont know why its not working.

_Aerospace_Eng_
03-05-2007, 07:46 AM
I'm guessing you missed my post. Its about 3 posts up. Read it.

mmarif4u
03-05-2007, 07:52 AM
No i apply both posts change
Its this now:

<?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>
';
?>

_Aerospace_Eng_
03-05-2007, 08:28 AM
Please post the html that gets generated on that page. Also its probably not wise to post your database connection info on the forums.

mmarif4u
03-05-2007, 08:39 AM
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.

mmarif4u
03-06-2007, 04:07 AM
Any suggestions guys?

_Aerospace_Eng_
03-06-2007, 08:15 PM
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.

Inigoesdr
03-06-2007, 08:49 PM
$disabled is empty for whatever reason. First guess would be if ($ic == '123456-00-0012') is false.

mmarif4u
03-08-2007, 03:50 AM
Thanks guys for ur time and help.
I make some changes in the script and its works.

mya7709
10-09-2011, 08:58 AM
can u show us the correct script for our reference pls?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum