Jump to content

my _POST and array not working properly


mike12255

Recommended Posts

So ive created a forum that I got handling several different approvals. (it is used to approve or decline all submitted notes) it works fine and it even submits fine im at the part know where i process the information and do something with it, below is my form:

 

<form action="course_proccess.php?action=approve" method="post">
  <table align="left" border="1" cellspacing="0" cellpadding="3">
    <tr>
      <td><b>Author</b></td>
      <td><b>File name</b></td>
      <td><b>Download</b></td>
      <td><b>Suggested catagory</b></td>
      <td><b>Select Catagory</b></td>
      <td>Approve</td>
    </tr>
    
      <td><input type="text " disabled="disabled" name="tr1_author" value="MikeH" </td>
      <td><input typee="text " disabled="disabled" name="tr1_name" value="A lot of my skills set back"</td>
      <td><a href= /uzEr%20Upl0ds/cache.zip > Download</a></td>
      <td>1001 Laws - Polceing </td>
      <td><select name="tr1_scatagory">
          <option value="1"> Intro To Law </option>
          <option value="2"> 1001 Laws - Police Foundations </option>
        </select></td>
      <td><select name = "tr1_approve">
          <option value = "1"> Yes</option>
          <option value = "2"> no</option>
        </select></td>
    </tr>
      <td><input type="text " disabled="disabled" name="tr2_author" value="MikeH" </td>
      <td><input typee="text " disabled="disabled" name="tr2_name" value="MM"</td>
      <td><a href= /uzEr%20Upl0ds/Michael Heintzman.doc > Download</a></td>
      <td>1001 Laws - Polceing </td>
      <td><select name="tr2_scatagory">
          <option value="1"> Intro To Law </option>
          <option value="2"> 1001 Laws - Police Foundations </option>
        </select></td>
      <td><select name = "tr2_approve">
          <option value = "1"> Yes</option>
          <option value = "2"> no</option>
        </select></td>
    </tr>
    <input type="hidden" name="rowCount" value="2">
    <tr>
      <td><input type="submit" name="sendData" value="send"/></td>
    </tr>
  </table>
</form>

 

 

so what I do in my process file is I have a for loop for all of the "TR's" in the table and if it is approved I have an if statment and then I want to add db stuff my problem is my $_POST's are returning blank and I have no idea why. Can someone please assit me with this? (p.s i have debugged and it does get into the if approve == 1 statment.

 

if(isset($_GET['action'])){

if ($_GET['action'] == "approve"){

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

	$dataArray = array();

	$row_count = $_POST['rowCount'];
	for($i=1;$i<$row_count;$i++)
		{

			$approven = "tr".$i."_approve";
			$approve = $_POST[$approven];

			if($approve == 1)
				{
					//Move the info over to "approved files" and delete it out of newnotes
					$author = "tr".$i."_author";
					$location = "tr".$i."_location";
					$catagory ="tr".$i."_scatagory";
					$filename = "tr".$i."_name";
					$submitedby = $_POST['author'];
					die($submitedby);

					$dataArray[]=array('author'=>$author,'fileName'=>$fileName,'Catagory'=>$catagory,'location'=>$location);
					var_dump($dataArray);

				}else{
					//Email user saying they did not recive credits AND delete the entry

}
		}

	if(!empty($dataArray))
		{
			//now do what you want with the dataArray...	
			var_dumb($dataArray);			
		}
}

}

 

Link to comment
Share on other sites

Your input for author and the one under are not ended

 

Also, my bad, but $author... etc, they are now the names of the post array keys. You need another step...

 

$author = "tr".$i."_author";

$authorContent = $_POST[$author];

 

Also if you're not sure what has been posted, you can always check the post array with print_r:

print_r($_POST);

Link to comment
Share on other sites

Ok i fixed the form it now looks like this:

<form action="course_proccess.php?action=approve" method="post">
  <table align="left" border="1" cellspacing="0" cellpadding="3">
    <tr>
      <td><b>Author</b></td>
      <td><b>File name</b></td>
      <td><b>Download</b></td>
      <td><b>Suggested catagory</b></td>
      <td><b>Select Catagory</b></td>
      <td>Approve</td>
    </tr>
    
      <td><input type="text " disabled="disabled" name="tr1_author" value="MikeH"></td>
      <td><input typee="text " disabled="disabled" name="tr1_name" value="A lot of my skills set back"></td>
      <td><a href= /uzEr%20Upl0ds/cache.zip > Download</a></td>
      <td>1001 Laws - Polceing </td>
      <td><select name="tr1_scatagory">
          <option value="1"> Intro To Law </option>
          <option value="2"> 1001 Laws - Police Foundations </option>
        </select></td>
      <td><select name = "tr1_approve">
          <option value = "1"> Yes</option>
          <option value = "2"> no</option>
        </select></td>
    </tr>
      <td><input type="text " disabled="disabled" name="tr2_author" value="MikeH"></td>
      <td><input typee="text " disabled="disabled" name="tr2_name" value="MM"></td>
      <td><a href= /uzEr%20Upl0ds/Michael Heintzman.doc > Download</a></td>
      <td>1001 Laws - Polceing </td>
      <td><select name="tr2_scatagory">
          <option value="1"> Intro To Law </option>
          <option value="2"> 1001 Laws - Police Foundations </option>
        </select></td>
      <td><select name = "tr2_approve">
          <option value = "1"> Yes</option>
          <option value = "2"> no</option>
        </select></td>
    </tr>
    <input type="hidden" name="rowCount" value="2">
    <tr>
      <td><input type="submit" name="sendData" value="send"/></td>
    </tr>
  </table>
</form>

 

however I printed the post and the name and filename location are not appearing this is what appears:

Array ( [tr1_scatagory] => 1 [tr1_approve] => 1 [tr2_scatagory] => 1 [tr2_approve] => 1 [rowCount] => 2 [sendData] => send )

 

here is the process code:

if(isset($_GET['action'])){

if ($_GET['action'] == "approve"){

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

	$dataArray = array();

	$row_count = $_POST['rowCount'];
	for($i=1;$i<$row_count;$i++)
		{

			$approven = "tr".$i."_approve";
			$approve = $_POST[$approven];


			if($approve == 1)
				{
					//Move the info over to "approved files" and delete it out of newnotes
					$author = "tr".$i."_author";
					$location = "tr".$i."_location";
					$catagory ="tr".$i."_scatagory";
					$filename = "tr".$i."_name";
					$submitedby = $_POST['$author'];
					print_r($_POST);
					die("test");

					$dataArray[]=array('author'=>$author,'fileName'=>$fileName,'Catagory'=>$catagory,'location'=>$location);
					var_dump($dataArray);

				}else{
					//Email user saying they did not recive credits AND delete the entry

}
		}

	if(!empty($dataArray))
		{
			//now do what you want with the dataArray...	
			var_dumb($dataArray);			
		}
}

}

 

 

if you want to view the site its cnotes.ca although you need an admin acc to view the admin center so if u make one ill make it an admin

 

 

 

Link to comment
Share on other sites

Your tr1_name, tr2_name fields are not working because you misspelled type. You have typee

 

You don't have any form fields named tr1_location and tr2_location, so it will be a little hard to get any values for those two fields.

 

And you should use arrays for your form fields, instead of the sequentially numbered - tr1_..., tr2_... Your code will be much simpler. See this link - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays Once you do this, you can simply use php array functions, such as foreach(), to iterate over the arrays. You won't even need the rowCount value any more.

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.