Jump to content

POST Help


gospabode2

Recommended Posts

Hello,

I am new to PHP and am trying to build a couple of webpages that when the first is submitted, posts to the next webpages, and the PHP recieves it, then accesses the database according to the posted variables and displays the information in a form. I have gotten this to work on other pages, so I don't see what the issue is. I am not getting any results on the next page. Only a white screen. I think there must be some error in the semantics somewhere, but I, for the life of me, cannot figure it out. Please Help! In essence, here's what it is:

First Page:

<form action="editchild2.php" method="post">
<input type="checkbox" name="checkbox[]" value="' . $row['IDa'] . '"/>
<input type="submit" value="Update Child" />

Receiving Page:

<?php
mysql_connect("database","table","password") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());
	$IDa = $_POST['checkbox'];
	$result = mysql_query("SELECT * FROM orphans WHERE IDa='$IDA'") or die(mysql_error());
	mysql_fetch_array($result) or die(mysql_error());
                $outputtable = '';

	while($row = mysql_fetch_array($result)){ 
                $idas = $row['IDa'];
		$firstname = $row['FirstName'];
		$lastname = $row['LastName'];
		$birthdate	 = $row['Birthdate'];
		$gender = $row['Gender'];
		$sponsorcount = $row['SponsorCount'];
		$createdon = $row['Created_On'];
		$changedon = $row['Changed_On'];
		$descip = $row['Despcription'];
		$pictureone = $row['PictureOne'];
		$picturetwo = $row['PictureTwo'];
		$picturethree = $row['PictureThree'];	
		$picturefour = $row['PictureFour'];
		$picturefive = $row['PictureFive'];

		$outputtable .= '<tr>' .
					'<td>ID#: </td>' .
					'<td><input type="text" name="IDa" value="' . $idas . '" readonly="readonly"/></td>' .
				'</tr>' .
				'''<tr>' . 
					'<td>First Name: </td>' . 
					'<td><input type="text" name="FirstName" value="' . $firstname . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Last Name: </td>' . 
					'<td><input type="text" name="LastName" value="' . $lastname . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Birth Date: </td>' . 
					'<td><input type="text" name="BirthDate" value="' . $birthdate . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Gender: </td>' . 
					'<td><input type="text" name="Gender" value="' . $gender . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Sponsor Count: </td>' . 
					'<td><input type="text" name="SponsorCount" value="' . $sponsorcount . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Created On: </td>' . 
					'<td><div id="calendarDiv"></div><input type="text" name="Created_On" readonly="readonly" value="' . $createdon . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Updated On: </td>' . 
					'<td><div id="calendarDiv"></div><input type="text" name="Changed_On" class="calendarSelectDate" value="' . $changedon . '"/></td>' . 
				'<tr>' . 
					'<td>Description: </td>' . 
					'<td><textarea name="Description" cols="25" rows="10"value="' . $descrip . '"></textarea></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #1: </td>' . 
					'<td><input type="text" name="PictureOne" value="' . $pictureone . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #2: </td>' . 
					'<td><input type="text" name="PictureTwo" value="' . $picturetwo . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #3: </td>' . 
					'<td><input type="text" name="PictureFour" value="' . $picturethree . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #4: </td>' . 
					'<td><input type="text" name="PictureFour" value="' . $picturefour . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #5: </td>' . 
					'<td><input type="text" name="PictureFive" value="' . $picturefive . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
				'<td><input type="submit" />';
		}
?>
<!Doctype html>
<html>
<head>
<!--Stylesheets and Stuff-->
</head>
<body>
<!--Divs and Paragraphs-->
<form action="updatechild.php" method="post">
<table border="0">
<?php print "$outputtable"; ?>
</table> 
</form>
<!--/Divs and Paragraphs-->
</body>
</html>

Whoops: Edited to Fix Stupid Mistakes.

Link to comment
Share on other sites

<input type="checkbox" name="checkbox[]" value="' . $row['IDa'] . '"/>

$IDa = $_POST['checkbox'];

mysql_query("SELECT * FROM orphans WHERE IDa='$IDA'")

 

You are defining the field as an array, but then referencing it as if it were a string. Without seeing the rest of your code, I suspect you need to reference the first element of the array:

 

$IDa = $_POST['checkbox'][0];

 

or change the checkbox so it does not create an array field:

 

<input type="checkbox" name="checkbox" value="' . $row['IDa'] . '"/>

Link to comment
Share on other sites

Thanks DavidAM, That fixed a whole lot of issues, although I still have a couple of questions, if you don't mind.

 

I copied the below method of printing it out from another tutorial, and was wondering if there is an issue with this code specifically, because when I insert it, everything goes white, but when I replace it with:

$outputtable .= "hello";

Everything works great. Here is the code, I am wondering about:


			$outputtable = '<tr>' .
					'<td>ID#: </td>' .
					'<td><input type="text" name="IDa" value="' . $idas . '" readonly="readonly"/></td>' .
				'</tr>' .
				'''<tr>' . 
					'<td>First Name: </td>' . 
					'<td><input type="text" name="FirstName" value="' . $firstname . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Last Name: </td>' . 
					'<td><input type="text" name="LastName" value="' . $lastname . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Birth Date: </td>' . 
					'<td><input type="text" name="BirthDate" value="' . $birthdate . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Gender: </td>' . 
					'<td><input type="text" name="Gender" value="' . $gender . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Sponsor Count: </td>' . 
					'<td><input type="text" name="SponsorCount" value="' . $sponsorcount . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Created On: </td>' . 
					'<td><div id="calendarDiv"></div><input type="text" name="Created_On" readonly="readonly" value="' . $createdon . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Updated On: </td>' . 
					'<td><div id="calendarDiv"></div><input type="text" name="Changed_On" class="calendarSelectDate" value="' . $changedon . '"/></td>' . 
				'<tr>' . 
					'<td>Description: </td>' . 
					'<td><textarea name="Description" cols="25" rows="10"value="' . $descrip . '"></textarea></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #1: </td>' . 
					'<td><input type="text" name="PictureOne" value="' . $pictureone . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #2: </td>' . 
					'<td><input type="text" name="PictureTwo" value="' . $picturetwo . '" /></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #3: </td>' . 
					'<td><input type="text" name="PictureFour" value="' . $picturethree . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #4: </td>' . 
					'<td><input type="text" name="PictureFour" value="' . $picturefour . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
					'<td>Picture #5: </td>' . 
					'<td><input type="text" name="PictureFive" value="' . $picturefive . '"/></td>' . 
				'</tr>' . 
				'<tr>' . 
				'<td><input type="submit" />';

Link to comment
Share on other sites

You have an extra set of single-quotes at the start of the second row.

 

$outputtable = '<tr>' .
					'<td>ID#: </td>' .
					'<td><input type="text" name="IDa" value="' . $idas . '" readonly="readonly"/></td>' .
				'</tr>' .
				'''<tr>' . // <<RIGHT HERE  

 

But must likely the problem is that you don't have a table tag. You need to start a table with <TABLE> and end it with </TABLE>.

Link to comment
Share on other sites

The Extra Quotes was IT!

I was looking all over for something like that, but after a while of looking at your own code, everything lookes fine.

I had the </table> inside of the document, I just didn't show it because it wasn't the PHP code I was worried about, but great eyes! You have been a tremendous help.

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.