hi,
i had written two programs and those are working fine but my Team Lead wants that two programs to be in one single page. i used post method so if i place it in single page i am getting error. so can anybody...
Thank u.

-----projectcreation.php--------

<html>
<body>
<script language="javascript" type="text/javascript">
		function check()
		{
			if(document.getElementById('txtname').value == "")
			{
				alert('Please enter projectname');
				return false;
				
			}
			
            if(document.getElementById('createdby').value == "")
            {
                alert('Please enter createdby');
                return false;
            }
		}
	</script>

<form action="insertproject.php" method="post">
<table align="center">
	
	
	<tr>
		<td style="color: navy;">projectname</td>
		<td><input id="txtname"  type="text" name="projectname"></td>
	</tr>
	
	<tr>
		<td style="color: navy;">allocated memory</td>
		<td><input type="text" name="allocatedmemory"></td>
		<td><select name="size">
		<option value="MB">MB</option>
		<option value="KB" selected="selected">KB</option>
		</select>
		</td>
	</tr>
   
    
    
	<td></td>
	    <td><input type="submit" name="btn" value="Submit" onclick="return check();"></td>
</table>
</form>
</body>
</html>

-----insertproject.php------

<?php
$id=$_GET['f1'];
@session_start();
require_once ("check.php");
createsessions($username,$password,$userid,$projectid,$projectname,$filename,$size,$allocatedmemory,$answer,$usedmemory,$Remainingmemory,$result);
$con=mysql_connect("10.70.1.248","invensis","invensis");
if(!$con)
	{
		die('Could not connect: ' . mysql_error());
	}         
mysql_select_db("database_myproject",$con);

if($_POST[size]== 'MB')
{
     $am=$_POST[allocatedmemory] ;
     $result=$am*1024;
      
}
else{
      $am=$_POST[allocatedmemory] ;
      $result = $am;
      
}
if($_POST[size]== 'KB')
{
    $am=$_POST[allocatedmemory];
    $test=round($am/1024,4);
    echo "$test";
}
else{
    $am=$_POST[allocatedmemory];
    $test=$am;
    echo "$test";  
}
if( $result < $Remainingmemory)
{
$sql="INSERT INTO projects(projectname,allocatedmemory,createdby)
VALUES ('$_POST[projectname]','$test MB','$_SESSION[username]')";
echo "New Project Added";
if(!mysql_query($sql,$con))
 {
 	die('Error:' . mysql_error());
 }
}                                          
else  
{                                     
echo "<script language='javascript'>
            alert('Insufficient Memory');
           </script>";
} 
                    
?>

these are the two pages i need to place in single page.

Recommended Answers

All 3 Replies

why does he want it all on one page? seems odd

ok it seems i get a hint of what you want to do you try to post a form or something and your team leader wants the code to be in a single script. then all you got to do is just copy out the php script in the second page unto the topmost part of your first script before any html content and try and do an if post check on it. then change your form action on the first page to the first page name.i hope this helps

Member Avatar for rajarajan2017

You only validate some of the things in the first file, so as your lead suggested integerate the both as a single file, and check the submit to make the action that is trigger on the same page.

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.