Page 1 of 1

PHP Serveral forms problem :Please help emergency

Posted: Thu May 31, 2012 10:26 am
by Natali25
Hi everybody,
Here is the code for creating a website,please have a look on the attachment(It shows how my web page looks like).I have 3 forms in each row and I have almost 2000 rows.

1)my problem is whenever I choose an option from one of the forms,It shows the result for the whole coulmns (example :If I choose passed on the first row and I click submit ,It shows passed for the all the rows in this column)
So please help me if you can give me a script that it works properly.

2)Also I have another problem.my problem is each form works seprately from the other.I mean I can not see the result of 3 forms together.it does not save the result from the previous column?

Code: Select all

<html>
<head>
</head>
<body>

<font size="6">
<?php
$db_host ="localhost";
$db_username ="***";
$db_pass ="****";
$db_name ="****";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to mySQL");
@mysql_select_db("$db_name") or die ("No database");


$sql ="SELECT * FROM `item_shop`";   //Select everything from the Database Where the columt Id = $id
$result = mysql_query($sql);
echo "<table border='1' width='100%' align='center' cellpadding='6' cellspacing='1' bgcolor='#CCCCCC' class='font_2'>"; //Begin of the Table
?>

<tr align="center" valign="middle">
	
    <td width="6%" bgcolor="#FFA07A" ><a href="?order=orgobjid&account_id=&send=send&keytype=GUID&keyword=&seq=desc">ID</a></td>
    <td width="12%" bgcolor="#FFA07A" >Name</td>
    
    <td width="1%" bgcolor="#FFA07A" >Stacked Number:\32</td>
    <td width="32%" bgcolor="#FFA07A" >Description</td>
    <td width="6%" bgcolor="#FFA07A" >Type </td>
    <td width="20%" bgcolor="#FFA07A" >Used Type</td>
	<td width="8%" bgcolor="#FFA07A" >Verification</td>
	<td width="8%" bgcolor="#FFA07A" >Item Flag</td>
	<td width="40%" bgcolor="#FFA07A" >Test Comment</td>
	
	
</tr>

<?php
while($row = mysql_fetch_array($result))
{
?>
    <td width="6%" bgcolor="#FFDEAD" ><a href="?order=orgobjid&account_id=&send=send&keytype=GUID&keyword=&seq=desc"><?php echo $row['ID']; ?></a></td>
    <td width="12%" bgcolor="#FFDEAD" ><?php echo $row['Name']; ?></td>
    
    <td width="1%" bgcolor="#FFDEAD" ><?php echo $row['Stacked_Number']; ?></td>
    <td width="32%" bgcolor="#FFDEAD" ><?php echo $row['Description']; ?></td>
    <td width="6%" bgcolor="#FFDEAD" ><?php echo $row['Type']; ?> </td>
    <td width="20%" bgcolor="#FFDEAD" ><?php echo $row['Used_Type']; ?></td>


	 <td align="center" bgcolor="#FFDEAD">


  
 <form method="post" action="http://****.php"">
Test Result?
<select name="Choose One">
<option>Choose One</option>
<option>Passed</option>
<option>Blocked</option>
<option>Retest</option>
<option>Failed</option>
</select><br>
<input type="submit" value="Submit">
<td align="center" bgcolor="#FFDEAD">
</form>

<form method="post" action="http://*****.php">
Item Flag?
<select name="degree">
<option>Choose One</option>
<option>Item Shop</option>
<option>Phirius Tocken Shop </option>
<option>Both</option>
</select>
<br><input type="submit" value="Submit">
</form>


 <td align="center" bgcolor="#FFDEAD">
<form method="post" action="http://****.php">
<textarea rows="5" cols="20" wrap="physical" name="comments">
<?php echo $row['Test_Comment']; ?>
</textarea><br>

<input type="submit" value="Submit">
<input type="reset" value="Reset">

</form>


<td align="center" bgcolor="#FFDEAD">
   <table border="1">
      <tr><td>
      <form name="Form1" method="POST" action="http://***.php">
          
         <br/>
          <textarea name="txtMessage" cols="30" rows="4"></textarea>
           <br />
           <input type="submit" name="Submit" value="Submit" />
            <input type="reset" name="Submit2" value="Reset" />
         </p>
        </form>
       </td></tr>
       </table>
	   
	   
   <pre>
   
   <? echo $_POST['txtMessage']; ?>
   </pre>
   </p>

<?php
echo "</tr>";
}
echo "</table>"; //End of the Table  
?>
</body>
</html>

Re: PHP Serveral forms problem :Please help emergency

Posted: Thu May 31, 2012 10:55 am
by Celauran
Natali25 wrote:I have 3 forms in each row
Why?

Re: PHP Serveral forms problem :Please help emergency

Posted: Thu May 31, 2012 1:13 pm
by temidayo
Your form tags are overlapping. make sure the tags are separate and standing outside each other e.g <form></form>.... <form></form>....<form></form>

Re: PHP Serveral forms problem :Please help emergency

Posted: Thu May 31, 2012 1:21 pm
by Celauran
temidayo wrote:Your form tags are overlapping.
No they aren't, there's just an extraneous </form> tag.

Re: PHP Serveral forms problem :Please help emergency

Posted: Thu May 31, 2012 8:26 pm
by califdon
Yes, there is at least one extra closing </form> tag, but the basic problem is the design of such a user interface. It may be possible to do it the way you've set it up, but I would not do it that way. The usual interface is to have a single "Edit" button in each row, and when that button is clicked, that row is displayed in another window, with a single form that the user can edit. That can be extended to allow multiple rows to be edited, but that requires more code, and would probably be used only if it's expected that many rows will need to be edited in one session. If you may have a thousand rows, I don't think you want to display all of them on the same web page! In other words, I think the whole user interface needs to be reconsidered.

Re: PHP Serveral forms problem :Please help emergency

Posted: Fri Jun 01, 2012 3:55 am
by Natali25
Thanks alot for all your replies.Yes you are right.I deleted the extra </form> and I edited my code.yes I think your idea is better.but what I should do with the last three columns ?I mean for example what I should put under Item flag for each row as default?
my next step is that I have to enter all the form result in the database.Also I have to make a search bottom that the user can search the item information based on the item ID or Item name.
So what is the easiest way to do that???
If I Do not make an edit bottom and simply want to change this script how can I change it?Because I have put all of them in the while loop .but I want to have the result of each row separately on the same page???????????

Re: PHP Serveral forms problem :Please help emergency

Posted: Fri Jun 01, 2012 11:52 am
by califdon
You are asking questions that would take many, many hours of discussion, clarification, and explanation to answer. A forum is not a practical place to learn how to design a user interface. I will suggest a few questions you should ask yourself, to clarify your objectives:
  • What is the purpose of this page? Is it to display the content of the database? Is it to select one or a few rows to edit? Is it to edit certain rows? (And the answer is NOT "all of the above".)
  • Is it really necessary to display all 2,000 rows? Are there criteria by which only the rows that may need editing could be displayed?
  • How many rows will the user need to update during one session, typically?
  • After updating some rows, is it necessary to confirm by re-displaying those rows?
Think of this operation from the viewpoint of the user. If you were using this application, what would make sense to you? How would you know which rows needed to be updated? How would you know what selections to choose? What mistakes would you be likely to make?

Re: PHP Serveral forms problem :Please help emergency

Posted: Mon Jun 04, 2012 4:03 am
by Natali25
Thanks for your reply.
1)The purpose of this page is to show the contents of the database,also it should be possible to change the last columns in the database.I mean if I select sth on the website ,and I click submit it should be saved in the database as well.and If i change sth in the database it should shows the change on the website.

2)It is necessary to show all the 2000 rows at the beginning,when sb login.but when sb search an item only based on the rows Name or ID.It only shows that specified result.

3)The user should be able to search any item that he want and then update them if he wants.(This website is for testing some items and it will update the result whenever a tester update the result)

4)I want that anything a user update when the user click submit .It should shows the the same page with the updated result.the update will remain until sb else update the same item again.the update result should goes to the database as well.

It was some explanation that u can have a better understanding.But I guess my code is ok.But at this time,I just want to add some if else statement in the in submit code that I can have the result of each form separately and the result will be submitted to the same page.
Could you please write that script for me???I really Do not know how to write it.because whatever I try, I realized that my while loop do not let me to do that?

Re: PHP Serveral forms problem :Please help emergency

Posted: Mon Jun 04, 2012 1:32 pm
by califdon
I'm sorry, but "The purpose of this page is to show the contents of the database" is not helpful. It doesn't explain what the real purpose of the page is. I can't even imagine a web page that displays 2,000 rows of data! It would mean more if you said something like "The user will submit a search request for records that meet certain criteria based on Name and Type of item, then the user will be able to update 3 specific columns in those records." You don't need to say that the updates will be stored in the database, that's what "update" and "edit" means.

Now we are back to the issue of having so many <form>s on this page. This seems to me to be a bad practice. Even if the user might only need to update one column, it could all be done with one submit for each row.

It seems that your main question, then, is how to display the updated data. If you save the search criteria, either in hidden fields of the form, or in session variables, all you need to do is refresh the page after you update the database, in your *****.php script.

Re: PHP Serveral forms problem :Please help emergency

Posted: Mon Jun 04, 2012 1:40 pm
by Celauran
If you really insist on displaying everything from the database, at least look into pagination. I also still don't understand why you need three forms per item.