Jump to content


  • Posts

  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

kenoli's Achievements

Regular Member

Regular Member (3/5)




Community Answers

  1. OMG, it's just too early in the morning. Thanks. --Kenoli
  2. I have defined my database connection data as constants in a separate file for security reasons. How can I simply access the data stored in those constants. I have to call the file to get the value of the constants. If I inadvertently call the file twice in a script using an include or require statement, I get an error that I am trying to define the constants again. Can I somehow just call the constants without including the file where they are defined? --Kenoli
  3. I am getting the following error message: Fatal error: Uncaught Error: Array callback must have exactly two elements in /Users/studio/Sites/BannerProject/b-as/tio-new/__classes/person_form_edit_initial.php:14 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/tio-new/index.php(78): require() #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/tio-new/__classes/person_form_edit_initial.php on line 14 for a line in my code that only has the following code: $person_id = $_SESSION('person_id'); This is a simple array assignment. Where is the "two elements" requirement? I"m confused by the "require() #1 {main}" comment in the message. If it refers to a require call in the index.php file, there are also no functions in that file or a file it requires that require two elements. --Kenoli
  4. Great, thanks. That should do it. I couldn't understand the php.net explanation. --Kenoli
  5. I'm trying to do this with the code below. I get an error because explode thinks I'm just sending it one argument since the string is held by an array element. If I can get the array from the explode function I can insure it into the first and last name fields in my table. Any suggestions? --Kenoli require '__classes/Db.php'; $sql = "SELECT name FROM tbl_persons"; $stmt = $pdo->query($sql); $row = $stmt->fetchall(PDO::FETCH_ASSOC); foreach ($row as $name) { $names = explode($name['name']); }
  6. Actually, I figured it out. Thanks, --Kenoli
  7. I'm not sure how to implement this. When I try, it just pulls out one record and inserts it in the new table. I have 227 rows I want it to do this to. Not sure how to construct a statement to do this. I was doing it with prepared statements using "?" placeholders as above and thought it should work, but it doesn't. I runs, throws no errors but inserts nothing into the table. --Kenoli
  8. Stuck again on simple code. I am trying to insert some fields extracted from one table into another. I'm using code that worked elsewhere. The SQL statement flies, the script runs, the input array is printed back I get an echo back from the end of the script but nothing is added to the table. Even aded an echo print_r in the conditional and I know the data is getting to the execute command. The script follows with a sample of the input array. I have attached am image of the table I am trying to insert the data into. --Kenoli The script: <?php require '__classes/DB.php'; $sql = "SELECT name, table_id, image_name, description, medium FROM tbl_person_data "; $stmt = $pdo->query($sql); $array1 = $stmt->fetchall(PDO::FETCH_ASSOC); $stmt = $pdo->prepare("INSERT INTO Images (name, person_id, filename, description, medium) VALUES (?,?,?,?,?)"); //$pdo->beginTransaction(); foreach ($array1 as $row) { $stmt->execute($row); } echo "<pre>"; print_r ($row); echo "</pre>"; echo '<h4>Got to end of file</h4>'; ?> $array1: The input array [0] => Array ( [name] => Carol Lettko [table_id] => 21 [image_name] => Carol_Lettko-DSC_3022.jpg [description] => Baby Herons/Brickyard [medium] => photo ) [1] => Array ( [name] => [table_id] => 22 [image_name] => Carol_Lettko-DSC_0164.JPG [description] => Heron/Brickyard [medium] => photo ) [2] => Array ( [name] => [table_id] => 23 [image_name] => Carol_Lettko-IMG_5723.jpg [description] => Kayaker/Brickyard [medium] => photo )
  9. Thanks. That makes sense. I also changed "select" as I thought that might be a problem and that issue is now gone. I had to fix a couple of other errors that I figured out and it worked! --Kenoli
  10. PS -- This is a sample of the execute array as print_r displays it. It looks right to me: Array ( [0] => Array ( [0] => 1 [1] => FALSE [2] => Carol Lettko [3] => [4] => [5] => TRUE [6] => FALSE [7] => Carol_Lettko-DSC_3022.jpg [8] => Baby Herons/Brickyard [9] => photo [10] => [11] => [12] => ) [1] => Array ( [0] => [1] => [2] => [3] => 925-285-0320 [4] => cjl164@aol.com [5] => [6] => [7] => Carol_Lettko-DSC_0164.JPG [8] => Heron/Brickyard [9] => photo [10] => [11] => [12] => )
  11. I'm sorry to be back so soon, but I'm up against another mystery. I'm using the code below to enter a bunch of css data from a spreadsheet into a mysql table. I think the data file is OK. The array created by the script checks out with print_r. (There are many more records than shown. I truncated it to save space.) The problem is that I get this error regarding my sql statement, not the data or anything else: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'check, name, phone, email, entry_fee, print_fee, image_name, description, med...' at line 1 in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php:242 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php(242): PDO->prepare('INSERT INTO tbl...') #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/_test_site/csv_to_array.php on line 242 I've typed it in a dozen times to make sure there are no errors and keep getting the same error. I tried running a test file and gradually increasing the number of placeholders and at some point I always end up getting the same error, I can delete the most recent addition and it works again. Then I can add another placeholder exactly as before and it works the second time. It feels like a ghost in the machine. Any idea what I am doing wrong? An I typing something I don't see? <?php require '__classes/Db.php'; $csvData = '1,FALSE,Carol Lettko,,,TRUE,FALSE,Carol_Lettko-DSC_3022.jpg,Baby Herons/Brickyard,photo,,, ,,,925-285-0320,cjl164@aol.com,,,Carol_Lettko-DSC_0164.JPG,Heron/Brickyard,photo,,, ,,,,,,,Carol_Lettko-IMG_5723.jpg,Kayaker/Brickyard,photo,,, ,,,,,,,,,,,, 2,FALSE,Louise Williams,,,TRUE,FALSE,Louise_Williams-BirdsOfAFeatherAOPR.jpg,Alligator with Words,Book Excerpt,,, ,,,510-232-9547,lkw@louisekwilliams.com,,,Louise_Williams-Hope-TheFairyChickenAOPR.jpg,Hope The Fairy Chicken,,,, ,,,The d exatrfrfvct/.*tygrvurr,,,,,,,,, ,,,,,,,,,,,, 3,TRUE,Dorothy Leeland,,lelanddorothy@gmail.com,TRUE,FALSE,DJ_Lee-bridge at dusk 700px width.jpg,Bridge,photo,,, ,,,,,,,DJ_Lee-friends 700px width.jpg,Friends,photo,,, ,,,,,,,DJ_Lee-hybiscus 700 px wide.jpg,Hibiscus,photo,,, ,,,,,,,,,,,, 4,FALSE,Rita Gardner,,,TRUE,FALSE,Rita_Gardner-Explosion - Gardner photo.JPG,Explosion,photo,,, ,,,,tropicrita@msn.com,,,Rita_Gardner-Ferry Point tables and chair - Gardner.JPG,Ferry Point Tables,photo,, , ,,,,,,,Rita_Gardner-Forks - Gardner photo.JPG,Forks,photo,,, ,,,,,,,,,,,, '; $lines = explode(PHP_EOL, $csvData); $array1 = array(); foreach ($lines as $line) { $array1[] = str_getcsv($line); } $stmt = $pdo->prepare("INSERT INTO tbl_person_data (number, check, name, phone, email, entry_fee, print_fee, image_name, description, medium, select, orient, site) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"); foreach ($array1 as $row) { $stmt->execute('$row'); } echo '<pre>'; print_r($array1); echo '</pre>'; ?>
  12. It works! I guess html doesn't like quotes in array elements. Hooray. Many thanks, I guess we're good to go. Sorry for how long it took. I appreciate your persistence. --Kenoli
  13. PPS -- Actually, I just now got both errors when I ran it with the conditional. The fact that it repeated the error three times as indicated above would indicate that the fatal error didn't occur that time. When I just ran it, it did. The errors returned are inconsistent. Here are the two errors: Warning: Undefined array key "title" in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php on line 71 (on the conditional line) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php:72 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php(72): PDOStatement->execute(Array) #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php on line 72 (on the "execute" line)
  14. PS -- Regarding the first error, there is an array with the key "title" that has content in the array referred to in the "if" conditional.
  15. I re-typed everything I had copied and pasted having had the same thoughts you had. It did get rid of an earlier issue but it still fails. The errors are described below. I am including my form code below as you requested. I was not sure exactly how to set it up but the way I did gave me a POST array I could work with. I get the following error when I run the script with the conditional as I go it from this discussion. Line 71 is if ($title_elements['title'] != ''). Warning: Undefined array key "title" in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php on line 71 Warning: Undefined array key "title" in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php on line 71 Warning: Undefined array key "title" in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php on line 71 I get this error when I run it without the conditional. Line 72 is $stmt->execute($title_elements); Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php:72 Stack trace: #0 /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php(72): PDOStatement->execute(Array) #1 {main} thrown in /Users/studio/Sites/BannerProject/b-as/_test_site/__classes/upload_images.php on line 72 <!DOCTYPE HTML> <html> <head> <title>Image Input Form</title> <LINK REL=StyleSheet HREF="../css/css-form_new.css" TYPE="text/css" MEDIA=screen> </head> <body> <div class="container"> <div class="sectionHeading">Submit Images to Taking it Outdoors</div> <form action="../__classes/upload_images.php" method = "POST" enctype = "multipart/form-data"> <input type="hidden" id="custId" name="person_id" value="<?php echo $_POST['person_id'];?>"> <!-- Start Artwork --> <h4>Upload up to three files in JPG, JPEG, PNG or TIF(F) format.</h4> <strong>File size:</strong> We recommend at least a <strong>2MB</strong> file and no larger than a <strong>20MB</strong> file. Take into account the speed of your internet connection. Large files can take a long time to uplaod if you have a slow connection. <p><strong>Larger Files:</strong> For very high resolution larger files (<strong>>100MB</strong>) we recommend using <a href="wetransfer.com">wetransfer.com</a>, a free file transfer service for files up to <strong>2 GB</strong>.</p> <div class="fileUpload" >Image 1:</div> <label for="title1"><span>Artwork Title </span><input type="text" class="input-field" name="1['title']" value="" /></label> <label for="medium1"><span>Medium<span class="required">*</span></span><input type="text" class="input-field" name="1['medium']" value="" /></label> <label for="image1"><span>Image File 1</span><input type="file" name="image1" ></label></span></label> <div class="fileUpload" >Image 2:</div> <label for="title2"><span>Artwork Title </span><input type="text" class="input-field" name="2['title']" value="" /></label> <label for="medium2"><span>Medium<span class="required">*</span></span><input type="text" class="input-field" name="2['medium']" value="" /></label> <label for="image2"><span>Image File 2</span><input type="file" name="image2"></label></span> <div class="fileUpload" >Image 3:</div> <label for="title3"><span>Artwork Title </span><input type="text" class="input-field" name="3['title']" value="" /></label> <label for="medium3"><span>Medium<span class="required">*</span></span><input type="text" class="input-field" name="3['medium']" value="" /></label> <label for="image3"><span>Image File 3</span><input type="file" name="image3"></label></span> </div> <!-- End Artwork --> <p><input type = "submit" name="submit"/> <a href="http://localhost/Sites/BannerProject/b-as/_test_site/index.php"><input type = "button" class="blue" name="Cancel" value="Cancel"/></a></p> </form> </div> </body> </html>
  • 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.