Page 1 of 1

no action taking

Posted: Fri Sep 30, 2005 5:13 am
by rami
i have following link
http://localhost/html/giveassign2.php?uid=5
when some body clicks in : giveassignment link it goes to that page (with teachers logged in)
i have made following page for assignment...

Code: Select all

<?php 
$page_title = 'Give assignment';
if (isset($_POST['submit'])) 
{ 
	require_once ('../mysql_connect1.php');	

		if (!empty($_POST['tropic']))
				{
		$u = escape_data($_POST['tropic']);
				} else 
					{
				$u = FALSE;
				echo '<p><font color="red">Please enter a URL!</font></p>';
					}
if (($_POST['program'] > 0)) 
		{
		$p=$_POST['program'];
		} 
		else
			{
		$p = FALSE;
		echo '<p><font color="red">Please select at least one category!</font></p>';
			}	


	
	if (!empty($_POST['assignment']))
		{
		$d = escape_data($_POST['assignment']);
		} 
		else 
			{
		$d = '';
			}
	

	
	if ($u && $d) 
		{ 
if (isset($_GET['uid'])) 
	{
$tid=$_GET['uid'];
		$query = "insert into  assignment(teach_id,tropic,program,assignment) VALUES ('$tid','$u','$p','$d')";
			$result= mysql_query($query);

		if ($result)  
		{ echo '<p><b>Thank you for your submission!</b></p>';
					$_POST = array();
		} 
		else 
		{
			echo '<p>No data returned!</p>';
		}
	}
	else 
	{
		echo '<p>Student not found.</p>';
	}
	}									
}
else 
{
echo '<p><font color="red" size="+1">Please enter again.</font></p>';
}
?>
	<table border="1" width="100%" bordercolor="#0000FF" bordercolorlight="#0000FF" bordercolordark="#0000FF">
  <tr>
    <td width="100%">
     <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <p align="center">&nbsp;&nbsp;&nbsp;&nbsp; <b>Give&nbsp; Assignment</b></p>
        <table border="0" width="100%" bgcolor="#EFEFEF">
          <tr>
            <td width="100%" colspan="3" bgcolor="#00659C">
              <p align="center"><b>&nbsp;<font color="#FFFFFF">Please enter data in following fields</font></b></td>
          </tr>
          <tr>
            <td width="41%"><b>Tropic </b></td>
            <td width="59%"><input type="text" name="tropic" size="60" maxlength="60" value="<?php if (isset($_POST['tropic'])) echo $_POST['tropic']; ?>" /></td>
          </tr>
<tr>
            <td width="41%"><b>select Batch </b></td>
            <td width="59%"><select name="program"><option >select one</option>
<?php
require_once ('../mysql_connect1.php');
$query = "SELECT batch_id,program  from batch";		
$result = mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
	echo "<option value=\"{$row['batch_id']}\">{$row['program']}</option>\n";
}
mysql_close();
?>
</select></td>
          </tr>	
<tr>
<td width="41%"><b>Assignment</b></td>
            <td width="59%"><textarea name="assignment" cols="40" rows="5"><?php if (isset($_POST['assignment'])) echo $_POST['assignment']; ?></textarea></td>
          </tr>		
	 </table>
        <p>&nbsp;</p>
        <p><div align="center"><input type="submit" name="submit" value="Register" /></div></p>
      </form>
</table>		
	</form><!-- End of Form -->

<?php // Include the HTML footer.
?>
it gives message please try again ...
even if there is uid ...and
i want not to enter teachers id manually ...rather take it through other page and enter it implicitly
is this logic correct

Code: Select all

if (isset($_GET['uid'])) 
	{
$tid=$_GET['uid'];
		$query = "insert into  assignment(teach_id,tropic,program,assignment) VALUES ('$tid','$u','
the program seems complicated but i s very simple
if i remove those uid and all program works

whats the matter....
if i remove any braces or so it gives
prase error in line no 54
any help

Posted: Fri Sep 30, 2005 5:35 am
by ruchit
haven't studied your code completely... but

Code: Select all

isset($_POST['submit'])
would only work if you pressed the submit button and did not hit 'ENTER' to submit the form.... for that use a hidden field & check that

Code: Select all

isset($_POST['hiddenfield'])

Posted: Fri Sep 30, 2005 5:58 am
by Jenk
Or just use any of the fieldnames that are being submitted, it doesn't have to be a seperate field just for the job.

Posted: Sat Oct 01, 2005 7:56 am
by rami
do you mean that i can remove

Code: Select all

if (isset($_POST['submit'])) 
{

especially i want not to enter teach_id manually ..ie take it from another page and do it implicitly so is this logic right ...or will it work(not working not...)

if (isset($_GET['uid']))
{
$tid=$_GET['uid'];
$query = "insert into assignment(teach_id,tropic,program,assignment) VALUES ('$tid','$u','

fow it is done then ...
any code snnipnets...
thanks for help....
rami
really thanks..
can some body provide me 3 minutes ..i think expert can even copy that files and quick redesign that page in 3 minutes
any way thanks for help
rami