Forum Moderators: coopster

Message Too Old, No Replies

PHP script issues

         

JuicyScript

10:59 pm on Nov 19, 2009 (gmt 0)

10+ Year Member



I have everyfin working.The combox loads all ryt but if($result['count']>=1) {
echo "Your session have expired";
exit();
}
Does not execute unless i equate it to 0
I want it to echo dat message but it does not.

<?php
include("./include/session.php");
//require_once('config.php');
// Connect to the database

$sql ="SELECT options from inst ";
//$result = @mysql_query($sql,$connection) or die(mysql_error());
$query = mysql_query($sql);

$sql1 ="SELECT rotation from inst ";
//$result = @mysql_query($sql,$connection) or die(mysql_error());
$query1 = mysql_query($sql1);

$sql2 ="SELECT rotation from inst ";
//$result = @mysql_query($sql,$connection) or die(mysql_error());
$query2 = mysql_query($sql2);


$sql4="SELECT options FROM inst WHERE options='Korle Bu'";
$qry=@mysql_query($sql4);
$result=@mysql_fetch_array($qry);
echo print_r($result);

if($result['count']>=1) {
echo "Your session have expired";
exit();
}
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;";
if($session->isAdmin()){
echo "[<a href=\"admin/admin.php\">Admin Center</a>] &nbsp;&nbsp;";
}
echo "[<a href=\"process.php\">Logout</a>]";
}
else{
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="images/templ.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center" class="FormInput">

<p>&nbsp;</p>
<div align="center"></div>
<table width="63%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="separtext">
<td valign="middle" class="separtext"><img src="images/icon_info-1.gif" alt="warning" width="29" height="29" /></td>
<td valign="middle" class="separtext">Please complete this brief registration form.Enter Your Detail Correctly Leaving No Information Out. All sections marked with an <span class="aster">*</span> are mandatory.</td>
</tr>
</table>
<p>&nbsp;</p>
<table width="742" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<td width="742" height="465"><form action="insert_new.php " method="post" name="insert_new_personal.php" id="insert_new_personal.php">
<table align="center" class="FormInput">
<tr>
<td width="193"><span class="aster">*</span>Mr/Mrs/Miss</td>
<td width="381"><input name="Mr" type="text" value="" size="4" id="Mr" /> </td>
</tr>
<tr>
<td width="193"><span class="aster">*</span>Sur Name</td>
<td width="381"><input name="surname" type="text" value="" size="20" id="surname" /> </td>
</tr>
<tr>
<td width="193"><span class="aster">*</span>Other Names</td>
<td width="381"><input name="othernames" type="text" value="" size="40" id="othernames" /> </td>
</tr>

<tr>
<td width="193" height="43"><span class="aster">*</span>Sex</td>
<td width="381"><input type="radio" name="gender" value="Male" />
Male
<input type="radio" name="gender" value="Female" checked="checked" />
Female </td>
</tr>
<tr>
<td width="193"><span class="aster">*</span>Trainee ID</td>
<td width="381"><input name="trainee" type="text" size="40" id="trainee" /> </td>
</tr>
<tr>
<td width="193"><span class="aster">*</span>Institution Attended</td>
<td width="381"><input name="instattended" type="text" size="40" id="instattended" /> </td>
</tr>
<tr>
<td width="193"><span class="aster">*</span>Agency Of Sponsor</td>
<td width="381"><input name="agency" type="text" size="40" id="agency" /> </td>
</tr>

<tr>
<td width="434" class="grhead">First Year Internship</td>
</tr>

<tr>
<td width="193"><span class="aster">*</span>Institution Attended</td>
<td width="381">
<select name="items" id="items">
<?php

while ($row = mysql_fetch_array($query)) {

while ($row = mysql_fetch_array($query)) {
echo '<option value="',$row['options'],'">',$row['options'],'</option>';
}

}
?> </select> </td>
</tr>

<tr>
<td width="434" class="grhead">Second Year Internship</td>
</tr>

<tr>
<td width="193"><span class="aster">*</span>First Rotation</td>
<td width="381">
<select name="items1" id="items1">
<?php
while ($row = mysql_fetch_array($query1)) {

while ($row = mysql_fetch_array($query1)) {
echo '<option value="',$row['rotation'],'">',$row['rotation'],'</option>';
}

}
?></select></td>
</tr>

<tr>
<td width="193"><span class="aster">*</span>Second Rotation</td>
<td width="381">
<select name="items2" id="items2">
<?php
while ($row = mysql_fetch_array($query2)) {

while ($row = mysql_fetch_array($query2)) {
echo '<option value="',$row['rotation'],'">',$row['rotation'],'</option>';
}

}
?></select></td>
</tr>

<tr>
<td width="193">&nbsp;</td>
<td width="381"><p>&nbsp;
</p>
<p>
<input name="Reset" type="reset" class="SaveButton" value="CLEAR" />
<input name="Submit" type="submit" class="SaveButton" value="SUBMIT" />
</p></td>
</tr>
<tr>
<td width="193">&nbsp;</td>
<td width="381">&nbsp;</td>
</tr>
</table>
</form></td>
</tr>
</table>
</div>
</body>
</html>

skinsey

6:15 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Don't know if this is best, but this is how I handle issues like that.

<?
session_start();
if ( $_SESSION['loginperm'] != 1) {
print "<script>";
print "self.location='index.php?session=1';";
print "</script>";
}

?>

Then on the index page you display the error with a

$_GET['session']

JuicyScript

6:58 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Sorry am kinda new to php,can you explain further.And i have created my sessions already in include("./include/session.php");.So i cant start another session on this page.

skinsey

8:58 am on Nov 20, 2009 (gmt 0)

10+ Year Member



My bad, read code and thought it was session issue from echo. Explain a bit of what your trying to do. Count rows, get value from field? Reply back.

If your trying to use the field $result['count'] then you have to select it in your select statement.

If your counting the numbers of rows use this.

$num_rows = mysql_num_rows($qry);

if($num_rows >=1)

JuicyScript

10:15 am on Nov 20, 2009 (gmt 0)

10+ Year Member



This script populates combo box data for the database.i have created a count so that anytime someone select that field and submits it,it counts + 1.("Which is working alryt")
Am now try to restrict a field form appearing(dont knw how to do that).But first i wanna use this script to test if the field recognize the count

if($result['count']>=1) {
echo "Your session have expired";
exit();
}
I dont knw if u get me this time.Am not a php guru...so it kinda difficult to understand me

skinsey

10:32 am on Nov 20, 2009 (gmt 0)

10+ Year Member



$sql4="SELECT * FROM inst WHERE options='Korle Bu'";

JuicyScript

11:18 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Sweet Jesus it worked mehn you are a survivor...Can u teach me how i will disable one of the field from populating in the combo box , since it's from the database.

skinsey

11:30 am on Nov 20, 2009 (gmt 0)

10+ Year Member



Gotta explain a bit more as what you mean by disabling a field.

here is a select to disable

<select name="items" id="items" disabled="true">

JuicyScript

11:41 am on Nov 20, 2009 (gmt 0)

10+ Year Member



I have 3 information that are in the combo box database ie. korle bu,peace and truth.I want to knw how to disable or prevent "peace" from showing into the combox after a certain number of counts.
Is this clear enough.

skinsey

12:12 pm on Nov 20, 2009 (gmt 0)

10+ Year Member



<select name="items" id="items">
<?php

while ($row = mysql_fetch_array($query))
{
$option = $row['options'];
switch ($option){
case "peace":
if($row['count'] <= 100)
{
echo '<option value="',$row['options'],'">',$row['options'],'</option>';
}
break;
case "korle bu":
echo '<option value="',$row['options'],'">',$row['options'],'</option>';
break;
case "truth":
echo '<option value="',$row['options'],'">',$row['options'],'</option>';
break;
}
}

?> </select>

skinsey

12:17 pm on Nov 20, 2009 (gmt 0)

10+ Year Member



I did cut and paste from your code here is the fixed syntax

select name="items" id="items">
<?php
while ($row = mysql_fetch_array($query))
{
$option = $row['options'];
switch ($option){
case "peace":
if($row['count'] <= 100)
{
echo "<option value=\"".$row['options']."\">".$row['options']."</option>";
}
break;
case "korle bu":
echo "<option value=\"".$row['options']."\">".$row['options']."</option>";
break;
case "truth":
echo "<option value=\"".$row['options']."\">".$row['options']."</option>";
break;
}
}