Jump to content

oraya

Members
  • Posts

    57
  • Joined

  • Last visited

Everything posted by oraya

  1. Wonderful, thank you PFMaBiSmAd, I'll have a look at this later this evening, once I have finished cooking dinner. And I will no doubt be back to ask questions. Hope that is ok? As I am teaching myself Php & Mysql, usually for the few hours each night I get some me time and like to know and understand exactly how things work and what it's doing. I'm very grateful for the reply. Kindest wishes, Oraya
  2. Sorry just realised left off part of the error check // Check if the form has been submitted: if ( isset($_POST['submitted']) ) { $problem = FALSE; // No problems so far. // Check for each value... if (empty($_POST['title'])) { $problem = TRUE; $err1 = '<li>Title is required!</li>'; $errdisplay1 = 'error'; } if (empty($_POST['first_name'])) { $problem = TRUE; $err2 = '<li>First name is required!</li>'; $errdisplay2 = 'error'; } if (empty($_POST['last_name'])) { $problem = TRUE; $err3 = '<li>Last name is required!</li>'; $errdisplay3 = 'error'; } if (empty($_POST['email'])) { $problem = TRUE; $err4 = '<li>Email is required!</li>'; $errdisplay4 = 'error'; } if(isset($_POST['call']) && $_POST['phone'] == ''){ $problem = TRUE; $err5 = '<li>Please provide a valid phone number!</li>'; $errdisplay5 = 'error'; } if (empty($_POST['subject'])) { $problem = TRUE; $err6 = '<li>Subject is required!</li>'; $errdisplay6 = 'error'; } if (empty($_POST['comments'])) { $problem = TRUE; $err7 = '<li>Message is required!</li>'; $errdisplay7 = 'error'; } ///SETTING THE CAPTCHA VARIALBES TO CHECK $num1 = $_POST['num1']; $num2 = $_POST['num2']; $num3 = $_POST['num3']; $answer = $_POST['answer']; $add = $num1+$num2; $total = $add-$num3; if(empty($_POST['answer'])){ $problem = TRUE; $err8 = '<li>Please complete the Captcha!</li>'; $errdisplay8 = 'error'; }elseif($_POST['answer'] != $total){ $problem = TRUE; $err9 = '<li> Captcha was incorrect please try again!</li>'; $errdisplay8 = 'error'; } if (!$problem) { // IF THERE WEREN'T ANY PROBLEMS THEN WE PROCESS THE FORM. /*Rest of form process, such as if else statements to send mail to different recipients depending on the subject selected etc. Haven't included as not relivant.*/ } } /* FORM */
  3. At present I have if statements that check that form fields aren't left empty, The onese that can't be left empty are: Title First Name Last Name Email Subject Comments Captcha (a simply random number question I wrote) Then depending if the check box for "Do you wish us to call you back?" is checked, then Phone must not be left empty I will need to add some other security checks so that first and last name, can only have letters and perhaps one hyphen, a check for the email and the phone can only be numbers of a certain length ect, but I'm wondering if there is an easier way to out put the errors? Or indeed if there is an easier way to cover the whole of this checking with an array and foreach? // Check if the form has been submitted: if ( isset($_POST['submitted']) ) { $problem = FALSE; // No problems so far. // Check for each value... if (empty($_POST['title'])) { $problem = TRUE; $err1 = '<li>Title is required!</li>'; $errdisplay1 = 'error'; } if (empty($_POST['first_name'])) { $problem = TRUE; $err2 = '<li>First name is required!</li>'; $errdisplay2 = 'error'; } if (empty($_POST['last_name'])) { $problem = TRUE; $err3 = '<li>Last name is required!</li>'; $errdisplay3 = 'error'; } if (empty($_POST['email'])) { $problem = TRUE; $err4 = '<li>Email is required!</li>'; $errdisplay4 = 'error'; } if(isset($_POST['call']) && $_POST['phone'] == ''){ $problem = TRUE; $err5 = '<li>Please provide a valid phone number!</li>'; $errdisplay5 = 'error'; } if (empty($_POST['subject'])) { $problem = TRUE; $err6 = '<li>Subject is required!</li>'; $errdisplay6 = 'error'; } if (empty($_POST['comments'])) { $problem = TRUE; $err7 = '<li>Message is required!</li>'; $errdisplay7 = 'error'; } /*Rest of form process, such as if else statements to send mail to different recipients depending on the subject selected etc. Haven't included as not relivant.*/ } /* FORM */ I'm really new to Php so I'd be greatful of some feed back and maybe a pointer in the right direction so that I can do a little more research. Kind regards Oraya EDIT Oh I should point out the first $err# is the error message that is displayed, and the second $errdisplay# is what is placed into the class tag so that my css can outline the field in red. Hence the reason I'm hoping to find a way of out putting only two error messages for all, the first perhaps changing the name with an array!
  4. Ok this appeared to work but am I doing it correctly or is there an easier way of doing this? Also is there anything I should be adding for security? Sorry so many questions I know, it's just because I'm new and want to make sure I'm doing it correctly. Oraya include_once'inc/_config.php'; include_once'inc/_dbconnect.php'; $table = mysql_real_escape_string( $_POST["table"] ); $image_file = mysql_real_escape_string( $_POST["image_file"] ); $location = mysql_real_escape_string( $_POST["location"] ); $id = $_POST['id']; $delete_id = implode(",", $id); $query="SELECT image_file FROM $table WHERE id IN($delete_id)"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $image_file=mysql_result($result,$i,"image_file"); unlink($base_address . $location . $image_file); $i++; } $sql="DELETE FROM $table WHERE id IN ($delete_id)"; $result = mysql_query( $sql ) or die( mysql_error() ); // header("Location: index.php");
  5. I know how to write a select query I'm just not sure how to go about deleting multiple image files. Sorry maybe I didn't explain myself very well. Oraya PS I know how to unlink() one file, but I'm just not sure how to delete x amount.
  6. How can I unlink the images associated with the id's in the database? At the moment I use the following delete.php to delete multiple rows: include_once'inc/_dbconnect.php'; $table = mysql_real_escape_string( $_POST["table"] ); $id = $_POST['id']; $delete_id = implode(",", $id); $sql="DELETE FROM $table WHERE id IN ($delete_id)"; $result = mysql_query( $sql ) or die( mysql_error() ); // header("Location: index.php"); In the database it also stores the image location and the file name, so before the row is deleted I'd like to somehow pull the associated image_file name and the location then create a loop (I presume that's what I'd use) to unlink the images, but I'm not sure how to do it. Could someone explain how I might do it? Many thanks in advance, Oraya
  7. I thought that was what was happening, so how should I go about altering my code to stop the error?
  8. I'm sorry really new to php, I thought I had. If not would you mind giving me an example of how to write it. Would it be just: $result=mysql_error(); Oraya
  9. Hi could someone tell me what I'm doing wrong. I've been trying to figure it out for a couple hours. I am trying to set up a page (Floral Catalogue) where the user can delete multiple entries in the database. The form has a checkbox that is used to delete the rows in the database. It works fine and deletes the items, but after the delete I get this error Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 38 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 39 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 40 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 41 Warning: mysql_result() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.9\www\testfolder\index-two.php on line 42 It relates to where I set the variables for the data pulled in from the database. What am I doing wrong? Any help would be so gratefully received, as it's driving me nuts trying to figure out what I'm doing wrong. I know what the error means, well I'm pretty sure I do. It means that you have to have the database connection first before you set the variables. Or am I wrong? Anyway if anyone could help as I said I'd be so grateful . Oraya <?php $table = 'floral_catalogue'; //TABLE TO OPEN $title = 'Testing the multi-delete form.'; //PAGE TITLE include_once'_layout-header.php'; include_once'_dbconnect.php'; $query="SELECT * FROM $table"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <br /> <br /> <div class="title"><?php echo $title; ?></div> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <!-- HIDDEN FIELDS DO NOT EDIT --> <input type="hidden" name="table" value="<?php echo $table; ?>" /> <!-- END OF HIDDEN FIELDS --> <table> <tr> <td style="padding-left: 10px;">File:</td> <td style="padding-left: 10px;">Name:</td> <td style="padding-left: 10px;">Description</td> <td style="padding-left: 10px;">Delete:</td> </tr> <?php $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $location=mysql_result($result,$i,"location"); $name=mysql_result($result,$i,"name"); $description=mysql_result($result,$i,"description"); $image_file=mysql_result($result,$i,"image_file"); if(!isset($_POST['submitted'])){ ?> <tr> <td style="width: 75px; height: 75px; background-image: url(<?php echo $location . $image_file ?>); background-size:75px 75px;"> </td> <td style="width: 150px; height: 50px; padding-left: 10px;"> <?php echo $name; ?> </td> <td style="width: 390px; height: 50px; padding: 10px;"> <?php echo $description; ?> </td> <td style="width: 75px; height: 75px; vertical-align: middle; text-align: center; background-color: #F6F4F2;"> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $id; ?>" /> </td> </tr> <?php }else{ include_once'_dbconnect.php'; $table = mysql_real_escape_string( $_POST["table"] ); $del_checkbox = $_POST['checkbox']; $del_items = implode(",", $del_checkbox); $sql="DELETE FROM $table WHERE id IN ($del_items)"; $result = mysql_query( $sql ) or die( mysql_error() ); } $i++; } // END OF THE LOOP ?> <input type="submit" name="submitted" value="Delete Selected Items" class="button" /> <div class="clearer"></div> </table> <input type="submit" name="submitted" value="Delete Selected Items" class="button" /> </form> <?php mysql_close(); include_once'_layout-footer.php'; ?>
  10. Brilliant works like a charm, thank you so much for your help! I'm very grateful.. Oraya
  11. Oh good call, duh why didn't I think of that? I'll give that a go, thank you! Been at it to long today... I think my brain has gong into melt down. Thank you again, Oraya
  12. I'm thinking I would do it with a foreach in an array but can't figure out how to do it.. have googled for an answer and tried many things but can't get to work.. If someone is able to point me in the right direction I'd be very grateful. Oraya
  13. Is there a way to pull the data from the database to populate the html table going across and then down to the next row and across? I'd like to place all the fields from the database in one td. Like so: CONTACT DETAILS: Title | Title | And so forth there are three columns so another after this. 1st line address | 1st line of address | 2nd line address | 2nd line of address | Town | Town | Post code | Post code | The row then from the mysl is title, 1st_line, 2nd_line, Town, Postcode. I can't figure out how I can populate the html fields across and then down onto the next row. I hope this makes sense! Oraya
  14. Ok just to follow this up, for anyone else that is looking for something similar, I've figured it out. This is what I did, I placed a check box on the update form named replace. I then used an if statement to see if the checkbox is set first in the update php, if it is then it deletes the file and then proceeds with the upload of the new file. UPDATE FORM <?php $dbhost = 'localhost'; $username=""; $password=""; $database="test"; mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Retrieve data from database $query="SELECT * FROM images"; $result=mysql_query($query); $num=mysql_numrows($result); $table = 'images'; $title = "TESTING FILE DELETE"; $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $image=mysql_result($result,$i,"image"); $location=mysql_result($result,$i,"location"); $position=mysql_result($result,$i,"position"); $content=mysql_result($result,$i,"content"); ?> <form enctype="multipart/form-data" action="insert.php" method="post"> <fieldset class="form_fieldset"> <legend> <?php echo $title;?> </legend> <input type="text" name="id" value="<?php echo $id;?>" size="1" /> <input type="text" name="location" value="images/" /> <input type="text" name="table" value="<?php echo $table;?>" /> <div><label>Image:</label><input type="text" name="image" class="image_input" value="<?php echo $image;?>" /></div> <div><label>Select File:</label><input name="uploadedfile" type="file" class="form_input" /></div> <div><label>Do you wish to replace the image with new one?: </label><input type="checkbox" name="replace" value="Yes" /></div> <div><label>Select Image Position:</label><select class="select" size="1" name="position"> <option value="left">Left</option> <option value="right">Right</option> </select></div> <br /> <div><label>Content:</label><textarea wrap="physical" cols="100" rows="20" name="content" id="form_textarea"><?php echo $content;?></textarea></div> <br /> <input type="submit" value=" Update Content " class="form_submit"/> </fieldset> </form> <?php $i++; } mysql_close() ?> UPDATE SCRIPT <?php $host = "localhost"; $user = ""; $pass = ""; $database = "test"; $replace = mysql_real_escape_string( $_POST["replace"] ); $image = mysql_real_escape_string( $_POST["image"] ); $location = mysql_real_escape_string( $_POST["location"] ); $target_path = $location ; if (isset($_POST['replace'])){ unlink($location . $image); } else { echo 'delete file did not work!'; } $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $host = "localhost"; $user = "penfal"; $pass = "bluenote"; $database = "test"; $conn = mysql_connect($host, $user, $pass) or die( mysql_error() ); mysql_select_db($database) or die( mysql_error() ); $id = mysql_real_escape_string( $_POST["id"] ); $table = mysql_real_escape_string( $_POST["table"] ); $image = mysql_real_escape_string( $_POST["image"] ); $location = mysql_real_escape_string( $_POST["location"] ); $position = mysql_real_escape_string( $_POST["position"] ); $content = mysql_real_escape_string( $_POST["content"] ); $image = basename( $_FILES['uploadedfile']['name'] ); $sql="UPDATE $table SET location='$location', image='$image', position='$position', content='$content' WHERE id='$id'"; $result = mysql_query( $sql ) or die( mysql_error() ); mysql_close($conn); if($result) { echo"it worked!!"; }}else{ echo "ERROR"; } ?>
  15. I thought about that, but not sure how to go about it. Would it be ok if I came back in a little while with some more questions? I'm just setting up a test site and test database for this purpose. Oraya.
  16. Could someone show me how I may edit my update script to delete the old image and replace it with the new image uploaded? So if they decide to change the image by uploading a new one, the old image file will be deleted off the server at the same time. For the life of me I can't figure it out. I'm not sure how to write the if statement. Oraya Submission Form: <form action="includes/update.php" method="post"> <fieldset class="form_fieldset"> <legend> Update - <?php echo $title;?> </legend> <input type="hidden" name="id" value="<?php echo $id;?>" /> <input type="hidden" name="redirect" value="welcome.php" /> <input type="hidden" name="location" value="<?php echo $location; ?>" /> <input type="hidden" name="table" value="<?php echo $table;?>" /> <input type="hidden" name="message" value="Welcome Message Updated Successfully!!" /> <input type="hidden" name="redirect" value="welcome.php" /> <label>Select File:</label><input name="uploadedfile" type="file" class="form_input" /> <label>Select Image Position:</label><select class="select" size="1" name="position"> <option value="left">Left</option> <option value="right">Right</option> </select> <label>Image:</label><input type="text" class="image_input" value="<?php echo $image;?>" /> <div><label>Subtitle:</label><input class="input" type="text" name="sub_title" value="<?php echo $sub_title;?>" /></div> <label>Content:</label> <br /> <textarea wrap="physical" id="form_textarea" class="widgEditor nothing"><?php echo $content;?></textarea> <br /> <input type="submit" value=" Update Content " class="form_submit"/> </fieldset> </form> The Update Script: <?php $location = mysql_real_escape_string( $_POST["location"] ); $target_path = $location; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $host = "localhost"; $user = "myusername"; $pass = "mypassword"; $database = "mydatabase"; $conn = mysql_connect($host, $user, $pass) or die( mysql_error() ); mysql_select_db($database) or die( mysql_error() ); $table = mysql_real_escape_string( $_POST["table"] ); $message = mysql_real_escape_string( $_POST["message"] ); $redirect =mysql_real_escape_string($_POST['redirect'] ); $position = mysql_real_escape_string( $_POST["position"] ); $sub_title = mysql_real_escape_string( $_POST["sub_title"] ); $content = mysql_real_escape_string( $_POST["content"] ); $image = basename( $_FILES['uploadedfile']['name'] ); $sql="INSERT INTO $table SET location=$location, image=$image, position=$position, sub_title='$sub_title', content='$content'"; $result = mysql_query( $sql ) or die( mysql_error() ); if($result) { header("Location: ../successful.php?message=$message&redirect=$redirect"); }}else{ echo"there was a problem!"; } mysql_close($conn); ?>
  17. Damn discovered why lol.. had quotes around it. Thank you for your help. Oraya
  18. Hi thorpe. thank you for the reply. How would I add a second variable. The first is the directory of the image and the second is the image name. I tried it this way and it doesn't seem to be passing the image and directory to it. I also tried it with a comma still no go. list($width, $height, $type, $attr) = getimagesize($location . $image);
  19. Is it possible to place to variables into a getimage? list($width, $height, $type, $attr) = getimagesize("image_name.jpg"); So in stead of the image_name.jpg. I'd have something like this list($width, $height, $type, $attr) = getimagesize("$location, $image"); I've googled to find an answer but only found info on getimagesize and not on this question. Any help would be gratefully received, thank you in advane Oray
  20. Wonderful, have booked marked the link for later reading. You have now turned the long day into a happy ending, so thank you for that. I do like to try and figure things out for myself, as I have found that if it takes me a while to find a solution it tends to stick more in my memory and so aids my learning. But no amount of googling sticky forms gave me the answer. You are gent, so thank you kindly. I can now close my laptop having accomplished my goals for today, create a contact form with several combo's doing different things through if statements etc, write a simple captcha to lessen future spam, (yuck almost as bad as the tinned variety lol) and the last goal was to find a solution to the question asked. I can now get some shut eye now. Thank you once again! Have a great Thursday Jc. Oraya
  21. Ok ignore that... lol I've just re-read you comment. No it wont because it's not set so it wont throw and error. Forgive me, long hours = tiredness and also new to php. Thank you so much for you help that's brilliant. One more question if you wouldn't mind what does the question mark do? Oraya
  22. And how would that pan out if when the form was re-displayed and the user removed the check and re-submitted, would that mean I'd still get the error Jc?
  23. I noticed that also, but just assumed he was passing the variable from another page.
  24. where are you getting the id from I don't see it in the form?
  25. I have a simple captcha just to lessen the spam made up of three rand() numbers. num1 and num2 are added together then num3 is subtracted from the add to give the total. Now this is my question. If someone gets the sum wrong and the form is re-displayed with the sticky fields, I can remove the contents and change the values of the inputs and re-sumbit with the correct sum captcha submitted, but if someone takes the check out of the checkbox or puts one in then it throws up the error Notice: Undefined index: <input type="checkbox" name="call" value="Yes" <?php if($_POST['call'] == 'Yes') echo "checked" ?> /> Do you wish to receive a call from us? Chances are 99% of the users wont change any or the inputs. But I'd like to cover myself for that 1% that may. Of those they will fall into two categories those that selected the wrong option on first submit and notice it during the catchpa re-display of the form, and those that have changed their minds on a certain option. Either way I want to make sure that I don't get the Undefined index error if they try to re-submit the form with the check taken out or one put in. So any help would be brilliant. I've tried so many things over the last couple of hours and can't find a solution. I like to try and figure it out myself as it helps me learn, but after a few hours now I'm still no further forward. So any help would be very gratefully received. If only two stop me from pulling my hair out, I don't think I'd look good bald lol.. Many thanks in advance for any help Oraya
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.