Jump to content

Question about URL's


jkewlo

Recommended Posts

Hello, I am working on a Content Management System and I am trying to keep the pages down to a minimum.

 

I am not good at wording things so sorry if it is hard to understand.

 

you have a url EX mywebsite.com/index.php?action=Edit_Agent&do=Edit&id=1

 

I am doing if statements like

 

$action = $_REQUEST['action'];

 

if($action == ""){

echo "Welcome to aDVYNE Content Management System.";

}

 

if($action == "Edit_Agents"){

echo show_Agents() ."<br>";

}

 

now what I am trying to do is get the &do &id as well now I might just be confusing myself as I have been working on this for about 12 hours straight.

 

so can I do it like

if($action == "Edit_Agents" && $do == "Edit" &id == $_SESSION['id']){ }

 

but this didnt work.. Any tips I dont want someone to do the code for me.. unless you are bored and just want to help out.. but a few points would help

 

Link to comment
Share on other sites

Are you trying to get the GET data passed in the URL?

 

If so, you need to refer to it by the GET super global...

 

if($_GET['action'] == "Edit_Agents" && $_GET['do'] == "Edit" && $_GET['id'] == $_SESSION['id']){ } ()

 

The data passed after the ? in the URL is automatically saved in the $_GET array when a form is submitted.

Link to comment
Share on other sites

It's confusing as you have Edit_Agents and edit.  I would assume edit given Edit_Agents, but maybe you would have a list option as well?  Several more elegant ways.  You can use switch statements, or possibly a function for the main action.

 

I started typing some code, but I think this is simpler than you are making it.  What are the possible values of action and how many different values of do are there for a given action?  I assume unlimited for id but comparing that with id in the session is confusing me.

 

     

Link to comment
Share on other sites

I agree with AbraCadaver, if you only have say 3 different pages you are going to run (New, Edit, Delete, or whatever..) then you should use a switch somewhere to direct you to the correct page.  Then you can use the default case to bounce you to a generic page if invalid data is entered.

 

I still am not sure exactly what you are looking for, but you need to reference the GET data properly.

Link to comment
Share on other sites

Ok, I just said screw it and made a editagent.php page. and just run it threw that..

 

I am now wondering if this is possible

function edit_Agents(){
$id = $_REQUEST['id'];
$sql="SELECT * FROM users WHERE id = '". $id ."'";
  	$result=mysql_query($sql) or die(mysql_error());
  	$rows=mysql_fetch_array($result);
echo "
<form method=post action=". change_Users() .">
<table width=750 border=0>
  <tr>
    <td width=100 height=100><img src=". $rows['path'] ." width=100 height=100></td>
    <td width=244 valign=top>First Name: <input type=text value=". $rows['Firstname'] ." name=fname><br>
Last Name: <input type=text value=". $rows['Lastname'] ." name=lname><br>
Admin Level: <input type=text value=". $rows['level'] ." name=adminlevel><br>
Email: <input type=text value=". $rows['email'] ." name=email><br><input type=submit value=\"Edit ". $rows['Firstname'] ." ". $rows['Lastname'] ."'s Profile\" name=edituser></td>
    <td width=331></a>
  </tr>
</table></form>";
}

This is in my function.class.php and I was wondering could you pass a form with the action like this?? being that th function change_User(); is in the same file as this function?? and for editagents.php I have just called the information with edit_Agents();

 

Hope this makes some sort of sense..

Link to comment
Share on other sites

Just a rough example:

 

1. Leave the action blank then set a hidden input for the function you want to call:

 

<form method="post" action="">
<input type="hidden" name="action" value="change_users">

 

Then you can do something like this when submitted:

$func = isset($_POST['action']) ? $_POST['action'] : 'edit_agents';
if(function_exists($func)) {
   $func();
}

--or--

 

2. Set the action to the name of the file with the function as a get parameter:

 

<form method="post" action="?action=change_users">

 

Then you would do the same but use $_GET:

$func = isset($_GET['action']) ? $_GET['action'] : 'edit_agents';
if(function_exists($func)) {
   $func();
}

Link to comment
Share on other sites

So, I will try and go with the first one you showed..

 

seems I am confusing myself reading this

 

This is the function where I added

<form method=post action=>

<input type=hidden name=action value=change_users>

 

function edit_Agents(){
$id = $_REQUEST['id'];
$sql="SELECT * FROM users WHERE id = '". $id ."'";
  	$result=mysql_query($sql) or die(mysql_error());
  	$rows=mysql_fetch_array($result);
echo "
<table width=750 border=0>
  <tr>
<form method=post action=>
<input type=hidden name=action value=change_users>
    <td width=100 height=100><img src=". $rows['path'] ." width=100 height=100></td>
    <td width=244 valign=top>First Name: <input type=text value=". $rows['Firstname'] ." name=fname><br>
Last Name: <input type=text value=". $rows['Lastname'] ." name=lname><br>
Admin Level: <input type=text value=". $rows['level'] ." name=adminlevel><br>
Email: <input type=text value=". $rows['email'] ." name=email><br><input type=submit value=\"Edit ". $rows['Firstname'] ." ". $rows['Lastname'] ."'s Profile\" name=edituser></td>
    <td width=331></a>
  </tr>
</table></form>";
}

 

Then I create my function change_Agents and add

$func = isset($_GET['action']) ? $_GET['action'] : 'edit_agents';
if(function_exists($func)) {
   $func();
}

 

now Where do I go from here?? Sorry.

Link to comment
Share on other sites

This is my function.class.php

<?PHP
session_start();

require_once("../class/connect.php");
$id = $_SESSION['id'];

function get_Name(){
$id = $_SESSION['id'];
$sql="SELECT * FROM users WHERE id='". $id ."'";
$result=mysql_query($sql) or die("get_Name()". mysql_error() ."");
$row = mysql_fetch_assoc($result);
echo "<b>Welcome: ". $row['Firstname'] ." ". $row['Lastname'] ."</b>";
}

function get_Picture(){
$id = $_SESSION['id'];
$sql="SELECT * FROM users WHERE id='". $id ."'";
$result=mysql_query($sql) or die("get_Picture()". mysql_error() ."");
$row = mysql_fetch_assoc($result);
echo "<img src=". $row['path'] ." width=100 height=100 >";

}

function show_SessionId(){
echo "Session ID".session_id();
}

function get_Username(){
echo "Username: ".$_SESSION['username'];
}

function show_Agents(){
$sql="SELECT * FROM users ORDER BY id ASC";
  	$result=mysql_query($sql);
  	while($rows = mysql_fetch_array($result)){
echo "<table width=650 border=0>
  <tr>
    <td width=100 height=100><img src=". $rows['path'] ." width=100 height=100></td>
    <td width=244 valign=top>First Name: ". $rows['Firstname'] ."<br>
Last Name: ". $rows['Lastname'] ."<br>
Admin Level: ". $rows['level'] ."<br>
Email: ". $rows['email'] ."</td>
    <td width=331><a href=editagents.php?id=". $rows['id'] .">Edit ". $rows['Firstname']. " ". $rows['Lastname'] ."</a>
  </tr>
</table>";

}
}

function edit_Agents(){
$id = $_REQUEST['id'];
$sql="SELECT * FROM users WHERE id = '". $id ."'";
  	$result=mysql_query($sql) or die(mysql_error());
  	$rows=mysql_fetch_array($result);
echo "
<table width=750 border=0>
  <tr>
<form method=post action=>
<input type=hidden name=action value=change_users>
    <td width=100 height=100><img src=". $rows['path'] ." width=100 height=100></td>
    <td width=244 valign=top>First Name: <input type=text value=". $rows['Firstname'] ." name=fname><br>
Last Name: <input type=text value=". $rows['Lastname'] ." name=lname><br>
Admin Level: <input type=text value=". $rows['level'] ." name=adminlevel><br>
Email: <input type=text value=". $rows['email'] ." name=email><br><input type=submit value=\"Edit ". $rows['Firstname'] ." ". $rows['Lastname'] ."'s Profile\" name=edituser></td>
    <td width=331></a>
  </tr>
</table></form>";
}

function change_Agents(){
if
?>

then we have my editagents.php

<?php
session_start();
require_once('../class/function.class.php');

?>
<!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>Gantt Insurance Agency Admin Controll Panel</title>
<link href="../css/adminstyle.css" rel="stylesheet" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function ShowHide(){
$("#slidingDiv").animate({"height": "toggle"}, { duration: 1000 });
}
//]]>
</script>
<style>
.login {
    width: 100%;
    margin: 10px auto;
    background-color:#CCC;
    color: #000;
    padding: 15px;
}

.cornertopleft {
    /* Border Radius Style */
    border-top-left-radius: 30px;
    /* Mozilla Firefox Extension */
    -moz-border-radius-topleft: 30px;
}

.cornertopright {
    /* Border Radius Style */
    border-top-right-radius: 30px;
    /* Mozilla Firefox Extension */
    -moz-border-radius-topright: 30px;
}

.cornerbottomleft {
    /* Border Radius Style */
    border-bottom-left-radius: 30px;
    /* Mozilla Firefox Extension */
    -moz-border-radius-bottomleft: 30px;
}

.cornerbottomright {
    /* Border Radius Style */
    border-bottom-right-radius: 30px;
    /* Mozilla Firefox Extension */
    -moz-border-radius-bottomright: 30px;
}

.login2 {
    width: 120px;
    height: 120px;
    margin: 10px auto;
    background-color: #fff;
    color: #000;
}

.cornerall {
    /* Border Radius Style */
    border-radius: 60px;
    /* Mozilla Firefox Extension */
    -moz-border-radius: 60px;
}

</style>
</head>
<body>
<div id="wrapper">
<div id="header" class="login ">
<img src="../img/smalladvyne.png" />
<div id="details">
<?PHP
echo get_Name() ."<br>";
echo show_SessionId() ."<br>";
echo get_Username() ."<br>";
echo "<a href=logout.php><b>Log Out!</b></a>";
?>
</div><!-- DETAILS -->

</div> <!-- HEADER -->
<div id="left">
<a onclick="ShowHide(); return false;" href="#">Add/Edit Agents</a>
<div id="slidingDiv">
-<a href="admin.php?action=Edit_Agents">Edit Agent</a><br />
-<a href="admin.php?action=Add_Agents">Add Agent</a>
</div>
</div>
<div id="content">
<?php
echo edit_Agents();
?>
</div>
<div id="footer"></div>
</div>

</center>
</body>
</html>

 

 

Link to comment
Share on other sites

How does this look??

function edit_Agents(){
$id = $_REQUEST['id'];
$sql="SELECT * FROM users WHERE id = '". $id ."'";
  	$result=mysql_query($sql) or die(mysql_error());
  	$rows=mysql_fetch_array($result);
echo "
<table width=750 border=0>
  <tr>
<form method=post action=>
<input type=hidden name=action value=change_Agents>
    <td width=100 height=100><img src=". $rows['path'] ." width=100 height=100></td>
 <td width=244 valign=top>Username: <input type=text value=". $rows['username'] ." name=uname><br>
    <td width=244 valign=top>First Name: <input type=text value=". $rows['Firstname'] ." name=fname><br>
Last Name: <input type=text value=". $rows['Lastname'] ." name=lname><br>
Admin Level: <input type=text value=". $rows['level'] ." name=adminlevel><br>
Email: <input type=text value=\"". $rows['email'] ."\" name=email><br><input type=submit value=\"Edit ". $rows['Firstname'] ." ". $rows['Lastname'] ."'s Profile\" name=edituser></td>
    <td width=331></a>
  </tr>
</table></form>";
}

function change_Agents(){
$username = $_POST['username'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$level = $_POST['level'];

$sql="UPDATE users SET username='". $username ."', Firstname='". $fname ."', 			 	Lastname='". $lname ."', level='". $level ."', email='". $email ."'";
$result=mysql_query($sql) or die(mysql_error());
header("Location: editagents.php?");
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.