TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-19-2010, 07:18 PM   #1 (permalink)
The Visitor
 
Join Date: Nov 2010
Posts: 2
Thanks: 1
kphigh is on a distinguished road
Default Help with php form

Hi,

I am extremely new to PHP. I have a form which is used to add/update data a mysql database. One of the fields is called "Approved' and I use a yes/no radio button to update the field. Is there a way to only allow certain team members see and or uddate the Approved field? I capture the username from the browser cookie.

Here is the code I use for the form:

<html>
<head>
<title>My Page</title>
</head>
<body>
<align = center><h2>SureIt Entry/Update Form</h2></align>
<?php
// set database server access variables:
$host = "";
$user = "";
$pass = "";
$db = "";

$tag=$_POST['tag'];
$developer=$_POST['developer'];
$application=$_POST['application'];
$username=$_COOKIE["InfoMgrWT"];

// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// create query
$query = "SELECT * FROM revo.sureit where tag = '".$tag."' and developer ='".$developer."' and application = '".$application."'";
//print $query;
//$query= "SELECT * from sureit";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$row = mysql_fetch_row($result);

if($row[0])
{
echo "<form name='ProdMove_1' action='sureit_update.php' method='POST'>";
echo "<div align='left'>";
}
else
{
echo "<form name='ProdMove_1' action='sureit_insert.php' method='POST'>";
echo "<div align='left'>";
}
echo "Tag<br>";

echo "<input type='text' name='tag' value='".$tag."'><BR><br>";

echo "Developer<br>";
echo "<input type='text' name='developer' value='".$developer."'><BR><br>";

echo "Application<br>";
echo "<input type='text' name='application' value='".$application."'><BR><br>";

echo "Description of Code change<br>";
echo '<textarea cols=60 rows=15 wrap="soft" name="descofchange">'.$row[3].'</textarea><BR><br>';

echo "Details<br>";
echo '<textarea cols=60 rows=15 wrap= "soft" name="details">'.$row[14].'</textarea><BR><br>';

echo "Description of Database Change<br>";
echo '<textarea cols=60 rows=15 wrap="hard" name="descofdbchange">'.$row[4].'</textarea><BR><br>';


echo "Front End Changes<br>";
echo '<textarea cols=60 rows=15 wrap="soft" name="frontendchanges">'.$row[9].'</textarea><BR><br>';

echo "Move Instructions<br>";
echo '<textarea cols=60 rows=15 wrap="soft" name="moveinst">'.$row[11].'</textarea><BR><br>';


echo "Post Move Validation<br>";
echo '<textarea cols=60 rows=15 wrap = "soft" name="postmovevalidate">'.$row[12].'</textarea><BR><br>';
echo "Move Validated<br>";
if ($row[15] == 'Y')
{
echo "<input type='radio' name='movevalidated' value='Y' checked >Y<br>";
echo "<input type='radio' name='movevalidated' value='N' >N<br>";
}
else
{
echo "<input type='radio' name='movevalidated' value='Y' >Y<br>";
echo "<input type='radio' name='movevalidated' value='N' checked >N<br><br><br>";
}
'<br><br>';
echo "Approved<br>";

if ($row[6] == 'Y')
{
echo "<input type='radio' name='approved' value='Y' checked >Y<br>";
echo "<input type='radio' name='approved' value='N' >N<br>";
}

else
{
echo "<input type='radio' name='approved' value='Y' >Y<br>";
echo "<input type='radio' name='approved' value='N' checked >N<br><br>";
}


echo "Cancelled<br>";
if ($row[13] == 'Y')
{
echo "<input type='radio' name='cancelled' value='Y' checked >Y<br>";
echo "<input type='radio' name='cancelled' value='N' >N<br>";
}
else
{
echo "<input type='radio' name='cancelled' value='Y' >Y<br>";
echo "<input type='radio' name='cancelled' value='N' checked >N<br>";
}
?>
<br>
<input type = "submit" value = "Submit">
<br><br>
<a href="http://revolab0.uswin.ad.vzwcorp.com/sureit_query.html">Back</a>
</form>
</body>
</html>


Thanks
kevin
kphigh is offline  
Reply With Quote
Old 11-19-2010, 08:55 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I would query for the user security level and only show that radio if it is in a certain level or higher.
tony is offline  
Reply With Quote
Old 11-20-2010, 12:13 AM   #3 (permalink)
The Contributor
 
SaintIsaiah's Avatar
 
Join Date: Jan 2009
Posts: 48
Thanks: 5
SaintIsaiah is on a distinguished road
Default

I agree with tony here, the best way is to check for their security level. You would need to have a users table in the sql with a column representing their security level. You would need to assign a default, such as "0" for that column, then that value increases by one each time on specific users when there is higher access to grant.

Lets say you have a usersystem that uses an sql table called "users".

Using their userid, you query their info in the database, then establish whether or not to show them the specific content or not, based on their security level

For this example, I'm using "$user['userid']"

There may already be a variable like this to identify your users if you are integrating your script into an existing php system. Otherwise, you will need to develop a register/login system that handles sessions.
Follow the comments below, introduced by "//" for more information and feel free to reply with any questions you have.

PHP Code:
//Using their userid ($user['userid']) I can grab all their information from the database
if($user_arr mysql_query("SELECT * FROM users WHERE userid ='" $user['userid'] . "'"))
{
   
//I now use "$userinfo" as the variable to display any of their information
   //NOTE: one of the SQL columns for their username contains their access 
   //level. This is labed as "access_level" but can be named anything
   
$userinfo mysql_fetch_array($user_arr);
   
   
//I now see if their access level is equal to the required level to see the 
   //content. If they have access, the content shows. If they don't, the content 
   //is skipped from being displayed
   
if($userinfo['access_level'] == '3'//'3' could be any access number you want
   
{
      
// Show Permissible Content Here or Skip Me
   
}

SaintIsaiah is offline  
Reply With Quote
The Following User Says Thank You to SaintIsaiah For This Useful Post:
kphigh (11-22-2010)
Old 11-22-2010, 01:13 PM   #4 (permalink)
The Visitor
 
Join Date: Nov 2010
Posts: 2
Thanks: 1
kphigh is on a distinguished road
Default

Thanks for the idea.. I'll give it a try and see what happens.
kphigh is offline  
Reply With Quote
Old 11-22-2010, 08:20 PM   #5 (permalink)
The Contributor
 
SaintIsaiah's Avatar
 
Join Date: Jan 2009
Posts: 48
Thanks: 5
SaintIsaiah is on a distinguished road
Default

Quote:
Originally Posted by kphigh View Post
Thanks for the idea.. I'll give it a try and see what happens.
No prob. Let me know how it works out.
SaintIsaiah is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
auto update of a form Can it be done only with PHP crimsont Absolute Beginners 1 07-09-2010 08:59 AM
Basic php form update mysql script dp2 Absolute Beginners 3 03-11-2009 04:06 PM
PHP fill in form help sacred_tinker Absolute Beginners 6 10-08-2008 12:28 PM
email fill in form help? PHP sacred_tinker Absolute Beginners 19 05-28-2008 05:58 AM
PHP Contact Form - 2 Questions ncmason General 0 05-26-2008 02:38 AM


All times are GMT. The time now is 07:59 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design