Jump to content

Recommended Posts

Hi all,

i hope you will be able to help me, i am very new to PHP and have stumbled on a problem with a profile page i am writing.

 

i have the page called from the member area as profile.php?act=view&id=1 depending if the profile is being viewed or edited it says view or edit (basics) and ofcause you will see the id is called from the MySQL database...

now the problem i have is when i type the url and leave the ?act=*&id=* i get a page of errors.

i would like this page to say somthing along the lines of "You Have Reached This Page In Error!"

 

This is the basic code so far most likly there is better ways to do things that the ways i have but as i said i am learning.

 

<?PHP
// profile.php

include('include/head.php');
include('include/pro_var.php');

confirm_logged_in();
if ($_SESSION['level'] == 0) {
	redirect('index.php');
}


$profile =  "SELECT * FROM users WHERE id = ".$_GET['id']."";
$result = mysql_query($profile);

while($rows = mysql_fetch_array($result)) {
?>
	<table width="70%" align="center" class="table">
		<tr>
			<td colspan="2" class="td2">
				<h2><?PHP echo $rows['user']; ?></h2>
			</td>
		</tr>
		</tr>
			<td colspan="2" class="td2">
				<?PHP	
					if ($_GET['act'] == 'edit') {
						echo "{$edit_pro}";
						}elseif ($_GET['act'] == 'view') {
							echo "{$view_pro}";
						}
				?>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="td2">
				<?PHP 
					if ($_GET['act'] == 'view') {
						if ($_SESSION['user_id'] == $_GET['id']) {
							echo "<a href=profile.php?act=edit&&id=".$_GET['id'].">Edit Profile</a>";
						}else {
						echo "";
						}	
					}elseif ($_GET['act'] == 'edit') {
						echo "<a href=profile.php?act=view&&id=".$_GET['id'].">View Profile</a>";
					}else {
						echo "";
					}
				 ?>
			</td>
		</tr>
	</table>

<?PHP
}
mysql_close();
include('include/foot.php');

?>

 

Thank You In Advance

Wiggly  ;D

Link to comment
https://forums.phpfreaks.com/topic/119545-help-_getact/
Share on other sites

now the problem i have is when i type the url and leave the ?act=*&id=* i get a page of errors.

i would like this page to say somthing along the lines of "You Have Reached This Page In Error!"

That's because you should always check to see if user defined variables exist first before using them. Eg

if((isset($_GET['act']) && $_GET['act'] == 'view') && (isset($_GET['id']) && is_numeric($_GET['id']))
{
    // variables are set, your code here
}
// variables are not set, display error
else
{
    die('You Have Reached This Page In Error!');
}

Link to comment
https://forums.phpfreaks.com/topic/119545-help-_getact/#findComment-615874
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.