Jump to content

Problem processing edit on the same page


bugzy

Recommended Posts

My validation

 

<?php 

if(!isset($_POST['submit']))
{
if(!isset($_GET["id"]))
	{
		me_redirect_to("staff.php");
	}
}
?>

 

 

 

is redirecting me even if my $_POST['submit'] is set

 

 

here's the full code

 

 

<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require("includes/header.php"); ?>
<?php require("includes/navbar.php"); ?>
<?php require("staff_sidebar.php"); ?>




<?php 

if(!isset($_POST['submit']))
{
if(!isset($_GET["id"]))
	{
		me_redirect_to("staff.php");
	}
}
?>


<?php 

if(!isset($_POST['submit']))
{
if(!is_numeric($_GET["id"]))
	{
	me_redirect_to("staff.php");
	}
}
?>



<?php

if(isset($_GET['id']));
{

$i = 0;

$edit_proj_id = $_GET['id'];


$edit_query = "Select proj_name, content from rec_projects where proj_id = {$edit_proj_id}";

$edit_result = mysql_query($edit_query, $connection);

$num = mysql_num_rows($edit_result);

if($num != 1)
{
	me_redirect_to("staff.php");
}


$edit_proj_name = mysql_result($edit_result,$i,"proj_name");
$edit_content = mysql_result($edit_result,$i,"content");


}
?>






<div id="content">
<h1>Edit Subject</h1><br>



<?php


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


	$proj_name = me_mysql_prep(trim($_POST['proj_name']));
	$proj_content = me_mysql_prep($_POST['proj_content']);



	if(empty($_POST['proj_name']))
	{
		$empty_name = array('Project Name Cannot Be Empty');
	}

	if(empty($_POST['proj_content']))
	{
		$empty_content = array('Content Cannot Be Empty');
	}




	if(isset($empty_name) && isset($empty_content))
	{
		$error_merge = array_merge($empty_name, $empty_content);
	}
	else if(isset($empty_name))
	{
		$error_merge = array_merge($empty_name);
	}
	else if(isset($empty_content))
	{
		$error_merge = array_merge($empty_content);
	}
	else
	{
		$error_merge = array();
	}






	if(!empty($error_merge))
			  {
				  foreach($error_merge as $error)
				  {
					  echo "<span class=\"error_validation\">*". $error . "<br></span>";
				  }
			  }
			  else
			  {

						$query = "UPDATE rec_projects SET proj_name='{$proj_name}', content='{$proj_content}' where proj_id = {$edit_proj_id}";

						if($result = mysql_query($query,$connection))
						{
							me_redirect_to("edited_project.php?edited=1");
						}
						else
						{
							echo "Can\'t edit the project: ". mysql_error() . "";
						}

			  }
			  
			  echo "<br><br>";

}	


?>



<table>
<tr><td>


</td></tr>
    
</table>





<table>

<form action="edit_project.php" method="post" name="add_subject">
<tr>
<td>Project Name:</td>
    <td><input type="text" size="50" name="proj_name" value="<?php echo $edit_proj_name; ?>"></td>
</tr>


<tr>
<td>Content:</td>
<td><textarea cols="70" rows="20" name="proj_content"><?php echo $edit_content; ?></textarea></td>
</tr>


<tr>
<td></td>
<td><input type="submit" value="Edit Project" name="submit" id="submit" size="30"></td>
</tr>


</form>

</table>

</div>



<?php require("includes/footer.php"); ?>

 

 

 

It's suppose to be executing the mysql edit query but it's bypassing my validation. I wonder what the problem is..

 

Link to comment
Share on other sites

This is the perfect way to debug on your own.  How are you sure $_POST is set?  Did you print_r it?  There are 4 redirects in this code snippet, did you figure out which one is the culprit?  Insert die() statements before each redirect to identify which one it is.  Once you find it, var_dump all the variables that lead to that logical condition, and ensure they are what you expect them to be.  If one (or more) of them is not, move up in the code until you identify the fault.  This is far too much code which relies on page load effects and external files for us to find it by hand.

Link to comment
Share on other sites

Finally solve it.

 

The problem is not with the validation. The problem is with the form

 

<form action="edit_project.php" method="post" name="add_subject">

 

 

at first I will be having a value on the $_GET but once I click the submit it will redirect me to "edit_project.php" without getting any variable id on the url.

 

 

so here's what I did

 

 

<form action=<?php echo "edit_project.php?id=". $_GET["id"]; ""; ?> method="post" name="add_subject">

 

 

Solved!  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.