PHP - Empty Field Check
Ok so i have registration page on my webs but i didn't work on empty fields so how could i check all fields?
Code: [Select] //if no name if(!$name){ $error = "Username missing."; } //if no pass if($pass == false){ $error = "$error,Password missing"; } //if no pass conf if($pass_conf == false) { $error = "$error,Pass conf missing."; } //if no email if($email == false){ $error = "$error,Email missing."; } //pass conf if($pass != $pass_conf){ $error = "$error,Passwords do not match."; } echo "<script>alert('$error');</script>;"; //header("Location: register.php"); My script gives same results every time (even if i fill any of fields)...also if i un-comment header command it wont show alert..it just reloads the page So can anyone help me with this? Thanks.. Similar TutorialsNow this one is a bit of a shit head. I am using a really comprehensive class i found on on the web for upload / re-size / crop but i want to be able to override it's error handling and i am not good enough to start modifying the code in the class with out fucking it up. Firstly i will show you how i have invoked the class. Code: [Select] if( isset($_FILES['image'] ) ) { //Class includes include("../scrips/php/cms/database.insert.class.php"); include ("../scrips/php/cms/img.upload.resize.crop.class.php.php"); //----------|Start: upload, resize & save $your_image = new _image; //----------| Upload orginal image $your_image->uploadTo = 'uploads/'; $upload = $your_image->upload($_FILES['image']); //----------| Resize and upload small thumbnail $your_image->newPath = 'thums/'; $your_image->newWidth = 50; $your_image->newHeight = 50; $resized = $your_image->resize(); //----------| Resize and upload medium thumbnail $your_image->newPath = 'thums2/'; $your_image->newWidth = 100; $your_image->newHeight = 100; $resized = $your_image->resize(); //----------| Getting the image name to insert into the database futher on in the code $name = $resized; $img_str = explode("/",$name); $final_img_name = $img_str['1']; echo "Article has been added!"; //----------------|end //----------------| Start database insert (class manipulation) $table = "blog_posts"; $title = "'".$_POST['ArticleTitle']."',"; $img = "'".$final_img_name."',"; $post = "'".$_POST['ArticleBody']."',"; $aurthor_id = "'1',"; $category_id = "'".$_POST['Category']."',"; $date_posted = "NOW()"; $values = array("$title","$img","$post","$aurthor_id","$category_id","$date_posted"); $fields = array('title,','img,','post,','aurthor_id,','category_id,','date_posted'); $obj= new DatabaseInsert; $obj->DatabaseConnectionRequire(); $obj->ArticleInsert($values,$fields,$table); //----------------|end } As you can see it's fairly basic. What i want to do is before it runs this script and starts including/invoking the class etc, i want to be able to check to see if there is a value been posted from a FILE FORM OBJECT and if there is to proceed with this script, alternatively i want it to execute another code which will handle it in regards to the concept of my page. A simple javascript alert with be ok providing it reloaded the page to it's default state. If any one can help me here i would appreciate it a lot. Thanks What I am looking for is that if any field in a database is empty, the form comes back and puts in the word "empty" into the web page, but not the database. I got this right now, it shows the first part fine, but the second part it doesn't show the "Empty" comment... I don't understand why... as far as I can tell the code is fine... Code: [Select] <?php //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box3">'; if (!empty($row['Nonconformity']) || !empty($row['Disposition']) || !empty($row['Comments']) || !empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />' . $row['Nonconformity'] . '</div>'; echo '<div id="dis"><span class="b">Disposition: </span><br />' . $row['Disposition'] . '</div>'; echo '<div id="comm"><span class="b">Comments: </span><br />' . $row['Comments'] . '</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />' . $row['CommentsAdditional_Details'] . '</div>';} else if (empty($row['Nonconformity']) || empty($row['Disposition']) || empty($row['Comments']) || empty($row['CommentsAdditional_Details'])) { echo '<div id="non"><span class="b">Nonconformity: </span><br />Empty</div>'; echo '<div id="dis"><span class="b">Disposition: <br /></span>Empty</div>'; echo '<div id="comm"><span class="b">Comments: <br /></span>Empty</div>'; echo '<div id="comma"><span class="b">Comments and/or Additional Details: </span><br />Empty</div>';} echo '</div>'; ?> (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. Hi all, I have this: Code: [Select] <?php session_start(); include('login/functions.php'); $username = $_SESSION['username']; $check = mysql_query("SELECT email FROM user_profile WHERE username = '$username'"); $a = mysql_fetch_field($check); if(empty($a)) { header('Location: complete.php'); } ?> However if the field is empty, ie no email address for user then nothing happens? Am going about this the right way? Cheers I have a number of fields to display on a page, from a mysql query, some fields are empty, some not. depends on what they choose on the original form. I am trying to display on the form results on a page formatted using the below: If the mysql field is empty, display an unchecked check box next to the result. If there is data in the field display a check box ticked. What can i do to achieve this, can you point me in the right direction? Results page using echo: </TD><TD>Options: <input type='checkbox' CHECKED>". $row[17]. " </TD> = is not empty field </TD><TD>Options: <input type='checkbox' UNCHECKED>". $row[17]. " </TD> = emtpy ,mysql field </TD><TD>Options: <input type='checkbox' CHECKED>". $row[18]. " </TD> = not empty mysql field from query </TD><TD>Options: <input type='checkbox' UNCHECKED>". $row[18]. " </TD> = Empty field in mysql I am trying to show Rows 1 to 16 to display normally, rows 17 to 30 use the above logic. There are about 30 fields to display like this, the others are required fields and are displayed no matter what. i am pulling the login date from the databases and i want it to check if the variable is empty and if it is echo Never Loged In and if it not empty echo the date <?php include'db.php'; $id=$_GET['id']; $sql=mysql_query("SELECT * FROM admin WHERE id='$id'")or die(mysql_error()); while($row=mysql_fetch_array($sql)) { $date=$row['login_date']; if($date > 0) { echo"Never Loged In"; } else { echo"$date"; } } ?> I have two array, how I can have if else to check if both array1 and array2 are empty? if (empty both arrays) { } else { even if one of them are not empty } Hi, I have a form containg three text inputs and one text area. On the php page that processes the form, I want to check first to make sure the user entered something (input field is not empty) before processing the form. I'll just provide a skeleton of form processing page below. *(I'm save space and time by omitting the form itself but he text inputs fields have the following name attributes "name", "company", "email", and the textarea field's name attribute is "message" ) I'll do my best to explain the code in further detail within the code comments. Code: [Select] <?php //Turn on output buffering. Allows for headers to be called anywhere on script. See pg228 Ulman. ob_start(); if (isset($_POST['submit'])) { // Initialize a session to keep tract of error and success messages: session_start(); //Define a session variable that keeps tract of how many times user accesses page. $_SESSION['views'] = 1; // Connect to the database. require('config/config.php'); //Check for errors. //Check to make sure they entered their name. if (!empty ( $_POST['name'])) { $a = TRUE; } else { $a = FALSE; //This variable will be echoed on the form if field is missing a value $_SESSION['name'] = '*Please enter a valid name.'; } //Check to make sure they entered their company name. if (!empty ( $_POST['company'])) { $b = TRUE; } else { $b = FALSE; //This variable will be echoed on the form if field is missing a value $_SESSION['company'] = '*Please enter the name of an institution you are affiliated with.'; } //Check to make sure email is valid. if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) { $c = TRUE; }else { $c = FALSE; //This variable will be echoed on the form if field is missing a value or email format is wrong. $_SESSION['email'] = '*Please enter a valid email address.'; } //Check to make sure they entered their message. if (!empty ( $_POST['message'])) { $d = TRUE; } else { $d = FALSE; //This variable will be echoed on the form if field is missing a value $_SESSION['message'] = '*Please enter your message.'; } //If no errors if (empty($_SESSION['name'] ) && empty($_SESSION['company'] ) && empty($_SESSION['email'] ) && empty($_SESSION['message'] ) ) { //Insert data into database. $query = "INSERT INTO table... ; $result = mysql_query($query) or die("Data could not be inserted into table because: " .mysql_error()); if (mysql_affected_rows() == 1) { // Display success message //This variable will be echoed on the form if everything is filled out correctly. $_SESSION['sent'] = "Your email has been sent. We will get back to you shortly."; // Display contact page (the page containing the form) header("Location: contact_page.php"); exit(); }else{die(mysql_error());} //Display error messages. } else {// if errors array is not empty // Display page (page containing the form) header("Location: contact_page.php"); exit(); }//End of if there are errors. }//End of if submit. ?> So there it is. Everything works fine except that the part which checks if the textarea (named "message") is empty, doesn't work. If I click the submit button without filling out any field, the appropriate error messages are printed for the text input fields but not the text area field. If I fill out all fields correctly and leave the "message" field blank, the form gets processed correctly and values are placed in the database and the success message is printed out. This is also the case when I enter a value for "message" textarea field. Now I tried something. I changed the textarea to a text field and the $_SESSION['message'] variable finally got echoed when I left this field blank. So apparently, the problem arises from the fact that the named attribute from a textarea tag is not being processed correctly?? Who knows what's going wrong here? I have the form / script below that works to add multiple rows of data with one query. One thing I did not think about is what if the first set of form fields are filled and the second is not. Currently the script insert an empty row. I'm sure how I would go about checking for an empty row and if there is an empty row ignore it and do not put it in the DB. Can someone point me in the right direction? Code: [Select] <?php // Begin the script for this page if (isset($_POST['submit'])) { //Assign each array to a variable $id = $_POST['id']; $store = $_POST['store']; $item = $_POST['item']; $itemprice = $_POST['itemprice']; $itemnumber = $_POST['itemnumber']; $couponvalue = $_POST['couponvalue']; $couponsused = $_POST['couponsused']; $limit = count($id); $values = array(); // initialize an empty array to hold the values for($i=0;$i<$limit;$i++){ $store[$i] = check_input($store[$i]); $item[$i] = check_input($item[$i]); $itemprice[$i] = check_input($itemprice[$i]); $itemnumber[$i] = check_input($itemnumber[$i]); $couponvalue[$i] = check_input($couponvalue[$i]); $couponsused[$i] = check_input($couponsused[$i]); $values[$i] = "( '{$id[$i]}', '{$store[$i]}', '{$item[$i]}', '{$itemprice[$i]}', '{$itemnumber[$i]}', '{$couponvalue[$i]}', '{$couponsused[$i]}')"; // build the array of values for the query string } $query = "INSERT INTO `item` (user_id, store, item, itemprice, itemnumber, couponvalue, couponsused) VALUES " . implode( ', ', $values ); // Form the query string and add the implod()ed values if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { $added = "Your items have been added."; } } ?> <div class="pageContent"> <div id="main"> <div class="container"> <?php echo $added; if($_SESSION['id']){ echo '<form action="" method="post">'; echo '<table cellpadding= "4">'; echo '<tr>'; echo '<input type="hidden" name="id[]" id="id[]" value='.$_SESSION['id'].' />'; echo '<td><DIV CLASS="p2"><b>Store</b></div>'; echo '<input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b>Item</b></div>'; echo '<input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b>Item Price</b></div>'; echo '<input type="text" name="itemprice[]" id="itemprice[]" size="5" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b>Item #</b></div>'; echo '<select name="itemnumber[]" id="itemnumber[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><DIV CLASS="p2"><b>Coupon Value</b></div>'; echo '<input type="text" name="couponvalue[]" id="couponvalue[]" size="10" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b># Coupons</b></div>'; echo '<select style="width: 60px;" name="couponsused[]" id="couponsused[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><DIV CLASS="p2"><b>Doubled Coupon</b></div>'; echo '<select style="width: 75px;" name="doubledcoupon[]" id="doubledcoupon[]"><option value="1">Yes</option><option value="0">No</option></td>'; echo '</tr>'; echo '<tr>'; echo '<input type="hidden" name="id[]" id="id[]" value="'.$_SESSION['id'].'" />'; echo '<td><input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td>'; echo '<td><input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td>'; echo '<td><input type="text" name="itemprice[]" id="itemprice[]" size="5" maxlength="255"/></td>'; echo '<td><select name="itemnumber[]" id="itemnumber[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><input type="text" name="couponvalue[]" id="couponvalue[]" size="10" maxlength="255"/></td>'; echo '<td><select style="width: 60px;" name="couponsused[]" id="couponsused[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><select style="width: 75px;" name="doubledcoupon[]" id="doubledcoupon[]"><option value="1">Yes</option><option value="0">No</option></td>'; echo'</tr>'; echo'<tr>'; echo '<input type="submit" name="submit" value="Submit Item">'; echo'</tr>'; echo '</table>'; echo'</form>'; } else { echo '<h1>Please, <a href="index.php">login</a> and come back later!</h1>'; } ?> </div> </div> </div> Been trying to find an answer and keep running around in circles... I have: ( left test echos in there) if ($r['left_house_number'] != '') { /* Now see what they are supposed to get */ $left_customer_query = "SELECT * FROM customer WHERE house_number ='".$r['left_house_number']."' AND street = '".$r['left_house_street']."' AND route_number = '".$_SESSION['route_number']."'"; // echo "SELECT * FROM customer WHERE house_number ='".$r['left_house_number']."' AND street = '".$r['left_house_street']."' AND route_number = '".$_SESSION['route_number']."'"; $left_customer_result = mysql_query($left_customer_query) or die(mysql_error()); $left_customer_result_count = mysql_num_rows($left_customer_result); echo $r['left_house_number'].' =lhn1'; while ($lrow = mysql_fetch_array($left_customer_result)) { echo $r['left_house_number'].' =lhn2'; /* See if there is any customer if not display blank row */ echo $left_customer_result_count.' = count '; if ($left_customer_result_count < 1) { echo $r['left_house_number'].' =lhn3'; echo '<span class="delivery_nothing">'.$r['left_house_number'].' </span> 1<span class="delivery_nothing">'.$r['left_house_street'].' '; } else { /* Have a customer, now check to see if they are supposed to get something */ if ($lrow['status'] != "AC" && $lrow['status'] != "VH") { /* Customer is stopped or on vacation so show house number and street not bolded */ echo '<span class="delivery_nothing">'.$r['left_house_number'].'</span>2<span class="delivery_nothing">'.$r['left_house_street']; echo $r['left_house_number'].' =lhn4'; } else { /* Now check for correct delivery day and return data */ if (Show_Product($lrow['product']) == '1') { echo $r['left_house_number'].' =lhn5'; echo '<span class="delivery_bold">'.$lrow['house_number'].'</span><span class="delivery_bold">'.$lrow['placement'].'</span><span class="delivery_bold">'.$lrow['street'].'</span>'; echo Product_Formater($lrow['product']); } I have tried... if ($left_customer_result_count < 1) { if ($left_customer_result_count == 0) { if ($left_customer_result_count == '') { if ($left_customer_result_count === 0) { And I can't get it to work. the count "test echo" is either blank or 1 If I echo the sql statement with values I know aren't in the db and paste it into phpmyadmin: SELECT * FROM customer WHERE house_number = '3333' AND street = 'Chili Avenue' AND route_number = '68-24-630' I get: "MySQL returned an empty result set" And if I change it to something that is in the db: SELECT * FROM customer WHERE house_number = '3019' AND street = 'Chili Avenue' AND route_number = '68-24-630' I get: "Showing rows 0 - 0 (1 total, Query took 0.0012 sec)" So what do I have to do to get this to work right? What does it actually output when there are no results returned? thanks, Hi i would like to know what is the best way to check if a textarea or an input box is empty. Is the empty function effective? I see some of the fields in mysql show NULL and some are just empty, wonder what is the difference, is empty field still NULL? Can anyone tell me the best way to handle empty search field on a mysql Query? The query below if $name is left blank but the other fields are filled it shows no results, currently i use if.... else.... but that means i have a lot of code replicated, is there a better way? $sql = "SELECT private.username, se.age, se.ro, se.suc, se.bu, se.fu, com.in, com.ol, se.di, se.bo, se.uin FROM Reg_Profile_public AS se INNER JOIN Reg_Profile_Private AS private USING (uin) INNER JOIN Reg_Profile_public_Com AS com USING (uin) WHERE se.age BETWEEN '$low' AND '$high' AND se.ro=''$name"; Hey guys, Really dumb question, but I want to check if a bunch of variables are all not empty. Then, if they aren't, I want to execute a mySQL query. Right now I have this which I know is wrong because it doesn't work the right way: Code: [Select] if($album != null || $artist != null || $year != null || $genre != null) { // stuff here... } Obviously I want all of those variables to be checked if they are empty or not. I did a quick Google and found that checking if the variables are null wouldn't be the correct way of solving this situation because an "empty string" is still not null? Anyway, any help would be appreciated. I'm pretty sure it's really simple :p. Code: [Select] Array ( [Comment] => Array ( [post_id] => 1 [name] => cc [email] => [body] => spam ) ) How can i check if email is empty or not? Is there any php built in function? Should i use foreach? i am trying to check if the array element (which would be a file) is null or not. when i run it, uploading one file, it says "Please select some files to upload first!" X 3. what am i doing wrong? my code: http://pastebin.com/m0k3fEd2 Having a bit of a problem with the code below, I am trying to get it the print the html code if the MySql field is not empty but its not working. Any ideas guy? thanks <!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>Untitled Document</title> </head> <body> <?php $uincookie = $_COOKIE["uin"]; require("./include/mysqldb.php"); $con = mysql_connect("$dbhost","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$dbame", $con); $result = mysql_query("SELECT * FROM Reg_Profile_images WHERE uin ='$uincookie'"); $i=1; while($rows = mysql_fetch_array($result)){ if (isset($row[image_zero])) { print "<p> </p> <table width=\"0\" border=\"0\"> <tr> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form3\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button3\" id=\"button3\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form4\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button3\" id=\"button4\" value=\"Make Primary\" /> </div> </label> </form></td> </tr> </table></td>\n"; } if (isset($row[image_one])) { print "<td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form5\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button4\" id=\"button5\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form6\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button4\" id=\"button6\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_two])) { print " </tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form7\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button5\" id=\"button7\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form8\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button5\" id=\"button8\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_three])) { print " </tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form9\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button6\" id=\"button9\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form10\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button6\" id=\"button10\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_four])) { print " </tr> </table></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> <p> </p> <table width=\"0\" border=\"0\"> <tr> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form2\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button2\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_five])) { print " </tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form11\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button11\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form12\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button12\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_six])) { print "</tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form13\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button13\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form14\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button14\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_seven])) { print " </tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form15\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button15\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form16\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button\" id=\"button16\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_eight])) { print " </tr> </table></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> <p> </p> <table width=\"0\" border=\"0\"> <tr> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form17\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button17\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form18\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button18\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_nine])) { print "</tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form19\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button19\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form20\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button20\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_ten])) { print "</tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form21\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button21\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form22\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button22\" value=\"Make Primary\" /> </div> </label> </form></td>\n"; } if (isset($row[image_eleven])) { print "</tr> </table></td> <td><table width=\"112\" height=\"129\" border=\"0\"> <tr> <td><img src=\"37658_1324208185514_1240161074_30749958_5597262_n.jpg\" alt=\"\" width=\"156\" height=\"166\" /></td> </tr> <tr> <td><form id=\"form23\" name=\"form1\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button23\" value=\"Delete Picture\" /> </div> </label> </form></td> </tr> <tr> <td><form id=\"form24\" name=\"form2\" method=\"post\" action=\"\"> <label> <div align=\"center\"> <input type=\"submit\" name=\"button2\" id=\"button24\" value=\"Make Primary\" /> </div> </label> </form></td> </tr> </table></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr>\n"; } //if($i %4 == 0) { echo '</tr><tr>'; } // this will create the line separator by inserting a row when the $i is dividable by 4 } ?> </table> <p> </p> <p> </p> </body> </html> hi all i have a problem here, Iv got a form that uploads images to a folder and updates the db with the name of that image, that work ok but if one of the upload field are left blank then the script updates the db with empty values how can i get it to only update the db with only submitted form field data???? here is the form Code: [Select] <?php if (isset($_GET['id'])) { $id = $_GET['id']; } ?> <form action="ud_image.php?id=<? echo "$id"?>" method="post" enctype="multipart/form-data" name="form1" id="form1"> <table class="udp"> <tr> <th>Thumbnail:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 1:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 2:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 3:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <th>Image 4:</th> <td><input type="hidden" name="MAX_FILE_SIZE" value="1029120" /> <input name="ufile[]" type="file" id="ufile[]" size="50" /><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </form> and here is the processing page <?php include("protect/password_protect.php"); error_reporting(E_ALL); include ("../includes/db_config.php"); $con = mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $path1= "../thumbnails/".$_FILES['ufile']['name'][0]; $path2= "../images/".$_FILES['ufile']['name'][1]; $path3= "../images/".$_FILES['ufile']['name'][2]; $path4= "../images/".$_FILES['ufile']['name'][3]; $path5= "../images/".$_FILES['ufile']['name'][4]; //copy file to where you want to store file copy($_FILES['ufile']['tmp_name'][0], $path1); copy($_FILES['ufile']['tmp_name'][1], $path2); copy($_FILES['ufile']['tmp_name'][2], $path3); copy($_FILES['ufile']['tmp_name'][3], $path4); copy($_FILES['ufile']['tmp_name'][4], $path5); ?> <html> <head> <title>Update Project Images</title> <link rel="stylesheet" type="text/css" href="../../project/backend/style.css" /> </head> <body> <table class="udip"> <tr> <th><? echo "<img src=\"$path1\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path2\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path3\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path4\" width=\"150\" height=\"150\">";?></th> <th><? echo "<img src=\"$path5\" width=\"150\" height=\"150\">";?></th> </tr> <tr> <td><? echo "File Name :".$_FILES['ufile']['name'][0]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][1]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][2]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][3]."<BR/>";?></td> <td><? echo "File Name :".$_FILES['ufile']['name'][4]."<BR/>";?></td> </tr> <tr> <td><?echo "File Size :".$_FILES['ufile']['size'][0]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][1]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][2]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][3]."<BR/>";?></td> <td><?echo "File Size :".$_FILES['ufile']['size'][4]."<BR/>";?></td> </tr> <tr> <td><? echo "File Type :".$_FILES['ufile']['type'][0]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][1]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][2]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][3]."<BR/>";?></td> <td><? echo "File Type :".$_FILES['ufile']['type'][4]."<BR/>";?></td> </tr> </table> </body> </html> <? $filesize1=$_FILES['ufile']['size'][0]; $filesize2=$_FILES['ufile']['size'][1]; $filesize3=$_FILES['ufile']['size'][2]; $filesize4=$_FILES['ufile']['size'][3]; $filesize5=$_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 != 0) { echo "We have recieved your files<p>"; } else { echo "Error in you images check and try again Database has been updated to blank images so no images will be shown on details page."; } $query = "UPDATE $db_table SET thumbnail = '".$_FILES['ufile']['name'][0]."', image1 = '".$_FILES['ufile']['name'][1]."', image2 = '".$_FILES['ufile']['name'][2]."', image3 = '".$_FILES['ufile']['name'][3]."', image4 = '".$_FILES['ufile']['name'][4]."' WHERE id = '".$_GET['id']."'"; if (!mysql_query($query,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> |