haris244808 Posted August 8, 2011 Share Posted August 8, 2011 Here is the code it only includes the connection to mysql but it shows mw this error: This webpage has a redirect loop... any suggestions?? <?php // Start a session for error reporting session_start(); //Connect to database require("includes/connect_to_mysql.php"); // 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", "image/png"); if (in_array($file['type'], $valid_types)) return 1; return 0; } // 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 = "upload_form_images/"; // Get our POSTed variables $name = $_POST['name']; $surname = $_POST['surname']; $email = $_POST['email']; $city = $_POST['city']; $details = $_POST['details']; $price = $_POST['price']; $image = $_FILES['image']; // Sanitize our inputs $name = mysql_real_escape_string($name); $surname = mysql_real_escape_string($surname); $email = mysql_real_escape_string($email); $city = mysql_real_escape_string($city); $details = mysql_real_escape_string($details); $price = mysql_real_escape_string($price); $image['name'] = mysql_real_escape_string($image['name']); // Build our target path full string. This is where the file will be moved do // i.e. images/picture.jpg $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ( $name == "" || $surname == "" || $email == "" || $city == "" || $details == "" || $price == ""|| $image['name'] == "" ) { $_SESSION['error'] = "Te gjithe fushat duhet plotesuar"; header("Location: upload_form.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'] = "Fotografite duhet te jene te formateve jpg, jpeg, bmp, gif, ose png"; header("Location: upload_form.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'] = "Ju lutem nderroni emrin e fotos."; header("Location: upload_form.php"); exit; } /* // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM upload_form WHERE name='$name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { $_SESSION['error'] = 'Ju lutem nderroni emrin sepse egziston ne databaze'; header("Location: upload_form.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 people (name, surname, email, city, details, price, filename) values ('$name', '$surname', '$email', '$city', '$details', '$price', '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Futja e te dhenave ne databaze DESHTOI: " . mysql_error()); echo "Shtimi i te dhenave u krye me SUKSES"; 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'] = "Shtimi i te dhenave NUK u krye me Sukses. Ju lutem provoni perseri"; header("Location: upload_form.php"); exit; } ?> <!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>Qiraja.com</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> <!--[if lte IE 6]><link rel="stylesheet" href="css/ie6.css" type="text/css" media="all" /><![endif]--> <!--[if IE]><style type="text/css" media="screen"> #navigation ul li a em { top:32px; } </style><![endif]--> </head> <body> <!-- Header --> <div id="header"> <div class="shell"> <!-- Logo --> <h1 id="logo"><a href="#">Company Name</a></h1> <!-- End Logo --> <!-- Navigation --> <div id="navigation"> <ul> <li><a href="#">Prishtine<span><em></em></span></a></li> <li><a href="#">Prizren<span><em></em></span></a></li> <li><a href="#">Ferizaj<span><em></em></span></a></li> <li><a href="#">Peje<span><em></em></span></a></li> <li><a href="#">Mitrovice<span><em></em></span></a></li> <li><a href="#">Gjilan<span><em></em></span></a></li> <li class="last"><a href="#">Gjakove<span><em></em></span></a></li> </ul> </div> </div> </div> <div id="slider"> <div class="shell"> <!-- Slides --> <div class="slides"> <ul> <!-- Slide --> <li> <form action="upload_form.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="center">Name</td> <td width="80%"><label> <input name="name" type="text" id="name" size="64" /> </label></td> </tr> <tr> <td align="center">Surname</td> <td><label> <input name="surname" type="text" id="surname" size="64" /> </label></td> </tr> <tr> <td align="center">Email</td> <td><label> <input name="email" type="text" id="email" size="64" /> </label></td> </tr> <tr> <td align="center">City</td> <td><select name="city" id="city"> <option value=""></option> <option value="Prishtine">Prishtine</option> <option value="Prizren">Prizren</option> <option value="Ferizaj">Ferizaj</option> <option value="Peje">Peje</option> <option value="Mitrovice">Mitrovice</option> <option value="Gjilan">Gjilan</option> <option value="Gjakove">Gjakove</option> </select></td> </tr> <tr> <td align="center">Cmimi</td> <td><label> <input name="price" type="text" id="price" size="12" /> $ </label></td> </tr> <tr> <td align="center">Fotografite</td> <td><label> <input type="file" name="image" id="image" /> </label></td> </tr> <tr> <td> </td> <td><label> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input type="submit" name="submit" id="submit" value="Shto te dhenat" /> </label></td> </tr> </table> </form> </li> <!-- End Slide --> <!-- Slide --> <li> <div class="slide-info"> <h2><span>Reklamo</span> Shtepine</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p> <p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p> <a href="#" class="more">read more</a></p> </div> <span class="slide-image image1"></span> </li> <!-- End Slide --> <!-- Slide --> <li> <div class="slide-info"> <h2><span>Reklamo</span> Apartmanin</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p> <p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p> <a href="#" class="more">read more</a></p> </div> <span class="slide-image image1"></span> </li> <!-- End Slide --> </ul> </div> <!-- End Slides --> </div> </div> <!-- End Slider --> <!-- Slider Nav --> <div id="slider-navigation"> <div class="shell"> <ul> <li><a href="index.php" class="active">Kthehu ne fillim<strong>Home</strong><em class="ico1"></em></a></li> <li><a href="upload_form.php">Shto<strong>Upload</strong><em class="ico2"></em></a></li> <li class="last"><a href="contact_form.php">Kontakti<strong>Contact</strong><em class="ico3"></em></a></li> </ul> </div> </div> <!-- End Slider Nav --> <!-- Main --> <div id="main"> <div class="shell"> <!-- Cols --> <div class="cols"> <div class="cl"> </div> <!-- Col --> <div class="col"> <h3>Sed Turpis sem</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero.<br /><a href="#" class="more">read more</a></p> <p>Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <!-- Col --> <div class="col"> <h3>Ligula amet augue</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p> <p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <!-- Col --> <div class="col col-last"> <h3>Ligula amet augue</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p> <p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <div class="cl"> </div> </div> <!-- End Cols --> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 you're always redirecting to header("Location: upload_form.php"); no matter what happens. remove the redirects for now and replace with an echo 'some error'; so you can find out where the problem is. Quote Link to comment Share on other sites More sharing options...
haris244808 Posted August 8, 2011 Author Share Posted August 8, 2011 you're always redirecting to header("Location: upload_form.php"); no matter what happens. remove the redirects for now and replace with an echo 'some error'; so you can find out where the problem is. yes but i want to do that so. I want to redirect to that page again but cleaning the informations he putted? ex. he wrote the username but not the password. it will redirect to the same page (so he doesnt need to come back again)by saying all fields are required . Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 what you are doing is redirecting without first checking if the user has clicked the submit button, so one or more of your if statements is return TRUE each refresh..thus redirecting in an infinite loop.. use isset to first make sure that the user has submitted the form.. if(isset($_POST['myForm'])){ //continue with form processing } Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 8, 2011 Share Posted August 8, 2011 I'm not saying "change your code", I'm saying "change it temporarily so we can figure out where the problem is"... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 8, 2011 Share Posted August 8, 2011 cleaning the informations he putted? Why would you want to do that? Making your visitors reenter ALL the form information every time there is ONE error will mean that you will have very few visitor to your site because no one is going to stay on your site after the first time they have to reenter data they have already entered before. Quote Link to comment Share on other sites More sharing options...
haris244808 Posted August 8, 2011 Author Share Posted August 8, 2011 yes yes u r right.. I forgot the isset() now its all ok.. Thanks for helping Quote Link to comment Share on other sites More sharing options...
haris244808 Posted August 8, 2011 Author Share Posted August 8, 2011 ups guys now its not uploading my infos to database. what i want is to upload my informations to database when i press the submit button. but if any field is empty it should show a text that all fields are required but in the same page(because of that i made redirections to same page) <?php // Start a session for error reporting session_start(); //Connect to database require("includes/connect_to_mysql.php"); //check if the button is pressed if(isset($_POST['submit'])){ // 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", "image/png"); if (in_array($file['type'], $valid_types)) return 1; return 0; } // 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 = "upload_form_images/"; // Get our POSTed variables $name = $_POST['name']; $surname = $_POST['surname']; $email = $_POST['email']; $city = $_POST['city']; $details = $_POST['details']; $price = $_POST['price']; $image = $_FILES['image']; // Sanitize our inputs $name = mysql_real_escape_string($name); $surname = mysql_real_escape_string($surname); $email = mysql_real_escape_string($email); $city = mysql_real_escape_string($city); $details = mysql_real_escape_string($details); $price = mysql_real_escape_string($price); $image['name'] = mysql_real_escape_string($image['name']); // Build our target path full string. This is where the file will be moved do // i.e. images/picture.jpg $TARGET_PATH .= $image['name']; // Make sure all the fields from the form have inputs if ( $name == "" || $surname == "" || $email == "" || $city == "" || $details == "" || $price == ""|| $image['name'] == "" ) { $_SESSION['error'] = "Te gjithe fushat duhet plotesuar"; header("Location: upload_form.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'] = "Fotografite duhet te jene te formateve jpg, jpeg, bmp, gif, ose png"; header("Location: upload_form.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'] = "Ju lutem nderroni emrin e fotos."; header("Location: upload_form.php"); exit; } /* // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM upload_form WHERE name='$name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { $_SESSION['error'] = 'Ju lutem nderroni emrin sepse egziston ne databaze'; header("Location: upload_form.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 people (name, surname, email, city, details, price, filename) values ('$name', '$surname', '$email', '$city', '$details', '$price', '" . $image['name'] . "')"; $result = mysql_query($sql) or die ("Futja e te dhenave ne databaze DESHTOI: " . mysql_error()); echo "Shtimi i te dhenave u krye me SUKSES"; 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'] = "Shtimi i te dhenave NUK u krye me Sukses. Ju lutem provoni perseri"; header("Location: upload_form.php"); exit; } } ?> <!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>Qiraja.com</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> <!--[if lte IE 6]><link rel="stylesheet" href="css/ie6.css" type="text/css" media="all" /><![endif]--> <!--[if IE]><style type="text/css" media="screen"> #navigation ul li a em { top:32px; } </style><![endif]--> </head> <body> <!-- Header --> <div id="header"> <div class="shell"> <!-- Logo --> <h1 id="logo"><a href="#">Company Name</a></h1> <!-- End Logo --> <!-- Navigation --> <div id="navigation"> <ul> <li><a href="#">Prishtine<span><em></em></span></a></li> <li><a href="#">Prizren<span><em></em></span></a></li> <li><a href="#">Ferizaj<span><em></em></span></a></li> <li><a href="#">Peje<span><em></em></span></a></li> <li><a href="#">Mitrovice<span><em></em></span></a></li> <li><a href="#">Gjilan<span><em></em></span></a></li> <li class="last"><a href="#">Gjakove<span><em></em></span></a></li> </ul> </div> </div> </div> <div id="slider"> <div class="shell"> <!-- Slides --> <div class="slides"> <ul> <!-- Slide --> <li> <form action="upload_form.php" enctype="multipart/form-data" name="myForm" id="myform" method="post"> <table width="90%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="20%" align="center">Name</td> <td width="80%"><label> <input name="name" type="text" id="name" size="64" /> </label></td> </tr> <tr> <td align="center">Surname</td> <td><label> <input name="surname" type="text" id="surname" size="64" /> </label></td> </tr> <tr> <td align="center">Email</td> <td><label> <input name="email" type="text" id="email" size="64" /> </label></td> </tr> <tr> <td align="center">City</td> <td><select name="city" id="city"> <option value=""></option> <option value="Prishtine">Prishtine</option> <option value="Prizren">Prizren</option> <option value="Ferizaj">Ferizaj</option> <option value="Peje">Peje</option> <option value="Mitrovice">Mitrovice</option> <option value="Gjilan">Gjilan</option> <option value="Gjakove">Gjakove</option> </select></td> </tr> <tr> <td align="center">Cmimi</td> <td><label> <input name="price" type="text" id="price" size="12" /> $ </label></td> </tr> <tr> <td align="center">Fotografite</td> <td><label> <input type="file" name="image" id="image" /> </label></td> </tr> <tr> <td> </td> <td><label> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input type="submit" name="submit" id="submit" value="Shto te dhenat" /> </label></td> </tr> </table> </form> </li> <!-- End Slide --> <!-- Slide --> <li> <div class="slide-info"> <h2><span>Reklamo</span> Shtepine</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p> <p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p> <a href="#" class="more">read more</a></p> </div> <span class="slide-image image1"></span> </li> <!-- End Slide --> <!-- Slide --> <li> <div class="slide-info"> <h2><span>Reklamo</span> Apartmanin</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam.</p> <p>Quisque quis vestibulum turpis. Sed venenatis ipsum laoreet elit pulvinar vitae pharetra massa dignissim. Curabitur ligula sapien, auctor ut porttitor a, ultricies lobortis dui. Suspendisse lacinia tellus a diam rutrum rhoncus. </p> <a href="#" class="more">read more</a></p> </div> <span class="slide-image image1"></span> </li> <!-- End Slide --> </ul> </div> <!-- End Slides --> </div> </div> <!-- End Slider --> <!-- Slider Nav --> <div id="slider-navigation"> <div class="shell"> <ul> <li><a href="index.php" class="active">Kthehu ne fillim<strong>Home</strong><em class="ico1"></em></a></li> <li><a href="upload_form.php">Shto<strong>Upload</strong><em class="ico2"></em></a></li> <li class="last"><a href="contact_form.php">Kontakti<strong>Contact</strong><em class="ico3"></em></a></li> </ul> </div> </div> <!-- End Slider Nav --> <!-- Main --> <div id="main"> <div class="shell"> <!-- Cols --> <div class="cols"> <div class="cl"> </div> <!-- Col --> <div class="col"> <h3>Sed Turpis sem</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. Sed turpis sem, interdum sit amet egestas a, mattis non libero.<br /><a href="#" class="more">read more</a></p> <p>Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <!-- Col --> <div class="col"> <h3>Ligula amet augue</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p> <p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <!-- Col --> <div class="col col-last"> <h3>Ligula amet augue</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam arcu ligula, faucibus eu imperdiet eu, bibendum sit amet augue. <br /><a href="#" class="more">read more</a></p> <p>Sed turpis sem, interdum sit amet egestas a, mattis non libero. Suspendisse tristique nisi sed justo accumsan vel mattis nulla fermentum. Etiam varius est id mi fermentum aliquam. <br /><a href="#" class="more">read more</a></p> </div> <!-- End Col --> <div class="cl"> </div> </div> <!-- End Cols --> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
haris244808 Posted August 8, 2011 Author Share Posted August 8, 2011 any suggestion?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.