4 Replies - 1204 Views - Last Post: 30 April 2012 - 09:51 AM Rate Topic: -----

#1 minaantoun  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-April 12

Approve Form problem

Posted 30 April 2012 - 05:26 AM

Hi all, I have trouble with creating an approval form as am still php beginner,

the idea is

user submit a form am setting a default value"0" in the approved row at the table..

so behind the scenes the admin shows all members from this table where approved="0"

and this is the code

 

<?php
$con = mysql_connect("localhost","ebarea_epic","...");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ebarea_epic", $con);

$query = "select * from medicalrep where approved='0'";

$result=mysql_query($query);

echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Password</th>
<th>Mobile </th>
<th>Address</th>
<th>Faculty</th>
<th>Graduation Year</th>
<th>Region</th>
<th>Area</th>
<th>Line</th>
<th>Appointment Date</th>
<th>Resign Data</th>
<th>Job Title</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['Mobile'] . "</td>";
  echo "<td>" . $row['Address'] . "</td>";
  echo "<td>" . $row['Faculty'] . "</td>";
  echo "<td>" . $row['Graduation Year'] . "</td>";
  echo "<td>" . $row['Region'] . "</td>";
  echo "<td>" . $row['Line'] . "</td>";
  echo "<td>" . $row['Area'] . "</td>";
  echo "<td>" . $row['Appointment'] . "</td>";
  echo "<td>" . $row['Resign'] . "</td>";
  echo "<td>" . $row['job_title'] . "</td>";
  
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>




I just want to add checkbox for every table user and when checked thier status changed to 1 in approved column

thanks all :)

Is This A Good Question/Topic? 0
  • +

Replies To: Approve Form problem

#2 Slice  Icon User is online

  • D.I.C Addict


Reputation: 196
  • View blog
  • Posts: 592
  • Joined: 24-November 08

Re: Approve Form problem

Posted 30 April 2012 - 05:34 AM

Well how do you think it should be done? What have you tried?
Was This Post Helpful? 0
  • +
  • -

#3 minaantoun  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-April 12

Re: Approve Form problem

Posted 30 April 2012 - 05:38 AM

View PostSlice, on 30 April 2012 - 05:34 AM, said:

Well how do you think it should be done? What have you tried?


at this point and i STOPPED !!

I just don't know how to make this check box and the submit button in this form :S !!
Was This Post Helpful? 0
  • +
  • -

#4 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Approve Form problem

Posted 30 April 2012 - 06:13 AM

Hi,

Well for starters you would need a form. You would want to add an <input type = "checkbox" /> for each of your records. You would need to tie each checkbox to a record from your database, giving it a value equal to the primary key of the record is one way to do that. Once the form is submitted you would go through each of the values and update the approved field accordingly.

This post has been edited by Jstall: 30 April 2012 - 06:14 AM

Was This Post Helpful? 1
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • Posts: 8,526
  • Joined: 08-August 08

Re: Approve Form problem

Posted 30 April 2012 - 09:51 AM

You do need a form, but let's look at your PHP code too. Specifically your while loop. It's long and repetitive. That makes it hard to read, especially as your code grows.

I don't recommend using mysql functions. You should read up on prepared statements, but that aside, look at this:
$expected = array("ID","username","password","Mobile","Address","Faculty","Graduation Year","Region","Line","Area","Appointment","Resign","job_title");
while($row = mysql_fetch_array($result))
{
	echo "<tr>";
	foreach($expected as $key)
	{
		echo "<td>".$row[$key]."</td>";
	}
	echo "</tr>";
}

It does what your loop does, but in a more compact way. If we needed to add/remove an item we would only need to edit the $expected array.

Now let's add some error handling. What would happen in your code if the 'Line' field (or some other field) was removed from the database? Would you know something was wrong?
$expected = array("ID","username","password","Mobile","Address","Faculty","Graduation Year","Region","Line","Area","Appointment","Resign","job_title");
while($row = mysql_fetch_array($result))
{
	echo "<tr>";
	foreach($expected as $key)
	{
		if(isset($row[$key])) {
			echo "<td>".$row[$key]."</td>";
		} else {
			echo "<td>".$key." is not set!</td>";
		}
	}
	echo "</tr>";
}

If you were to add this error detection to your version the loop would be more than twice as long as it is now, and much harder to read.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1