I am making a work..in that i have a forum which contain a lots of field like Name, Age, Sex, Date of Birth, nationality, Address, Phone Number etc.
If any person who submits the forum after completing the form it will go to the admin to verify and get accept to the Approved list of persons. The Admin will only see the new added name listing. I am trying to make a page which display all the details of the person into another html page as the admin select the name.
This is the code of my admin listing page:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("year", $con);
// how many rows to show per page
$rowsPerPage = 10;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = " SELECT * FROM jan " .
" LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');
?>
<body>
<table width="100%" border="0">
<tr>
<td width="29%" ><div align="left">NAME</div></td>
<td width="17%"><div align="left">AGE</div></td>
<td width="14%"><div align="left">SEX</div></td>
<td width="25%"><div align="left">STATUS</div></td>
</tr>
<?php
// print the random numbers
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><a href="Copy of view.php?Id=<?=$row['Id']?>"><?php echo $row['Name'];?></a></td>
<td><?php echo $row['Age']; ?></td>
<td><?php echo $row['Sex']; ?></td>
<td><form id="form<?=$row['Id']?>" name="form<?=$row['Id']?>" method="post" action="adminconnect.php">
<select name="Status">
<option value="0" <?php if($row['Status'] == "On Review"){echo "selected = 'selected'";} ?>>On Review</option>
<option value="YES" <?php if($row['Status'] == "Approved"){echo "selected = 'selected'";} ?>>Approved</option>
<option value="NO" <?php if($row['Status'] == "Rejected"){echo "selected = 'selected'";} ?>>Rejected</option>
</select>
<input type="submit" value="OK" name="submit"/>
<input name="Id" id="Id" type="hidden" value="<?php echo $row['Id']; ?>" />
</form></td>
</tr>
<tr>
<?php
}
?>
</table>
<?php
/* echo $row['Name'] . $row['Age']. $row['Number'] . $row['Status'] .'<br>';
}*/
// ... more code here
// how many rows we have in database
$query = "SELECT COUNT(Name) AS numrows FROM jan";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}
}
// ... still more code coming
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection
mysql_close($con);
?>
This is the code of my view page:
<?php
$host = "localhost"; //your sql host, usually 'localhost'
$user = "root"; //username to connect to database
$pass = ""; //password to connect to database
$db = "year"; //the name of the database
mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error());
mysql_select_db($db) or die("ERROR DB:".mysql_error());
$Id = $_GET['Id'];
$sql="SELECT Name, Age, Sex FROM jan WHERE Id = '$Id'";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query))
{
echo "<p>".$row['Name'].": ".$row['Age']."</p>";
}
?>
This code showing an error like his:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in F:\www\hhhh\view.php on line 26
or it will not display anything.. pls pls help me