Jump to content

oraya

Members
  • Posts

    57
  • Joined

  • Last visited

About oraya

  • Birthday 05/15/1968

Profile Information

  • Gender
    Female
  • Location
    Cornwall, England
  • Interests
    Music (playing and listening to), Walking, Photography, Art, Reading, All things outdoors, Karate (to keep fit), and above all else my daughter.

oraya's Achievements

Member

Member (2/5)

0

Reputation

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