Disable textbox in php?

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
truce enough
Forum Newbie
Posts: 8
Joined: Fri Sep 02, 2011 12:53 am

Disable textbox in php?

Post by truce enough »

Hi,

How to limit the amount of data sent in the database?
I wanted to do something like this

Code: Select all

<?
$result3 = mysql_query("SELECT id FROM user_comments WHERE id = '$id'");
$num_rows = mysql_num_rows($result3);
if($num_rows > 3){
	//How to disable the textbox in php??
	}

User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Re: Disable textbox in php?

Post by ok »

Which textbox?

Maybe you meant:

Code: Select all

<?
$result3 = mysql_query("SELECT id FROM user_comments WHERE id = '$id'");
$num_rows = mysql_num_rows($result3);
if ($num_rows > 3) {
    echo '<input type="text" name="textbox_name" disabled="disabled" />
}
Dodon
Forum Commoner
Posts: 64
Joined: Wed Aug 03, 2011 4:11 am
Location: Netherlands

Re: Disable textbox in php?

Post by Dodon »

I'm not really sure what you mean with "data sent in the database" but if you want to limit the search result you get from the database you can do something like:

Code: Select all

<?
 $result3 = mysql_query("SELECT id FROM user_comments WHERE id = '$id' LIMIT 0 , 3");
 $num_rows = mysql_num_rows($result3);
 if($num_rows > 3){
         //How to disable the textbox in php??
         }
?> 
The limit option in the sql query will limit the amount of results you get back from the database.

And what textbox are you trying to disable? I don't see a textbox in your code?
truce enough
Forum Newbie
Posts: 8
Joined: Fri Sep 02, 2011 12:53 am

Re: Disable textbox in php?

Post by truce enough »

Sorry for the limited info, was in a rush just now.
what i meant was that the page will check whether or not the the number of rows with the same id is more than 3.
If it is more than 3, it will automatically disable the text box preventing them from submitting.
here is the full code :D

Code: Select all

<?php session_start;
$con = mysql_connect("localhost","nchsicc","7112local");
if (!$con){
die('Could Not Connect:'.mysql_error());
}

mysql_select_db('nchsicc_nica2011',$con);


$result3 = mysql_query("SELECT * FROM post_data ORDER BY id");
$content = $row['content'];


$dates = date("l, F d, Y " );

$id = $_GET['id'];
$result3 = mysql_query("SELECT id FROM user_comments WHERE id = '$id'");
$num_rows = mysql_num_rows($result3);
$result = mysql_query("SELECT * FROM post_data WHERE id = '$id'");
$result2 = mysql_query("SELECT * FROM user_comments WHERE id = '$id' ORDER BY date_comment");
$row = mysql_fetch_array($result);



if (mysql_num_rows($result3)==0){
    header('location:view.php');
}else{

 
     // Your normal code




echo "<table class='backbtn' border='0'>";
echo "<tr>";
echo "<td class='backbtn'>" . "<a class='backbtn' href='view.php'>" . "Back" . "</a>" . "</td>";
echo "</tr>";
echo "</table>";


echo "<table class='title' border='0'>";

echo "<tr>";
echo "<td class='title'>" . $row['text'] . "</td>";  
echo "</tr>";
echo "<tr>";
echo "<td class='subtitle'>" . $row['date'] . "> </td>";
echo "</table>";


echo "<table border = '0' class='post'>";





if (isset($_POST['Submit'])){
if (empty($_POST['name']) || empty($_POST['post']))
		{
		$Text = "Please fill in all the fields.";
echo "<script type='text/javascript'>alert('{$Text}');</script>";

	}
	else
	{
	if($num_rows > 3){
	echo "This page has reached the maximum posts:D";
	}
	else{
mysql_query("INSERT INTO user_comments (id,comment,date_comment,name)VALUES ('$id','$_POST[post]','$dates','$_POST[name]')");
header('location:testing1.php?id=' . $id);
}
}
}
}

?>


	
<table class='commentbox' border='0'>
<tr>
<td>
<form class="comment" method="post" action="">
<p align="center">Name:</p><p align="center"><textarea name='name' tabindex="4" onblur="if(this.value=='')this.value=this.defaultValue" onfocus="if(this.value==this.defaultValue)this.value=''" title="name" id="comment" class="forminput" rows="3" cols="30" name="comment"  ></textarea></p>
Comments:<p align="center"><textarea name='post' tabindex="4" onblur="if(this.value=='')this.value=this.defaultValue" onfocus="if(this.value==this.defaultValue)this.value=''"  id="comment" class="forminput" rows="3" cols="30" name="comment"></textarea></p>
<p align="center"><input type="submit" value="Submit" class="submitbtn" name="Submit" onclick=”this.disabled=true“ id="Submit" /></p>
</form>
</td>
</tr>
</table>
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Re: Disable textbox in php?

Post by ok »

You can add condition for printing the text boxes, meaning that if the maximum is reached you don't print the text boxes...
truce enough
Forum Newbie
Posts: 8
Joined: Fri Sep 02, 2011 12:53 am

Re: Disable textbox in php?

Post by truce enough »

Oic, but do you have the code? cause i searched the net for a few hours but to no avail.
Is it possible to print out

Code: Select all

<table class='commentbox' border='0'>
<tr>
<td>
<form class="comment" method="post" action="">
<p align="center">Name:</p><p align="center"><textarea name='name' tabindex="4" onblur="if(this.value=='')this.value=this.defaultValue" onfocus="if(this.value==this.defaultValue)this.value=''" title="name" id="comment" class="forminput" rows="3" cols="30" name="comment"  ></textarea></p>
Comments:<p align="center"><textarea name='post' tabindex="4" onblur="if(this.value=='')this.value=this.defaultValue" onfocus="if(this.value==this.defaultValue)this.value=''"  id="comment" class="forminput" rows="3" cols="30" name="comment"></textarea></p>
<p align="center"><input type="submit" value="Submit" class="submitbtn" name="Submit" onclick=”this.disabled=true“ id="Submit" /></p>
</form>
</td>
</tr>
</table>

inside the php?
Post Reply