PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 27, 2020 10:10 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Dec 29, 2009 1:52 pm 
Offline
Forum Commoner

Joined: Sat Oct 10, 2009 2:53 am
Posts: 32
Hi all,

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 = '&nbsp;'; // we're on page one, don't print previous link
$first = '&nbsp;'; // 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 = '&nbsp;'; // we're on the last page, don't print next link
$last = '&nbsp;'; // 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 :banghead: :banghead:


Top
 Profile  
 
PostPosted: Tue Dec 29, 2009 3:53 pm 
Offline
Forum Newbie

Joined: Tue Dec 29, 2009 2:42 pm
Posts: 5
The error means your query is failing. Use mysql_error() or echo out the SQL and run it directly in phpMyAdmin or in the MySQL console to get specifics.


Top
 Profile  
 
PostPosted: Tue Dec 29, 2009 9:54 pm 
Offline
Forum Commoner

Joined: Sat Oct 10, 2009 2:53 am
Posts: 32
thanks for the replay..but i didn't get you.. :roll: can u explain my mistake through codes..

so that i can get what u mean............


Top
 Profile  
 
PostPosted: Wed Dec 30, 2009 2:35 am 
Offline
Forum Newbie
User avatar

Joined: Sat Dec 26, 2009 5:48 am
Posts: 2
echo your sql query and run directly to your phpmyadmin then u will get exact pob in your sql query..........


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group