Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Posts posted by jarvis

  1. Solved:

    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    $filename = basename($pageURL);
    #echo $filename; //debug
    
    if ($filename == 'index.php') {
    	echo 'home';
    } elseif ($filename == 'about.php') {
    	echo 'about';
    } elseif ($filename == 'services.php') {
    	echo 'services';
    } elseif ($filename == 'affiliate.php') {
    	echo 'affiliate';
    } elseif ($filename == 'links.php') {
    	echo 'links';
    } else {
    	echo 'contact';
    }
    
    

  2. Sorry to sound daft, but if

    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];	
    $filename = basename($pageURL);	
    echo $filename; //debug
    

    Can give me the filename, then don't I just need to say if filename = $filename, then show x y or z?

    As $filename would be links.php, so don't I just need to say, it $filename is equal to links.php show whatever?

  3. Hi,

     

    Am probably being thick (not enough coffee yet!!!). Why is the below not working:

    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    $filename = basename($pageURL);
    echo $filename; //debug
    
    if ($filename == 'index.php') {
    	echo 'home';
    } elseif ($filename == 'about.php') {
    	echo 'about';
    } elseif ($filename == 'services.php') {
    	echo 'services';
    } elseif ($filename == 'affiliate.php') {
    	echo 'affiliate';
    } elseif ($filename == 'links.php') {
    	echo 'links';
    } else($filename == 'contact.php') {
    	echo 'contact';
    }
    

     

    The idea is it get the filename from the URL and depending which page, a different image will be shown.

     

    Sorry it's a silly question. Your help is appreciated!

     

    Many thanks

  4. Hi All,

     

    I've got the following script which resizes my images.

     

    It then produces:

    1) A cropped thumbnail

    2) A scaled down image

     

    Is there anything I can do to improve the images quality of the resized file? The client using it is uploading very high res images you see. Thanks

     

    <?php
    function saveThumb($gal,$fn) {
    define("MAX_XY_SMALL", 150); // maximum width or height of thumbnail image
    define("MAX_XY_LARGE", 550); // maximum width or height of thumbnail image
    $fpath = "categories/$gal/$fn";
    //print $fpath."\n";
    /* GetImageSize returns an array:
     * $info[0] - horizontal size of image in pixels
     * $info[1] - vertical size of image in pixels
     * $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG)
    */
    $info = GetImageSize("$fpath");
    //print_r($info);
    
    // do we need to resize image?
    if ($info[0] > MAX_XY_SMALL || $info[1] > MAX_XY_SMALL) {
    	// is image landscape?
    	if ($info[0] >= $info[1]) {
    		$width = MAX_XY_SMALL;
    		$height = MAX_XY_SMALL;
    	// or portrait?
    	} else {
    		$height = MAX_XY_SMALL;
    		$width = MAX_XY_SMALL;
    	}
    } else {
    	// use original dimensions
    	$width = $info[0];
    	$height = $info[1];
    }
    
    
    if ($info[0] > MAX_XY_LARGE || $info[1] > MAX_XY_LARGE) {
    	// is image landscape?
    	if ($info[0] >= $info[1]) {
    		$width_large = MAX_XY_LARGE;
    		$height_large = $info[1]*MAX_XY_LARGE/$info[0];
    	// or portrait?
    	} else {
    		$height_large = MAX_XY_LARGE;
    		$width_large = $info[0]*MAX_XY_LARGE/$info[1];
    	}
    } else {
    	// use original dimensions
    	$width_large = $info[0];
    	$height_large = $info[1];
    }	
    
    // create new thumbnail image
    //echo "<br>$width - $height<br>";
    $im = ImageCreateTrueColor($width, $height);
    $im_large = ImageCreateTrueColor($width_large, $height_large);
    
    /* determine image type and load original image. Notice new tests for image
     * types. The GD extension has changed a lot over the years, dropping GIFs
     * and adding PNG support. By testing, we avoid trying to process an image
     * PHP can't deal with
    */
    $im_big = ""; // default is no image
    switch ($info[2]) {
    	case 1 :
    		if (ImageTypes() & IMG_GIF) // test for GIF support 
    			$im_big = ImageCreateFromGIF("$fpath");
    		break;
    	case 2 :
    		if (ImageTypes() & IMG_JPG) // test for JPEG support 
    			$im_big = ImageCreateFromJPEG("$fpath");
    		break;
    	case 3 :
    		if (ImageTypes() & IMG_PNG) // test for PNG support  
    			$im_big = ImageCreateFromPNG("$fpath");
    		break;
    	case 4 :
    		if (ImageTypes() & IMG_BMP) // test for BMP support  
    			$im_big = ImageCreateFromBMP("$fpath");
    		break;			
    }
    
    if ($im_big) {
    	/* resize original image into thumbnail - see PHP Manual for details on
    	 * the arguements ImageCopyResized takes
    	*/
    	#ImageCopyResized($im,$im_big,0,0,0,0,$width,$height,MAX_XY_SMALL,MAX_XY_SMALL);
    	#ImageCopyResized($im,$im_big,0,0,150,150,$width,$height,MAX_XY_SMALL,MAX_XY_SMALL);
    	ImageCopyResized($im,$im_big,0,0,300,230,$width,$height,MAX_XY_SMALL,MAX_XY_SMALL);
    	ImageCopyResized($im_large,$im_big,0,0,0,0,$width_large,$height_large,$info[0],$info[1]);
    } else {
    	// couldn't load original image, so generate 'no thumbnail' image instead
    	$width = 150;
    	$height = 150;
          	$im = ImageCreate($width, $height); // create a blank image
          	$bgc = ImageColorAllocate($im, 0, 0, 0); // background color = black
          	$tc  = ImageColorAllocate($im, 255, 255, 255); // text color = white
          	ImageFilledRectangle($im, 0, 0, $width, $height, $bgc); // draw rectangle
          	ImageString($im, 3, 9, 36, "No thumbnail", $tc); // add text
    		ImageString($im, 3, 17, 48, "available", $tc);  
      	}
    
    /* save our image in thumb directory - if the second argument is left out,
     * the image gets sent to the browser, as in thumbnail.php
    */
    ImageJPEG($im, "categories/".$gal."/t_".$fn, 100);
    ImageJPEG($im_large, "categories/".$gal."/".$fn, 100);
    
    // clean up our working images
    ImageDestroy($im_big);
    ImageDestroy($im);
    ImageDestroy($im_large);
      }
    
    ?>
    

     

    Thanks in advanced

  5. Ok,

     

    I think I'm making head way but still not getting it exactly right. Instead of:

    echo '<script type="text/javascript">alert("You forgot to enter your email address!");</script>';
    

    I change it to

    $email_popup = '<script type="text/javascript">alert("You forgot to enter your email address!");</script>';
    

     

    If i then add this at the end of my page as

    <?php if (isset($_POST['submitted'])) { echo $email_popup; }?>
    

     

    This displays the top of the page, the form but still fails to show the main bg (called in via css)

     

    I then though about changing the pop up to:

    echo 'div id="login_bg">';
    $email_popup = '<script type="text/javascript">alert("You forgot to enter your email address!");</script>';
    echo '</div>';
    

     

    This doesn't work as once you clear the pop up, it shows the entire bg image again at the end of the page!

     

    There must be an easy way to get around this????

     

    TIA

  6. Hi All,

     

    Odd one this, I've got the following code (below) which is a simple log in form. The client wanted a pop to inform you when you've not completed a field and an asterix to appear.

     

    This is fine. However, if you forget to enter some info, the pop up appears but the page behind goes blank, as if the rest of the page wont load until you click OK.

     

    How can I stop this?

     

     

    Thanks in advanced!

    <?php 
    // This is the login page for the site.
    
    // Include the configuration file for error management and such.
    require_once ('./includes/config.inc.php'); 
    
    // Set the page title and include the HTML header.
    $page_title = 'Login';
    include ('./includes/header.html');
    
    $email_error = '';
    $pw_error = '';
    
    $error_message = '';
    
    if (isset($_POST['submitted'])) { // Check if the form has been submitted.
    
    require_once ('../mysql_connect.php'); // Connect to the database.
    
    // Validate the email address.	
    if (!empty($_POST['email'])) {
    	$e = escape_data($_POST['email']);
    } else {
    	echo '<script type="text/javascript">alert("You forgot to enter your email address!");</script>';
    	$e = FALSE;
    	$email_error = '<span class="required"><img src="images/star.gif" /></span>';
    }
    
    // Validate the password.
    if (!empty($_POST['pass'])) {
    	$p = escape_data($_POST['pass']);
    } else {
    	$p = FALSE;
    	echo '<script type="text/javascript">alert("You forgot to enter your password!");</script>';
    	$pw_error = '<span class="required"><img src="images/star.gif" /></span>';
    }
    
    if ($e && $p) { // If everything's OK.
    
    	// Query the database.
    	$query = "SELECT user_id, name, acc_type FROM users WHERE (email='$e' AND pass=SHA('$p')) AND active IS NULL";	
    	$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error());
    
    		if (@mysql_num_rows($result) == 1) { // A match was made.
    
    		// Register the values & redirect.
    		$row = mysql_fetch_array ($result, MYSQL_NUM); 
    		mysql_free_result($result);
    		mysql_close(); // Close the database connection.
    		$_SESSION['user_id'] = $row[0];
    		$_SESSION['name'] = $row[1];
    		$_SESSION['acc_type'] = $row[2];
    
    		// Start defining the URL.
    		$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
    		// Check for a trailing slash.
    		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
    			$url = substr ($url, 0, -1); // Chop off the slash.
    		}
    
    		// Add the page.
    		$acc_type = $_SESSION['acc_type']; 
    		if ($acc_type == '1') {
    			$url .= '/print.php';
    		} else {
    			$url .= '/category.php';
    		}
    
    		ob_end_clean(); // Delete the buffer.	
    		header("Location: $url");
    		exit(); // Quit the script.
    
    	} else { // No match was made.
    		echo '<script type="text/javascript">alert("Either the email address and password entered do not match those on file or you have not yet activated your account!");</script>';
    	}
    
    } else { // If everything wasn't OK.
    	$error_message = '<span class="required">Please fill in all boxes to log in!</span>';
    }
    
    mysql_close(); // Close the database connection.
    
    } // End of SUBMIT conditional.
    ?>
      <!-- box_top -->
      <div id="box_top"> 
      	<img src="images/login_box_top.jpg">	
      </div>
      <!-- /box_top -->
    
    <!-- box_content -->
    <div id="login_box_content">	
    
    	<!-- left_column -->
    	<div id="login_left_column">
    	<img src="images/client_login_text.gif" />
    	<form action="login.php" method="post">
    	<table border="0" width="320">
    	  <tr>
    		<td><img src="images/email_address.gif" /></td>
    		<td><div class="myBoxLh"></div><input type="text" name="email" style="width:160px;" maxlength="90" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /><div class="myBoxRh"></div></td>
    		<td><?php if (isset($_POST['submitted'])) { echo $email_error; }?></td>
    	  </tr>
    	  <tr>
    		<td><img src="images/password.gif" /></td>
    		<td><div class="myBoxLh"></div><input type="password" name="pass" style="width:160px;" maxlength="20" /><div class="myBoxRh"></div></td>
    		<td><?php if (isset($_POST['submitted'])) { echo $pw_error; }?></td>
    	  </tr>  
    	  <tr>
    		<td colspan="2"><div align="right"><input type="image" src="images/submit.jpg" name="submit" value="Login" class="submit_small" /></div>
    		<input type="hidden" name="submitted" value="TRUE" /></td>
    		<td><img src="images/spacer.gif" width="14"/></td>
    	  </tr>
    	</table>
    	</form>				
    
    </div>
    <!-- /box_content -->		
    
    <!-- box_bottom -->
    <div id="login_box_bottom">
    <img src="images/login_box_bottom.jpg">
    </div>
    <!-- /box_bottom -->
    
    <!-- login_copyright -->
    <div id="login_copyright">
    <img src="images/login_copyright.jpg">
    </div>
    <!-- /login_copyright -->
    
    </div>
    <!-- /wrapper -->		
    <?php // Include the HTML footer.
    include ('./includes/footer_login.html');
    ?>
    

  7. Hi,

     

    When I copy an image, my script then has the following to copy the image to it's location:

    ImageJPEG($im, "categories/".$gal."/t_".$fn);
    

    To improve the quality, do I simply add a third parameter for the quality level? i.e.

    ImageJPEG($im, "categories/".$gal."/t_".$fn, 75);
    

    Either 75 - 100 with 100 being best, is that right?

  8. Hi all,

     

    I use the following script to resize my images to either 150 high or wide and 800 high or wide

     

    What I need to do, is set the thumbnail to be 150 x 150 and take a crop of the main image and resize the main to 800px high or wide.

     

    how can I alter the below to do this?

    <?php
    function saveThumb($gal,$fn) {
    define("MAX_XY_SMALL", 150); // maximum width or height of thumbnail image
    define("MAX_XY_LARGE", 800); // maximum width or height of thumbnail image
    $fpath = "categories/$gal/$fn";
    //print $fpath."\n";
    /* GetImageSize returns an array:
     * $info[0] - horizontal size of image in pixels
     * $info[1] - vertical size of image in pixels
     * $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG)
    */
    $info = GetImageSize("$fpath");
    //print_r($info);
    
    // do we need to resize image?
    if ($info[0] > MAX_XY_SMALL || $info[1] > MAX_XY_SMALL) {
    	// is image landscape?
    	if ($info[0] >= $info[1]) {
    		$width = MAX_XY_SMALL;
    		$height = $info[1]*MAX_XY_SMALL/$info[0];
    	// or portrait?
    	} else {
    		$height = MAX_XY_SMALL;
    		$width = $info[0]*MAX_XY_SMALL/$info[1];
    	}
    } else {
    	// use original dimensions
    	$width = $info[0];
    	$height = $info[1];
    }
    
    
    if ($info[0] > MAX_XY_LARGE || $info[1] > MAX_XY_LARGE) {
    	// is image landscape?
    	if ($info[0] >= $info[1]) {
    		$width_large = MAX_XY_LARGE;
    		$height_large = $info[1]*MAX_XY_LARGE/$info[0];
    	// or portrait?
    	} else {
    		$height_large = MAX_XY_LARGE;
    		$width_large = $info[0]*MAX_XY_LARGE/$info[1];
    	}
    } else {
    	// use original dimensions
    	$width_large = $info[0];
    	$height_large = $info[1];
    }	
    
    // create new thumbnail image
    //echo "<br>$width - $height<br>";
    $im = ImageCreateTrueColor($width, $height);
    $im_large = ImageCreateTrueColor($width_large, $height_large);
    
    /* determine image type and load original image. Notice new tests for image
     * types. The GD extension has changed a lot over the years, dropping GIFs
     * and adding PNG support. By testing, we avoid trying to process an image
     * PHP can't deal with
    */
    $im_big = ""; // default is no image
    switch ($info[2]) {
    	case 1 :
    		if (ImageTypes() & IMG_GIF) // test for GIF support 
    			$im_big = ImageCreateFromGIF("$fpath");
    		break;
    	case 2 :
    		if (ImageTypes() & IMG_JPG) // test for JPEG support 
    			$im_big = ImageCreateFromJPEG("$fpath");
    		break;
    	case 3 :
    		if (ImageTypes() & IMG_PNG) // test for PNG support  
    			$im_big = ImageCreateFromPNG("$fpath");
    		break;
    	case 4 :
    		if (ImageTypes() & IMG_BMP) // test for BMP support  
    			$im_big = ImageCreateFromBMP("$fpath");
    		break;			
    }
    
    if ($im_big) {
    	/* resize original image into thumbnail - see PHP Manual for details on
    	 * the arguements ImageCopyResized takes
    	*/
    	ImageCopyResized($im,$im_big,0,0,0,0,$width,$height,$info[0],$info[1]);
    	ImageCopyResized($im_large,$im_big,0,0,0,0,$width_large,$height_large,$info[0],$info[1]);
    } else {
    	// couldn't load original image, so generate 'no thumbnail' image instead
    	$width = 150;
    	$height = 150;
          	$im = ImageCreate($width, $height); // create a blank image
          	$bgc = ImageColorAllocate($im, 0, 0, 0); // background color = black
          	$tc  = ImageColorAllocate($im, 255, 255, 255); // text color = white
          	ImageFilledRectangle($im, 0, 0, $width, $height, $bgc); // draw rectangle
          	ImageString($im, 3, 9, 36, "No thumbnail", $tc); // add text
    		ImageString($im, 3, 17, 48, "available", $tc);  
      	}
    
    /* save our image in thumb directory - if the second argument is left out,
     * the image gets sent to the browser, as in thumbnail.php
    */
    ImageJPEG($im, "categories/".$gal."/t_".$fn);
    ImageJPEG($im_large, "categories/".$gal."/".$fn);
    
    // clean up our working images
    ImageDestroy($im_big);
    ImageDestroy($im);
    ImageDestroy($im_large);
      }
    
    ?>
    
    

     

    Thanks in advanced!

  9. Ok, I've sorted that issue. Problem I've got now, when I update the image, I want to remove the old one.

     

    However, it errors as its says

    rename(categories/11/window.jpg,categories/11/window.jpg) [function.rename]: No such file or directory

     

    Where window.jpg is the old image.

     

    I think it's obvious but cannot see for looking. My code is below:

    	if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'update')
    	{
    		// Get the category
    		if (!empty($_POST['category'])) {
    			$category = escape_data($_POST['category']);
    
    		}	
    
    		// Check for an image.
    		if (is_uploaded_file ($_FILES['image']['tmp_name']))
    		{
    
    			//remove old image and replace with new
    
    			$R=mysql_query("SELECT * FROM uploads WHERE upload_id = ".$_POST['this_image_id']);
    			echo $R;
    			$O=mysql_fetch_object($R);
    			$category_id=$O->category_id;
    			$fname=$O->file_name;
    			$tfname="t_".$fname;
    			@unlink("categories/$category_id/$fname");
    			@unlink("categories/$category_id/$tfname");		
    
    
    			// Relocate the image
    			if (move_uploaded_file($_FILES['image']['tmp_name'], 'categories/'.$_POST['id'].'/'.$_FILES['image']['name']))
    			{
    
            		saveThumb($_POST['id'],$_FILES['image']['name']);
    				$update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'", file_type = "'.$_FILES['image']['type'].'", file_size = "'.$_FILES['image']['size'].'", file_name = "'.$_FILES['image']['name'].'" where upload_id = '.$_POST['this_image_id'];
    
    				#echo $update_sql;
    				$update_rs  = mysql_query($update_sql) or die(mysql_error());
    
    				echo '<p class="error">The image has been uploaded!</p>';
    
    			} else { // Inform user if problem relocating image
    
    				echo '<p class="error">The file could not be Uploaded!</p>';
    
    			}	
    		}
    
    		//RELOCATE THE IMAGE IF REQUIRED
    		if (!empty($_POST['image_name'])) {
    			$image_name = escape_data($_POST['image_name']);
    		}
    
    
    		//UPDATE IMAGE AND DESCRIPTION ALREADY SET IN DATABASE.
    		$update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'" WHERE upload_id = '.$_POST['this_image_id'];
    		#echo $update_sql .' update and relocate';
    
    		$update_rs  = mysql_query($update_sql) or die(mysql_error());
    		#if ($update_rs){
    		$original = 'categories/'.$id.'/'.$image_name;
    		$original_t = 'categories/'.$id.'/t_'.$image_name;
    		$copied = 'categories/'.$_POST['category'].'/'.$image_name; 
    		$copied_t = 'categories/'.$_POST['category'].'/t_'.$image_name; 
    		rename($original, $copied); 
    		rename($original_t, $copied_t); 	
    		#}
    
    	} else {
    
    	//INSERT NEW IMAGE AND DESCRIPTION INTO DATABASE.
    	if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'upload')
    	{
    

     

    Thanks again!

  10. Hi All,

     

    Hope some kind soul can help, I think I've got myself in a muddle! I've a form which:

    If an image exists, you can delete it or update it. The update can be either:

    a) The image

    b) the description or

    c) the category it's in.

     

    If no image exists, you can add a new image and description.

     

    Currently, the adding a new image works. It's the if existing image update fails.

     

    My code:

    	if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'update')
    	{
    		// Get the category
    		if (!empty($_POST['category'])) {
    			$category = escape_data($_POST['category']);
    
    		}	
    
    		// Check for an image.
    		if (is_uploaded_file ($_FILES['image']['tmp_name']))
    		{
    			// Relocate the image
    			if (move_uploaded_file($_FILES['image']['tmp_name'], '../uploads/'.$_POST['id'].'/'.$_FILES['image']['name']))
    			{
            		saveThumb($_POST['id'],$_FILES['image']['name']);
    				$update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'", file_type = "'.$_FILES['image']['type'].'", file_size = "'.$_FILES['image']['size'].'", file_name = "'.$_FILES['image']['name'].'" where upload_id = '.$_POST['this_image_id'];
    
    				echo $update_sql;
    				$update_rs  = mysql_query($update_sql) or die(mysql_error());
    
    				echo '<p class="error">The image has been uploaded!</p>';
    
    			} else { // Inform user if problem relocating image
    
    				echo '<p class="error">The file could not be Uploaded!</p>';
    
    			}	
    		}
    
    		//UPDATE IMAGE AND DESCRIPTION ALREADY SET IN DATABASE.
    		$update_sql = 'UPDATE uploads SET category_id = "'.escape_data($_POST['category']).'", image_description = "'.escape_data($_POST['image_description']).'" WHERE upload_id = '.$_POST['this_image_id'];
    
    		//RELOCATE THE IMAGE IF REQUIRED
    		if (!empty($_POST['image_name'])) {
    			$image_name = escape_data($_POST['image_name']);
    		}
    
    		$original = 'categories/'.$id.'/'.$image_name;
    		$original_t = 'categories/'.$id.'/t_'.$image_name;
    		$copied = 'categories/'.$_POST['category'].'/'.$image_name; 
    		$copied_t = 'categories/'.$_POST['category'].'/t_'.$image_name; 
    		rename($original, $copied); 
    		rename($original_t, $copied_t); 
    
    	} else {
    
    	//INSERT NEW IMAGE AND DESCRIPTION INTO DATABASE.
    	if(!empty($_POST['submit_type']) && $_POST['submit_type'] == 'upload')
    	{
    	...code to upload new
    

    Please can someone point out where I've gone wrong.

     

    many thanks

     

  11. Hi all,

     

    Hope someone can point out the obvious. I've a log in script, if you dont enter a username or pw, you get a red asterix show by the field and a pop up.

     

    If you enter an email but not the pw, it says Undefined variable: email_error .

     

    This is the code:

    // Validate the email address.	
    if (!empty($_POST['email'])) {
    	$e = escape_data($_POST['email']);
    } else {
    	echo '<script type="text/javascript">alert("You forgot to enter your email address!");</script>';
    	#echo '<p class="error">You forgot to enter your email address!</p>';
    	$e = FALSE;
    	$email_error = '<span class="required"><img src="images/star.gif" /></span>';
    }
    
    // Validate the password.
    if (!empty($_POST['pass'])) {
    	$p = escape_data($_POST['pass']);
    } else {
    	$p = FALSE;
    	echo '<script type="text/javascript">alert("You forgot to enter your password!");</script>';
    	$pw_error = '<span class="required"><img src="images/star.gif" /></span>';
    	#echo '<p class="error">You forgot to enter your password!</p>';
    }
    

    My form looks like:

    	<form action="login.php" method="post">
    	<table border="0" width="310">
    	  <tr>
    		<td><img src="images/email_address.gif" /></td>
    		<td><div class="myBoxLh"></div><input type="text" name="email" style="width:150px;" maxlength="90" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>"  /><div class="myBoxRh"></div><?php if (isset($_POST['submitted'])) { echo $email_error; }?></td>
    	  </tr>
    	  <tr>
    		<td><img src="images/password.gif" /></td>
    		<td><div class="myBoxLh"></div><input type="password" name="pass" style="width:150px;" maxlength="20" /><div class="myBoxRh"></div><?php if (isset($_POST['submitted'])) { echo $pw_error; }?></td>
    	  </tr>  
    	  <tr>
    		<td colspan="2"><div align="left"><?php if (isset($_POST['submitted'])) { echo $error_message; }?></div><div align="right"><input type="image" src="images/submit.jpg" name="submit" value="Login" class="submit_small" /></div>
    		<input type="hidden" name="submitted" value="TRUE" /></td>
    	  </tr>
    	</table>
    	</form>
    

     

    How can I stop this error as I thought I'd coded the correct way?

     

    Thanks in advanced!

  12. Hi all,

     

    Got the following code:

    if (mysql_affected_rows() == 1) {
    	echo "<div align=\"center\"><img src=\"images/account_active.gif\"></div>";
    		$query1 = "SELECT email, pass FROM users WHERE (user_id=$x) LIMIT 1";
    		$result1 = mysql_query ($query1) or trigger_error("Query: $query1\n<br />MySQL Error: " . mysql_error());
    			$email = $row[0];
    			$pw = $row[1];
    

    When it runs, I get Undefined variable: row on line 44 which is $email = $row[0];

     

    Please point out the obvious as to why and what I need to do. I can't think straight anymore

     

    Thanks

  13. Hi All,

     

    I hope someone can point out the obvious with this one.

     

    I've a CMS which has 2 account types:

    - Admin

    - Basic

     

    If you're logged in as an admin, you can edit a user and you've access to other parts of the CMS

    If you're logged in as a basic user, you just get access to 1 page

     

    My problem is, when I edit a user with basic access, as soon as I go into the edit user screen, the CMS removes all access as if you were logged in as the basic user.

     

    There are 3 parts to the script

    - header

    - edit_user

    - footer

     

    Header contains

    // This page begins the HTML header for the site.
    
    // Start output buffering.
    ob_start();
    
    // Initialize a session.
    session_start(); 
    

     

    edit_user contains

    <?php
    
    // This page edits a users profile
    // This page is accessed through view_users.php.
    
    // Include the configuration file for error management and such.
    require_once ('includes/config.inc.php'); 
    
    // Set the page title and include the HTML header.
    $page_title = 'Edit A Profile';
    include ('includes/header.html');
      
    // If no first_name variable exists, redirect the user.
    
    if (!isset($_SESSION['name'])) {
    
    // Start defining the URL.
    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
    // Check for a trailing slash.
    if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
    	$url = substr ($url, 0, -1); // Chop off the slash.
    }
    // Add the page.
    $url .= '/index.php';
    
    ob_end_clean(); // Delete the buffer.
    header("Location: $url");
    exit(); // Quit the script.
    
    } else {
    ?>
    <!-- box_top -->
    <div id="box_top">
    <img src="images/login_box_top.jpg">
    </div>
    <!-- /box_top -->
    
    <!-- general -->
    <div id="general">
    <div id="general_scrollarea">
    <?php
    
    // Check for a valid user ID, through GET or POST
    if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php
    	$id = $_GET['id'];
    } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted
    	$id = $_POST['id'];
    } else { // No valid ID, terminate the script here and inform user
    	echo '<h1>Page Error</h1>
    	<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
    	require('includes/footer.html');
    	exit();
    }
    
    require_once('../mysql_connect.php');// Connect to the db
    
    // Check if the form has been submitted
    if (isset($_POST['submitted']))
    {
    
    // Check for a name.
    if (eregi ('^[[:alpha:]\.\' \-]{2,15}$', stripslashes(trim($_POST['name'])))) {
      $name = escape_data($_POST['name']);
    } else {
      $name = FALSE;
      echo '<p>Please enter your name!</p>';
    }
    
    // Check for a position
    if (!empty($_POST['position'])) {
    	$position = escape_data($_POST['position']);
    } else {
    $position = FALSE;
    echo '<p class="error">Please enter a position!</p>';
    }  
    
    // Check for a company
    if (!empty($_POST['company'])) {
    	$company = escape_data($_POST['company']);
    } else {
    $company = FALSE;
    echo '<p class="error">Please enter a company!</p>';
    }
    
    // Check for a address
    if (!empty($_POST['address'])) {
    	$address = escape_data($_POST['address']);
    } else {
    $address = FALSE;
    echo '<p class="error">Please enter an address!</p>';
    } 
    
    // Check for a postcode
    if (!empty($_POST['postcode'])) {
    	$postcode = escape_data($_POST['postcode']);
    } else {
    $postcode = FALSE;
    echo '<p class="error">Please enter a postcode!</p>';
    } 
    
    // Check for a country
    if (!empty($_POST['country'])) {
    	$country = escape_data($_POST['country']);
    } else {
    $country = FALSE;
    echo '<p class="error">Please enter a country!</p>';
    } 
    
    // Check for a telephone
    if (!empty($_POST['telephone'])) {
    	$telephone = escape_data($_POST['telephone']);
    } else {
    $telephone = FALSE;
    echo '<p class="error">Please enter a telephone!</p>';
    }  
    
    // Check for an email address.
    if (eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST['email'])))) {
      $email = escape_data($_POST['email']);
    } else {
      $email = FALSE;
      echo '<p>Please enter a valid email address!</p>';
    }
    
    // Check for a design requirement
    if (!empty($_POST['requirements'])) {
    	$requirements = escape_data($_POST['requirements']);
    } else {
    $requirements = FALSE;
    echo '<p class="error">Please enter your design requirements!</p>';
    }  
    
    // Check the account type 
    if(isset($_POST['acc_type'])){
      $acc_type = $_POST['acc_type'];
    } else {
      $acc_type = '0';
    } 
    
    // Check for a category.
    if (isset($_POST['types']) && (is_array($_POST['types']))) {
    $type = TRUE;
    } else {
    $type = FALSE;
    echo '<p class="error">Please select at least one user category!</p>';
    }
    
    // Check for a collection type
    if (!empty($_POST['collection'])) {
    	$collection = escape_data($_POST['collection']);
    } else {
    $collection = FALSE;
    echo '<p class="error">Please enter your collection type!</p>';
    }
    
    if ($type && $name && $email) {
    
    	//  Test for unique user
    	$query = "SELECT user_id FROM users WHERE email='$email'AND user_id != $id";	
    	$result = mysql_query($query);
    	if (mysql_num_rows($result) == 0) {
    
    		// Make the query.			
    		// Update the articles table.
    		$query1 = "UPDATE users SET name='$name', position='$position', company='$company', address='$address', postcode='$postcode', country='$country', telephone='$telephone', email='$email', requirements='$requirements', acc_type='$acc_type', collection='$collection' WHERE user_id=$id";			
    		#echo $query1;
    		$result1 = mysql_query($query1);
    
    		// Update the category_associations table.
    		// Retrieve the old categories.
    		$exist_types = unserialize(urldecode($_POST['exist_types']));
    
    		if ($_POST['types'] != $exist_types) { // A category change was made.
    
    			// Determine the new and old categories.
    			$add = array_diff($_POST['types'], $exist_types);
    			$delete = array_diff($exist_types, $_POST['types']);
    
    			// Add new types, if needed.
    			if (!empty($add)) {
    				$query2 = 'INSERT INTO user_associations (user_id, category_id, approved) VALUES ';
    				foreach ($add as $v) {
    					$query2 .= "($id, $v, 'Y'), ";
    				}
    				$query2 = substr ($query2, 0, -2); // Chop off the last comma and space.
    				$result2 = mysql_query ($query2); // Run the query.				
    			} else { // No new types.
    				$result2 = TRUE;
    			}
    
    			// Delete old types, if necessary.
    			if (!empty($delete)) {
    				$query3 = "DELETE FROM user_associations WHERE (user_id=$id) AND (category_id IN (". implode (',', $delete) . "))";
    				$result3 = mysql_query($query3);
    			} else { // No old types.
    				$result3 = TRUE;
    			}
    
    		} else { // No category changes being made.
    			$result2 = TRUE;
    			$result3 = TRUE;
    		}
    
    		// Report on the success.
    		if ($result1 && $result2 && $result3) {
    			echo '<p class="confirm"><b>The user has been edited!</b></p>';
    		} else {
    			#echo '<p clas="error">Your submission could not be processed due to a system error. We apologize for any inconvenience.</p>';
    			echo '<p class="confirm">The categories have been added!</p>';
    			// Print queries and use the mysql_error() function (after each mysql_query() call) to debug.
    		} 
    
    	} else { // If one of the data tests failed.
    		echo '<p class="error">That email address has been registered already</p>';		
    	}			
    
    }
    
    
    } // End of submit conditional
    
    // Display the form
    
    // Retrieve the properties information
    $query = "SELECT name, position, company, address, postcode, country, telephone, email, requirements, acc_type, collection, category_id FROM users LEFT JOIN user_associations USING (user_id) WHERE users.user_id=$id";
    
    #echo $query;
    
    $result = @mysql_query ($query); // Process the query
    
    // Get all of the information for the first record.
    $exist_types = array(); // Reset.
    list($name, $position, $company, $address, $postcode, $country, $telephone, $email, $requirements, $acc_type, $collection, $exist_types[]) = mysql_fetch_array ($result, MYSQL_NUM);
    
    // Get the other article_category_id values.
    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    $exist_types[] = $row[11];
    }
    
    ?>
    
    <form action="edit_user.php" method="post">
      <table width="500px" align="center">
            <tr>
    
              <td align="right"><img src="images/name.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="name" value="<?php echo $name; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>		
    		<tr>
    
              <td align="right"><img src="images/position.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="position" value="<?php echo $position; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>
    		<tr>
    
              <td align="right"><img src="images/company.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="company" value="<?php echo $company; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>
    		<tr>
    
              <td align="right"><img src="images/address.gif" /></td>
    			<td><div class="myBoxLhLarge"></div><textarea name="address" cols="13" rows="2" value="<?php echo $address; ?>"><?php echo $address; ?></textarea><div class="myBoxRhLarge"></div></td>
    		</tr>
    		<tr>
    
              <td align="right"><img src="images/postcode.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="postcode" value="<?php echo $postcode; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>	
    		<tr>
    
              <td align="right"><img src="images/country.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="country" value="<?php echo $country; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>
    		<tr>
    
              <td align="right"><img src="images/telephone.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="telephone" value="<?php echo $telephone; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>
    		<tr>
    
              <td align="right"><img src="images/email.gif" /></td>
    			<td><div class="myBoxLh"></div><input type="text" name="email" value="<?php echo $email; ?>" size="30" /><div class="myBoxRh"></div></td>
    		</tr>
    		<tr>
    
              <td align="right"><img src="images/design_requirements.gif" /></td>
    			<td><div class="myBoxLhLarge"></div><textarea name="requirements" cols="13" rows="2" value="<?php echo $requirements; ?>"><?php echo $requirements; ?></textarea><div class="myBoxRhLarge"></div></td>
    		</tr>
    
    
    		<tr>	
              		<td align="right">collection:</td>
    			<td>
    
    
    <input name="collection" type="radio" <?php if($collection == 'print'){  echo 'checked="checked"'; } ?> value="print" />Print<br/>
    <input name="collection" type="radio" <?php if($collection == 'licence'){  echo 'checked="checked"'; } ?> value="licence" />Licence
    
    
    </td>			
    		</tr>			
    
            	<tr>	
              		<td align="right">User Category/Categories:</td>
    			<td>
    			<select name="types[]" multiple="multiple" size="5">
    			<?php // Create the pull-down menu information.
    			#require_once ('../mysql_connect.php');
    			$query = "SELECT * FROM categories ORDER BY category ASC";		
    			$result = @mysql_query ($query);
    			while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
    				echo "<option value=\"$row[0]\"";
    				// Make sticky, if necessary.
    				if (in_array($row[0], $exist_types)) {
    					echo ' selected="selected"';
    				}
    				echo ">$row[1]</option>\n";
    			}
    			 ?>
    			</select>            
    			</td>
    		</tr>  	
    		<tr>
    
              <td align="right">Account Type:</td>
    			<td>
    				<select name="acc_type">
    					<option value="0" <?php if($acc_type == '0'){  echo 'selected="selected"'; }else{ echo ''; } ?>>Basic</option>
    					<option value="1" <?php if($acc_type == '1'){  echo 'selected="selected"'; }else{ echo ''; } ?>>Admin</option>                     
    				</select> 
    			</td>
    		</tr>	        			
    		<tr>
    
              <td colspan="2" align="right">
    <div align="center"><input type="image" src="images/submit.jpg" name="submit" value="Update" class="submit" /></div></td>
    		</tr>
    	</table>
        <?php echo '
    <input type="hidden" name="submitted" value="TRUE" />
    <input type="hidden" name="id" value="' . $id . '" />
    <input type="hidden" name="exist_types" value="' . urlencode(serialize($exist_types)) . '" />';
    ?>
    
    </form>
    </div>
    </div>
    <!-- /general -->
    <?php
    mysql_close(); // Close the db connection
    
    require('includes/footer.html');
    //end of the check authorised user function
    }
    ?>
    

     

    Footer contains

    <?php 
    
    // Display links based upon the login status.
    // Show LOGIN links if this is the LOGOUT page.
    if (isset($_SESSION['user_id']) && ($_SESSION['acc_type']=="1") && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) {
    echo '	<a href="logout_admin.php">Logout</a> | <a href="change_password.php">Change Password</a> | <a href="add_category.php">Add A Category</a> | <a href="view_categories.php">Edit A Category</a> | <a href="view_users.php">Edit A User</a> | <a href="forgot_password.php">Reset User Passwords</a> | <a href="licence.php">Licence Categories</a> | <a href="print.php">Print Categories</a> | <a href="admin_register.php">Create Account</a> | <a href="export.php" target="_blank">Export users</a>
    ';
    } elseif (isset($_SESSION['user_id']) && ($_SESSION['acc_type']=="0") && (substr($_SERVER['PHP_SELF'], -10) != 'logout.php')) {
    echo 'basic rights only';
    } else { //  Not logged in.
    echo '	<a href="register.php">Register</a> | <a href="request.php">Request New Password</a> | <a href="login.php">Login</a>';
    }
    ?>
    
    </div>
    
    
    </body>
    </html>
    <?php // Flush the buffered output.
    ob_flush();
    ?>
    

     

    Please help as this is driving me mad!

     

    Thanks in advanced!

  14. Hi,

     

    Hope you can help & this makes sense. When a user registers on my site, they select a radio button for:

    licence

    print

     

    This stores the selection in the db as text rather than 1 or 0

     

    When I edit the user, i'd like to use the radio button again, however, depending what they selected initially, needs to be the default value. i.e. they selected print when they joined, so when I edit that user, the radio button print is checked.

     

    My code is below but won't work. Please help

    <input name="collection" type="radio" value="<?php if($collection == 'print'){  echo 'checked="checked"'; }else{ echo ''; } ?>">Print				
    <input name="collection" type="radio" value="<?php if($collection == 'licence'){  echo 'checked="checked"'; }else{ echo ''; } ?>">Licence
    

    Thanks in advanced

×
×
  • 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.