PHP - Simple Remote Image Display Script Help
Hi,
I am planning to display remote images with the following code but it seems to return errors. <?php $image_dir = 'http://www.domain.com/images/' ; $dir_handle = opendir( $image_dir ); $count = 0 ; $display = '' ; while( $filename = readdir($dir_handle)){ if( preg_match( '/$[a-z0-9]{4}_th\.jpg$/' , $filename ) ){ $display .= " <img src='$image_dir$filename' /> " ; $count++ ; if( $count % 10 == 0 ){ $count=0; $display .= "<br />"; } } } closedir( $dir_handle ); echo $display ; ?> I am thinking might be the $image_dir cannot use address format.... Errors is as follow Quote Warning: opendir(http://www.foo.com/images/) [function.opendir]: failed to open dir: not implemented in /home/jch02140/public_html/test.php on line 3 Warning: readdir(): supplied argument is not a valid Directory resource in /home/jch02140/public_html/test.php on line 6 Warning: closedir(): supplied argument is not a valid Directory resource in /home/jch02140/public_html/test.php on line 16 Similar TutorialsWell the subject line is pretty explicit. I found this script that uploads a picture onto a folder on the server called images, then inserts the the path of the image on the images folder onto a VACHAR field in a database table. Code: [Select] <?php //This file inserts the main image into the images table. //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //Check whether the session variable id is present or not. If not, deny access. if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) { header("location: access_denied.php"); exit(); } else{ // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { // This is an array that holds all the valid image MIME types $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } // Just a short function that prints out the contents of an array in a manner that's easy to read // I used this function during debugging but it serves no purpose at run time for this example function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } // Set some constants // This variable is the path to the image folder where all the images are going to be stored // Note that there is a trailing forward slash $TARGET_PATH = "images/"; // Get our POSTed variable $image = $_FILES['image']; // Sanitize our input $image['name'] = mysql_real_escape_string($image['name']); // Build our target path full string. This is where the file will be moved to // i.e. images/picture.jpg $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ( $image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: member.php"); exit; } // Check to make sure that our file is actually an image // You check the file type instead of the extension because the extension can easily be faked if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: member.php"); exit; } // Here we check to see if a file with that name already exists // You could get past filename problems by appending a timestamp to the filename and then continuing if (file_exists($TARGET_PATH)) { $_SESSION['error'] = "A file with that name already exists"; header("Location: member.php"); exit; } // Lets attempt to move the file from its temporary directory to its new home if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { // NOTE: This is where a lot of people make mistakes. // We are *not* putting the image into the database; we are putting a reference to the file's location on the server $sql = "insert into images (member_id, image_cartegory, image_date, image) values ('{$_SESSION['id']}', 'main', NOW(), '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); header("Location: images.php"); echo "File uploaded"; exit; } else { // A common cause of file moving failures is because of bad permissions on the directory attempting to be written to // Make sure you chmod the directory to be writeable $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; header("Location: member.php"); exit; } } //End of if session variable id is not present. ?> The script seems to work fine because I managed to upload a picture which was successfully inserted into my images folder and into the database. Now the problem is, I can't figure out exactly how to write the script that displays the image on an html page. I used the following script which didn't work. Code: [Select] //authenticate user //Start session session_start(); //Connect to database require ('config.php'); $sql = mysql_query("SELECT* FROM images WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main' "); $row = mysql_fetch_assoc($sql); $imagebytes = $row['image']; header("Content-type: image/jpeg"); print $imagebytes; Seems to me like I need to alter some variables to match the variables used in the insert script, just can't figure out which. Can anyone help?? I came up with the following script for displaying an uploaded picture on a webpage but for some reason I can't pinpoint, the picture won't be displayed. I checked my database from php myadmin and sure enough, the picture was successfully uploaded but somehow, the picture won't be displayed. So here is the display script. I named it display_pic.php Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //include the config file require('config.php'); $image = stripslashes($_REQUEST[imname]); $rs = mysql_query("SELECT* FROM images WHERE member_id = '".$_SESSION['id']."' AND image_cartegory = 'main' "); $row = mysql_fetch_assoc($rs); $imagebytes = $row[image]; header("Content-type: image/jpeg"); print $imagebytes; ?> The tag on the html page that's supposed to display the picture reads something like this <img src="display_pic.php" width="140" height="140"> And just in case this might help, I will include the image upload script below, which I think worked just fine because my values were successfully inserted into the database. Code: [Select] <?php //This file inserts the main image into the images table. //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //Check whether the session variable id is present or not. If not, deny access. if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) { header("location: access_denied.php"); exit(); } else{ // Make sure the user actually // selected and uploaded a file if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { // Temporary file name stored on the server $tmpName = $_FILES['image']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); // Create the query and insert // into our database. $query = "INSERT INTO images (member_id, image_cartegory, image_date, image) VALUES ('{$_SESSION['id']}', 'main', NOW(), '$data')"; $results = mysql_query($query); // Print results print "Thank you, your file has been uploaded."; } else { print "No image selected/uploaded"; } // Close our MySQL Link mysql_close(); } //End of if statmemnt. ?> So any insights as to why the script fails to display the image? Any help is appreciated. I had posted a similar post a few days back, about an display script which is supposed to retrieve a stored image from my database and displays it on an html page, but fails to do so. Someone suggested that I upload my image onto a folder on the server and then save the image path name in my database. I found this script(below) which does just that. It uploads the image into a folder on the server called images and stores the image path into a table in my database called images and I know this script works because i saw the file saved in the images folder and the path name inserted into the images table. Code: [Select] <?php //This file inserts the main image into the images table. //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user //Start session session_start(); //Connect to database require ('config.php'); //Check whether the session variable id is present or not. If not, deny access. if(!isset($_SESSION['id']) || (trim($_SESSION['id']) == '')) { header("location: access_denied.php"); exit(); } else{ // Check to see if the type of file uploaded is a valid image type function is_valid_type($file) { // This is an array that holds all the valid image MIME types $valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif"); if (in_array($file['type'], $valid_types)) return 1; return 0; } // Just a short function that prints out the contents of an array in a manner that's easy to read // I used this function during debugging but it serves no purpose at run time for this example function showContents($array) { echo "<pre>"; print_r($array); echo "</pre>"; } // Set some constants // This variable is the path to the image folder where all the images are going to be stored // Note that there is a trailing forward slash $TARGET_PATH = "images/"; // Get our POSTed variable $image = $_FILES['image']; // Sanitize our input $image['name'] = mysql_real_escape_string($image['name']); // Build our target path full string. This is where the file will be moved to // i.e. images/picture.jpg $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ( $image['name'] == "" ) { $_SESSION['error'] = "All fields are required"; header("Location: member.php"); exit; } // Check to make sure that our file is actually an image // You check the file type instead of the extension because the extension can easily be faked if (!is_valid_type($image)) { $_SESSION['error'] = "You must upload a jpeg, gif, or bmp"; header("Location: member.php"); exit; } // Here we check to see if a file with that name already exists // You could get past filename problems by appending a timestamp to the filename and then continuing if (file_exists($TARGET_PATH)) { $_SESSION['error'] = "A file with that name already exists"; header("Location: member.php"); exit; } // Lets attempt to move the file from its temporary directory to its new home if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)) { // NOTE: This is where a lot of people make mistakes. // We are *not* putting the image into the database; we are putting a reference to the file's location on the server $sql = "insert into images (member_id, image_cartegory, image_date, image) values ('{$_SESSION['id']}', 'main', NOW(), '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error()); header("Location: images.php"); echo "File uploaded"; exit; } else { // A common cause of file moving failures is because of bad permissions on the directory attempting to be written to // Make sure you chmod the directory to be writeable $_SESSION['error'] = "Could not upload file. Check read/write persmissions on the directory"; header("Location: member.php"); exit; } } //End of if session variable id is not present. ?> Now the display image script accompanying this insert image script is shown below. Code: [Select] <?php // Get our database connector require("config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Dream in code tutorial - List of Images</title> </head> <body> <div> <?php // Grab the data from our people table $sql = "SELECT * from images WHERE image_cartegory = 'main'"; $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<div class=\"picture\">"; echo "<p>"; // Note that we are building our src string using the filename from the database echo "<img src=\"images/ " . $row['filename'] . " \" alt=\"\" />"; echo "</p>"; echo "</div>"; } ?> </div> </body> </html> Well, needless mentioning, the picture isn't displayed. Just a tiny jpeg icon is displayed at the top left hand corner of the page. Figuring out that the problem might be the lack of a header that declares the image type, I add this line header("Content-type: image/jpeg"); but all it does is display a blank white page, without the tiny icon this time. What am I missing? Any clues?? I have created 5 websites under 5 different domains. Contents of this websites' are similar and using a same template for each one. Now I need to create an admin panel to control these websites. PHP and MySql I will use for this backend.
My problem is how can I manage these five website with one backend? Reason is I will use different domain for my backend. My all 5 client will use this same backend system to manage their own website.
So can I know from the professionals here, is it possible to display mysql data on these 5 website. If it is possible then how?
Any links to article or tutorials would be welcome and appreciated.
NOTE: I checked
mysql federated storage enginebut no idea? Is it the way where do I need to go? Thank you. Hi all, I have two issue with script. 1. It works in PhpEd and with apache but doesn't work at remote server with apache. Error is well known - "Warning: Cannot modify header information - headers already sent " 2. when I added more than 20 records like $var = $_POST['var']; it stops work local. Error is same. adminka_wrapp.php Code: [Select] <?php $addFormatName = $_POST['addFormatName']; $addFormatDes = $_POST['addFormatDes']; $page = $_GET['page']; if (isset($addFormatName) && isset($addFormatDes)) { $page = 'add_formats'; } else if ($page == NULL) { $page = "user_access_log"; } ?> <!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> <link rel="stylesheet" type="text/css" href="../style/adminkaview.css"> </head> <body> <div class="col-wrap1"> <div class="col-wrap2"> <div class="col1"> <div class="content" id="c1"> <p><a href="?page=view_add_format">Format and extensions</a></p> </div> </div> <div class="col2"> <div class="content" id="c2"> <?php require("$page.php");?> </div> </div> <div class="clear"></div> </div> </div> </body> </html> view_add_format.php Code: [Select] <?php require_once "../function.php"; $q = connect("SELECT `formats`.* FROM `xxx`.`formats` "); echo "<form method='post' action='adminka_wrapp.php'> <table> <tr> <td>id</td> <td>Formats Name</td> <td>Description</td> </tr>"; while($rowResult = $q->fetch_assoc()) { echo "<tr>"; $id = $rowResult["id"]; $formatName = $rowResult["f_name"]; $description = $rowResult["description"]; echo "<td>".$id."</td>" ."<td>".$formatName."</td>" ."<td>".$description."</td>"; echo "</tr>"; } echo " <tr> <td> <input type='submit' value='AddFormat' name='submitAddFormat'> </td> <td> <input type='text' name='addFormatName' maxlength='20' size='5'> </td> <td> <input type='text' name='addFormatDes' maxlength='20' size='5'> </td> "; echo "</table> </form>"; ?> add_formats.php Code: [Select] <?php require "../function.php"; if (isset($addFormatName) && isset($addFormatDes) ) { $q = connect("INSERT INTO `xxx`.`formats` (`id` ,`f_name` ,`description` ) VALUE (NULL ,'$addFormatName' ,'$addFormatDes' ) "); header("Location: adminka_wrapp.php?page=view_add_format"); exit(); } ?> function.php Code: [Select] <?php function connect($query) { $db = new mysqli('127.0.0.1', 'xxx', 'xxx', 'xxx'); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $result = $db->query($query); $db->close(); return $result; } ?> I'm trying to save images from a directory into mine. To get the image I am having to take the email from a database, split it and take whatever it is before the '@' sign and add it to "-S.jpg". I wrote the script and when I echo the variable it shows the correct thing, but when it tries to save it , it is trying to find the image as "script>-S.jpg". It looks like it is taking whatever is after the last '/' which in the variable since I am running javascript it is going to be </script> if you look at my variable $url. Here is the code below. Any help is appreciated. while($rows=mysql_fetch_array($result)){ $email=$rows['email']; $url= "<SCRIPT LANGUAGE=\"javascript\"> var url; var email = \"$email\"; function emailsplit () { var userid = email.split(\"@\"); var url = userid[0]; var imgid = \"http://my.snu.edu/images/idpictures/\" + url + \"-S.jpg\"; return url; } document.write(emailsplit()); </script> "; $img[]= 'http://my.snu.edu/images/idpictures/'.$url.'-S.jpg'; } function save_image($img,$fullpath='basename'){ if($fullpath=='basename'){ $fullpath = basename($img); } $ch = curl_init ($img); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); if(file_exists($fullpath)){ unlink($fullpath); } $fp = fopen($fullpath,'x'); fwrite($fp, $rawdata); fclose($fp); } foreach($img as $i){ save_image($i); if(getimagesize(basename($i))){ echo '<h3 style="color: green;">Image ' . basename($i) . ' Downloaded OK</h3>'; }else{ echo '<h3 style="color: red;">Image ' . basename($i) . ' Download Failed</h3>'; } } Please help before this script drives me insane. It tries to download a skin from Minecraft. It works fine, except, if it returns an error code, (301, 302, 404), don't download, and using my image (char.png) as a replacement. I can get the error code, except, no matter how I compare it, it will a) still say it's 302 or b) not work at all. Here's my code: userskin.inc.php > <?php require('class.mineuser.php'); if(!isset($_GET['width']) || strlen(trim($_GET['width'])) == 0 || !isset($_GET['height']) || strlen(trim($_GET['height'])) == 0) { $x = 16; $y = 16; } else { $x = $_GET['width']; $y = $_GET['height']; } if(isset($_GET['refresh'])) $refresh = true; else $refresh = false; if(isset($_GET['debug'])) $debug = true; else $debug = false; $http = curl_init("http://www.minecraft.net/skin/{$_GET['user']}.png"); curl_setopt($http, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($http); $http_status = curl_getinfo($http, CURLINFO_HTTP_CODE); $resp = preg_match("/302/", $http_status, $match); $code = $match[0]; if($code == 302) { mineuser::downloadSkin($_GET['user'], $_GET['path'], $code, $refresh); mineuser::getFace($_GET['user'].".png", $x, $y, $_GET['path'], $code, $debug); } else { mineuser::getFace("char.png", $x, $y, $_GET['path'], $code, $debug); } class.mineuser.php > <?php class mineuser { public static function downloadSkin($user, $path = "", $resp, $new = false) { if($resp !== 302) { //Checks if $new is true, if it is, then delete $user.png and download a new one. if($new == true) unlink("$path/$user.png"); //Checks if the users skin already exists (faster loading time) if(!file_exists("$path/$user.png")) { $fh = fopen("$path/$user.png", "w"); $file = file("http://www.minecraft.net/skin/$user.png"); foreach($file as $char) //Since it's an array, we use a foreach loop and write each character individually fwrite($fh, $char); fclose($fh); //Close our file handler. } } else { } } //End of function downloadSkin() public static function getFace($user, $width, $height, $path, $resp, $debug = true) { $im = imagecreatetruecolor($width, $height); if($debug == false) { header("Content-type: image/png"); } if($resp === 302) { $image = imagecreatefrompng("$path/char.png"); } else { $image = imagecreatefrompng("$path/$user"); } imagecopyresampled($im, $image, 0, 0, 8, 8, $width, $height, 8, 8); imagepng($im); imagedestroy($im); } //End of function getFace() } ?> please help before i go insane Thanks in advance i need to count the number of image files on a remote server not in my network. ive come across a suggestion to use
@getimagesize($img_url)the above works but is really slow. anyone able to suggest a better method? Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Hello all, I was just reading the PHP manual and came across this example that doesn't work right for me. Anyone know why this is so? Tried looking through the manual for this but found nothing about it.. $s = 'monkey'; $t = 'many monkeys'; printf("[%s]\n", $s); // standard string output printf("[%10s]\n", $s); // right-justification with spaces printf("[%-10s]\n", $s); // left-justification with spaces printf("[%010s]\n", $s); // zero-padding works on strings too printf("[%'#10s]\n", $s); // use the custom padding character '#' printf("[%10.10s]\n", $t); // left-justification but with a cutoff of 10 characters The above example will output: [monkey] [ monkey] [monkey ] [0000monkey] [####monkey] [many monke] But when i tried this for myself, printf("[%10s]\n", $s);does not left pad the output as so : [ monkey].Instead it outputs [ monkey]. But adding a 0 as so : printf("[%010s]\n", $s);, pads it with 4 0's, outputting : [0000monkey] . Is there some other way to make it pad spaces that i'm missing? Running PHP 5.3.2 Hello, Five images will be displayed inside a division. There will be a previous and next button/link. If someone click the next button the next image will be added in that div and the first image will be gone from that div. The previous button/link will do the same thing. Is it possible with php? I am confused if it's a javascript or ajax question. Thanks. Would like to be able to click on a radio button that represents an image. Once selected and submitted, have that image display on another page. I have an idea, but need some guidance. BTW, is using php only doable? Is there a simpler or more elegant way to do this? Thanks all! <html> <head></head> <body> My favourite bands a <ul> <?php // define arrays $morebands = array('Desturbed', 'Anthrax'); $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands"); // loop over it // print array elements foreach ($artists as $a) { if ($a != 'Array'){ echo '<li>'.$a; } Else { foreach ("${$a}" as $b){ echo '<li>'.$b; } } } ?> </ul> </body> </html> I can not figure out why this will not work:( I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well. I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so). right now I am working on http://devzone.zend.com/node/view/id/635 anyhow thanks for any help! Hello all, I am new to php and was wondering if i could get some guidance here. I am using phpAdmin 2.6.0 and running Mysql 4.1.21. here is my situation.... I have a script that allows us to upload a new product name, product code, category and a PDF file to the data base. There is also a folder on the server that has the PDF files in it. I think I deleted the code on the page (library.php) that displays the files for the client to download. My goal here is after I upload everything I want it to then be displayed on the page with a link to the PDF file. Here is the page that has the links on it. I hope that I explained this correctly. I am not a programmer but do have some idea and have been reading up on php to try and figure this out. I am looking to create the script that would display the links on the library.php page. Any help would be great. The other link is to the script that allows us to upload. www.pennstateind.com/library.php www.pennstateind.com/lib-admin.php Hi everybody, my goal is to get the IP of someone accesing the site, writing the time and date along with his IP into the database. Of course, I would be adding the script to my frontpage when I make it work. But I get this error: Quote Parse error: syntax error, unexpected T_VARIABLE in D:\Program Files\xampp\xampp\htdocs\script1.php on line 8 I've checked line 8, I dont find anything in it that is out of place. Here is the code: <?php $ip = $_SERVER['REMOTE_ADDR']; $date = date("m.d.y"); $time = time(); mysql_connect ("localhost", "root", "********") or die ('Error: '. mysql_error()); mysql_select_db ("ip"); $query = "INSERT INTO ipdo (time, date, ip) VALUES ('"$time"', '"$date"', '"$ip"')"; mysql_query($query) or die ('Error updating database'); echo "Database updated with: " .$ip. "" ; ?> This is the first script I write entirely on my own, so be gentle Help? i already have the front page that calls the script, but its not letting me login, i don't see the problem i know its returning the rows from the database but i don't understand why its not letting me login and when i do get it to login messing around with the code everybody logs in as an admin, my database has, user, pass, and role inside admin, poweruser, and reg user but when i get it to log in everybody logs in as an admin, can someone please help me ? i even tried the error thing but that doesn't seem to work either ini_set('display_errors', 1); error_reporting(E_ALL); //echo ini_set('display_errors'); session_start(); $username = $_POST['username']; $password = $_POST['password']; if (mysql_connect("localhost", "root", "")) { //echo 'connect'; } else { echo 'failure'; } if (mysql_select_db("athentication")) { //echo 'connect'; } else { echo 'no connect'; } $result = mysql_query("SELECT * FROM login WHERE user = '$username'"); $rows = mysql_num_rows($result); $role = $rows['role']; if ($rows != 0) { if ($role == 'admin') { header('Location: admin.php'); $_SESSION['username'] = $username; } elseif ($role == 'poweruser') { header('Location: poweruser.php'); $_SESSION['username'] = $username; } /*elseif ($role ==' reg') { echo "WHAT UP"; $_SESSION['username'] = $username; }*/ } else echo "enter a valid user name"; I was told that you guys could probably help me with this, so heres my situation. I use this program called Activeworlds, and me and my buddies are makeing a "tv show" if you will within the program. To do so, you take screenshots, save the screenshots, and add the image files into a directory on your domain. You need a .php script to present them as a slideshow. Now the problem is, ive searched for scripts already made from other sites, but the thing is, they are all fancy slideshow viewers, meaning they come with control buttons to cycle through the pictures and all kinds of other banners and flashy looking things. The only script im needing, is a simple script that will display and cycle through the raw images, and nothing else, within the web browser, in a slideshow format. Id also like to have a value I can edit that will change how fast the pictures cycle through, 15 seconds or so would be perfect however. If someone could refer me to this code or even make it for me, it would be soo appreciated. I know im probably asking for alot, but it would help me soo much. I wish I knew a little more about .php files to do it myself, or else I would. If you do link me to a script, please give me simple instructions on what to do with it lol because like I said, I dont know anything about the world of .php yet. Thank you all for your time. There is a sql query happening if the item is not empty, what I NEED and can not seem to figure out is to re run the rand() function. The server is PHP 4 so it is not possible to use the goto statement... That would be to easy. So any help would be great... Here is the code... the script running after the script finds a empty sql row is ot included... it works... just this one part does not. Code: [Select] <?php $connection = mysql_connect(CREDENTIALS REMOVED) or die(mysql_error()); mysql_select_db("testingblock", $connection)or die(mysql_error()); $random_num = rand(1,10); if($random_num == 1){ $query = sprintf("SELECT email FROM access_codes WHERE id='1'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 2){ $query = sprintf("SELECT email FROM access_codes WHERE id='2'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 3){ $query = sprintf("SELECT email FROM access_codes WHERE id='3'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 4){ $query = sprintf("SELECT email FROM access_codes WHERE id='4'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<br />'; if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 5){ $query = sprintf("SELECT email FROM access_codes WHERE id='5'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 6){ $query = sprintf("SELECT email FROM access_codes WHERE id='6'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if($random_num == 7){ $query = sprintf("SELECT email FROM access_codes WHERE id='7'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 8){ $query = sprintf("SELECT email FROM access_codes WHERE id='8'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 9){ $query = sprintf("SELECT email FROM access_codes WHERE id='9'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<br />'; if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 10){ $query = sprintf("SELECT email FROM access_codes WHERE id='10'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } ?> [icode] |