Jump to content

jodunno

Members
  • Posts

    293
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by jodunno

  1. it seems to me that you are copying and pasting code from this thread without trying to understand the code. for example, you have the following code in your file: $query = "SELECT * FROM convoy_part WHERE us_convoy=:get_id"; $stmt = $pdo->prepare($query); $start->execute(array(':getId' => $_GET['id'])); $result = $stmt->fetchALL(PDO::FETCH_ASSOC); you don't even notice the difference between :get_id and :getId. (the underscore naming convention, by the way, is just more useless bytes added to the file) once again, remove the following code block from your file: <?php include 'connection/sql1.php'; // Abrufen der ID für Teilnehmerknopf if (isset($_GET['id'])) { $user2 = mysqli_real_escape_string($conn , $_GET['id']); $query = "SELECT * FROM convoy_part WHERE id= '$user2' "; $run_query = mysqli_query($conn, $query) or die(mysqli_error($conn)) ; } ?> do you not notice that the aforementioned codeblock contains mysqli code? in your code you echo $convoy_kilometer but where is this data coming from? where do you set a variable named $convoy_kilometer? last time i mention a practice file. I recommend that you make a new blank php file specifically for learning pdo. use your current file as a basis. Actually, just start frsh from the html body tag with a proper pdo code block. simply echo results to see it working, then build the rest of your page. you have enough pdo ammo to clean up your document. the rest is up to you. let us know when you get it working...
  2. I strongly urge you to create a practice file. You have to integrate your code to the pdo format. You implemented pdo but you still have old mysqli statements left in the code which need to be removed. I wouldn't loop at all if you are only fetching all columns in one row. a loop is necessary if you need all columns from many rows. xampp is nice and easy to install. set up a simple database and create a php file to practice pdo. like so: database name: mytestdb table name: convoys columns: id, user_id, convoy_name, convoy_organizer $host = 'localhost'; $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $fake_id = 1; $connection = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); $query = 'SELECT convoy_name, convoy_organizer FROM convoys where id = :id'; $start = $connection->prepare($query); $start->execute(array(':id' => $fake_id)); $result = $start->fetch(); echo $result['convoy_name'] . '<br>' . $result['convoy_organizer']; Best wishes.
  3. his code is missing the closing bracket: $stmt->execute([':get_id' => $ _GET ['id']]); which is why i use array (so that brackets are easy to see): $start->execute(array(':getId' => $_GET['id'])); really, you should use a practice file and select names that are consistent. either $start, $s2, $stmt or some other name but mixing names even in this thread is confusing.
  4. so you just want the filename (optional extension) from a uri? <?php declare (strict_types = 1); $uri = 'http://my-site.com/gifts/images/my-image.jpg'; echo $uri . '<br>'; $ext = pathinfo($uri, PATHINFO_EXTENSION); $uri = pathinfo($uri, PATHINFO_FILENAME); echo 'filename is: ' . $uri . '<br>voila!<br>'; echo '<br>looking for extension?<br>'; echo 'filename and extension: ' . $uri . '.' . $ext; echo '<br>and once again, voila!'; exit; ?>
  5. you have the following code: <?php // Abrufen der ID für Teilnehmerknopf if (isset($_GET['id'])) { $user2 = mysqli_real_escape_string($conn , $_GET['id']); $query = "SELECT * FROM convoy_part WHERE id= '$user2' "; $run_query = mysqli_query($conn, $query) or die(mysqli_error($conn)) ; } ?> you should practice pdo in a new php file. write it out according to my example and examples on internet pages about pdo. when you see the expected results printed on the screen of your new php practice file, then you can begin integrating your webpage to the new pdo method of retrieving data from a db.
  6. Hello Endrick, please slow down and be certain that you are maintaining consistency in your variable names. you are using $s2 in place of $start. let's agree on names: $bdd, $query, $s2, $results. Then try the following code: <?php require('connection/db1.php'); // Abfragen der Daten z.B. für <?php echo $convoy_description; ... $bdd = new PDO("", ,); //fill in connection data and be sure that this data is available in db1.php $query = 'SELECT * FROM convoy_part WHERE user_convoy = :getID'; $s2 = $bdd->prepare($query); $s2->execute(array(':getID' => $_GET['id'])); //if you do not set fetch association in the attributes, then you must set it in your while loop while ($result = $s2->fetch(PDO::FETCH_ASSOC)) { $convoy_name = $result['convoy_name']; $convoy_veranstalter = $result['convoy_veranstalter']; $convoy_server = $result['convoy_server']; $convoy_date = $result['convoy_date']; $convoy_adddate = $result['convoy_adddate']; $convoy_language = $result['convoy_language']; $convoy_participants = $result['convoy_participants']; } ?>
  7. also, db1.php has insufficient data for making a connection. $bdd = new PDO('mysql:host=localhost;dbname=;charset=utf8', '', ''); let's pretend that your database is name 'mytestdb' and your database username is 'root' and your password is empty (default empty using xampp). $host = 'localhost'; $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $bdd = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); be sure to include host, database name, character set if you need it followed by the actual db username, password and attributes. as for your last post, have you tried the following approach? $result = $start->fetch(); $convoy_name = $result['convoy_name']; $convoy_veranstalter = $result['convoy_veranstalter']; $convoy_server = $result['convoy_server']; $convoy_date = $result['convoy_date']; $convoy_adddate = $result['convoy_adddate']; $convoy_language = $result['convoy_language']; $convoy_participants = $result['convoy_participants']; //you could also use closeCursor as a feel-good terminator $start=>closeCursor(); once you execute the fetch, then your data is available to you. Either set variables for each requested column or use loops.
  8. if you want to use $row instead of $result, then change the code. $result['convoy_cars'] will display the column data. Take the example pdo code that i have posted and make it work with your existing code. remember to use corresponding names of variables and arrays.
  9. Hello, i think that any community should be willing to facilitate migration from mysqli to pdo. Thus, i am stepping up to offer support. here is an example of the necessary code to conduct pdo business as usual. i use variables when executing queries but bindings can also be used. I use a variable to set necessary attributes. I've included association to make life easier. $host = 'localhost'; //localhost or 127.0.0.1 $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $connection = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); $qry = 'SELECT * FROM con where id = :user'; $start = $connection->prepare($qry); $start->execute(array(':user' => $user)); $result = $start->fetch(); I hope that this code helps you migrate successfully. Best wishes!
  10. whereever do you get loop through a db? StevenOliver mentioned manually entering input. furthermore, if you don't know how to pull selected data from a database, then you have some reading to do. I'm moving on from this nonevent. Anyway, manually selected inputs will work well with the quick solution that i've posted. Meantime, adding number_format will also handle dollars and cents. Best wishes.
  11. a hardcoded example versus php output is hardly a massive difference. exaggeration. The forum is not a code my php for me forum. The hardcoded example was posted by StevenOliver and used by me. Simply change the form to factor php output. <?php $products = array('3829' => '5.00','1444' => '12.00','9035' => '3.00'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $updatedProducts = array(); $skuQuantities = array(); $total = 0; foreach ($products as $sku => $price) { if (isset($_POST[$sku.'q']) && $_POST[$sku.'q'] > 1) { $skuQuantities[$sku] = $_POST[$sku.'q']; } if (isset($_POST[$sku]) && $_POST[$sku] !== $price) { $updatedProducts[$sku] = $_POST[$sku]; continue; } $updatedProducts[$sku] = $price; } foreach ($updatedProducts as $sku => $price) { if (array_key_exists($sku, $skuQuantities)) { for ($i=1; $i <= $skuQuantities[$sku]; $i++) { echo $sku . ': $' . $price . ' ' . '<br>'; $total += $price; } } else { echo $sku . ': $' . $price . '<br>'; $total += $price; } } echo 'Total: $' . $total . '.00'; unset($products); unset($updatedProducts); unset($skuQuantities); exit; } ?> <form name="form1" method="post"><?php foreach ($products as $sku => $price) { ?> <input type="text" name="<?php echo $sku; ?>" value="<?php echo $price; ?>"> <input type="number" name="<?php echo $sku . 'q'; ?>" min="1" value="1"><br><?php } ?> <input type="submit" class="no_class_its_the_90s_remember"> </form> updated code now shows a total price and accepts an unaltered price for display. try the code in xampp. the original problem is solved. Once again, macgyver's post does not solve the problem because it offers no solution for a duplicate entry. In addition, one should not blindly loop over POST data. Stop telling people to do this. Best wishes.
  12. Hello StevenOliver, i only have time to tinker with a quantity method but it should be helpful to you (i hope so.) The following code only handles changes to the price and factors quantity into the final output, ie, if you really want to print multiple items on the same receipt. Otherwise, you could just echo a quantity and use simple addition to reflect a sum price of quantities greater than 1. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $products = array('3829' => '5.00','1444' => '12.00','9035' => '3.00'); $updatedProducts = array(); $skuQuantities = array(); foreach ($products as $sku => $price) { if (isset($_POST[$sku]) && $_POST[$sku] !== $price) { if (isset($_POST[$sku.'q']) && $_POST[$sku.'q'] > 1) { $skuQuantities[$sku] = $_POST[$sku.'q']; } $updatedProducts[$sku] = $_POST[$sku]; continue; } $updatedProducts[$sku] = $price; } foreach ($updatedProducts as $sku => $price) { if (array_key_exists($sku, $skuQuantities)) { for ($i=1; $i <= $skuQuantities[$sku]; $i++) { echo $sku . ': ' . $price . ' ' . '<br>'; } } else { echo $sku . ': ' . $price . '<br>'; } } unset($products); unset($updatedProducts); exit; } ?> <form name="form1" method="post"> <input type="text" name="3829" value="5.00"> <input type="number" name="3829q" min="1" value="1"><br> <input type="text" name="1444" value="12.00"> <input type="number" name="1444q" min="1" value="2"><br> <input type="text" name="9035" value="3.00"> <input type="number" name="9035q" min="1" value="1"> <input type="submit" class="no_class_its_the_90s_remember"> </form> you should be able to fill a products array from your database based upon form submission or some other method. Then you could implement code like my example to work out quantities. I really don't have time to develop something further for you but it's a start. Best wishes.
  13. a problem still exists which hasn't been addressed: you have two text inputs with the same name in your example above (A1444, 12.00). The first occurrence of A1444 is considered as a duplicate. This is why you can only change the last occurrence. This is also why a quantity would be a better method. one sku, one price, quantity. furthermore, i don't recommend blindly looping over post data. I recommend looping over known data and checking isset post[known_data]. Imagine a form with a million inputs.
  14. personally, i am a visual learner. I can't see the code, so i can only offer solutions based upon the pseudocode. I think that you would be better off seeking duplicates and incrementing a quantity associated with the product sku. then you know that the customer has three of a particular item. price change will represent $5.00 x skuQuantity. edit: i see: you don't want a product * quantity receipt. So you want to list all three and the new price. In that case, why not loop through the prooducts for matches of the price change sku? then, you can change the price of all three.
  15. a variable can be used as a variable, hence, variable variable. However, $_POST[$sku] will return the value of the post, which is 5.99. I don't see a variable named 5.99 and neither does php. So ${$_POST[$sku]} is really supposed to represent $5.99. I am not sure but i don't think the full stop is a valid variable name anyway. Why not just compare post sku to price? <?php $sku = "123456"; $price = "5.99"; if (isset($_POST[$sku]) && $_POST[$sku] !== $price) { $price = $_POST[$sku]; echo '<br>' . $price; } ?> <form method="post"> <input type="text" name="<?php echo $sku; ?>" value="<?php echo $price; ?>"> <input type="submit"> </form>
  16. so back to the question: location.href has solved my problem. My page scrolls to the named anchor when it is loaded. Excellent. Thank you.
  17. Dear members, I have a self-inflicted problem but i do not know of a proper solution. My site is a subscription based members only website. Some pages are protected pages while others are low security accessible pages. This means that low-security pages only check the session for login. An example of low-security is a news article or press release. PHP on low-security pages just checks the session to see if the user is a logged in member. The low-security pages are accessed via standard hyperlinks with a constant address (e.g., place.ext/News). Protected pages, on the other hand, are hidden behind a post form which utilizes prg to send the request to the index page (place.ext). The requests are analyzed for tokens, timestamps, referrer, ip address etc. the user is checked in the database and the session data is compared to verify user login status etc. Such a design prevents me from using anchor names to jump to specific places in the page (place.ext#jumplink). I am trying to figure out a way to still use named anchors. I think that a session variable can be used to store the anchor name for jumping. Then i wonder if i could use javascript to actually make the jump? (document.location perhaps?) is there someway to use php for this task besides a session variable? has anyone done this before? i cannot think of a simple solution. Thabk you and Best Wishes.
  18. Hello benanamen, Thank you very much. I didn't know that i could do custom handling. I should probably read the php manual a little closer. My apologies for this lack of knowledge. Best wishes.
  19. Hello everyone, quick description of 'error handling' so that everyone understands the solution i am seeking. let php and the database handle the error is not an appropriate answer here. find out what i mean: using xampp, go to a login screen of your website, then turn off the database before submitting the login data. the connection will be attempted then fail. the browser will display its own error page which is white bg with a message. this is ridiculous. i made a custom handler that allows me to ignore this failure and show my own website with an error message. now how can i detect an error with a select or update statement? i am not a db designer, so i really don't know how to do it. what say i fetch filed['testmyerror'] and it doesn't exist or there is a problem. how do i write php code that is used to ignore this problem and display my own message. naturally i will log the error and/or log and send email to myself. anyone able to help? just a tip in the right direction? Thank you very much, i appreciate this forum and its members always.
  20. Hello again, I've tinkered with my hsv sorting algorithm and i'm happy with the results. so i guess that i am able to group the colors afterall. I am not sure if the natsort is scientifically accurate or not but the final palette looks very nice. I've attached a png image of the final palette. Any additional comments? Best wishes.
  21. so try to change the default style: border: none; outline: none; then specify a solid 2px gray border. input[type="password"], input[type="text"], textarea { background-color:#ffffff; font-weight:bold; color:#000000; border: none; outline: none; border: solid 2px gray; border-width: thin; border-radius: 20px; border-color:green; } input[type="input"]:focus, input[type="password"]:focus, input[type="text"]:focus, textarea:focus { background-color:#f4cd81; font-weight:bold; color:Blue; border-width: thick; border-radius: 20px; border-color:green; } meantime, input type="input"? please review input types. let us know how it goes...
  22. Hello again, i've decided to write an hsv converter using known formulas. i had to laugh because alot of proposed solutions are not correct. hsv is degrees percentage percentage and alot of code on the internet does not factor degrees for hue and the code is actually division by zero, which means the author is a mathematical idiot. i found a couple of examples actually implementing degrees. Anyway, i've tinkered with the code and i have it producing correct results as compared with the hsv values in my photoimpact 256color palette. it still isn't sorted by groups correctly. I'm not interested in solving the sorting problem when a world full of smarter people should be doing it. Anyway, i'll see if i can produce a 6-6-6, 6-8-5 method and move on. colors do not need anymore of my time. a simple hex palette is all that i need. if i wanted to group the colors it would be a manual color group flag before a sort. Have a great day.
  23. Hi StevenOliver, so you answer my question with a question. LOL. I know why i have a lenny face but i don't know why yours is missing :-) - just poking fun. hopefully you see it that way. anyway, i'm quite happy with a hexidecimal arranged palette. I have no intentions of organizing it via hsv. I think that adding hsv is simple enough. I've added some quick code to illustrate my point: <?php declare (strict_types = 1); $rgbhex = ['00','33','66','99','cc','ff']; $rgbdec = ['0','51','102','153','204','255']; $hexpalette = array(); $decpalette = array(); $palette = array(); $colors = 0; foreach ($rgbhex as $redhex) { foreach ($rgbhex as $greenhex) { foreach ($rgbhex as $bluehex) { $hexKey = $redhex . $greenhex . $bluehex; $decVal = hexdec($redhex) . ',' . hexdec($greenhex) . ',' . hexdec($bluehex); array_push($hexpalette, $hexKey); array_push($decpalette, $decVal); ++$colors; } } } echo 'there are ' . $colors . ' colors in this palette'; echo '<br><br>'; $palette = array_combine($hexpalette, $decpalette); unset($hexpalette); unset($decpalette); print_r($palette); foreach ($palette as $rgbVal) { list($r,$g,$b) = explode(',',$rgbVal); $r = ($r / 255); $g = ($g / 255); $b = ($b / 255); $cMax = max($r, $g, $b); $cMin = min($r, $g, $b); $delta = $cMax - $cMin; $hsV = $cMax; //et cetera... } exit; ?> one could just continue with the hsv conversion and saving it to a new hex key hsv value array for output to the screen. I think it should work. Anyway, i was just wondering if there is a mathematical way to represent the hex codes in a 6-6-6 fashion. so that maybe i could alter the code to support a 6-8-5 palette, which is also nice. besides the wonder of an alternate method, i was hoping for a method easier than three loops. Meantime, i am not really interested in using php to dynamically create a css file with headers. I just want to allow members to change my default bg color if they dislike it. I recommend that members use my bg photos but i offer a setting to turn them off and use colors instead. I'm just trying to be thoughtful but not behave like a serf. Thus, grouping colors seems to servant like to your every whim. I'm just not interested in anything more than a palette structured by hex codes. Best wishes to all and stay safe and healthy.
  24. Hello everyone, i use content security policy set at self for javascript and css. unsafe-inline is forbidden. However, i want to allow the background to be changed in tow ways: foto selection and color selection if photos are turned off. I have accomplished all of this but unsafe inline does not help my purpose. I need the color to be accessible via css file. Thus, input color cannot be used here unless i dynamically crete a css file based upon a selection. I don't want to do this, so i hardcoded the 216 colors into a css file which is only 6kb. perfect! now i need to loop through the color values to dynamically create the 216 color palette. I've never done this before so i had to think about it and try to recognize a pattern. I noticed that red is first follwed by green and blue. so green and blue should be together inside a red loop. I've tested my theory and it works. yipee. Now i want to know if there is a better method for accomplishing this task? i've tried searching google with no luck at all. i don't know what to search for other than 'build a 256 color palette using php loops'. I really find nothing of value. Amazing! here is my code which is working. so can someone offer a more professional method? <?php declare (strict_types = 1); $rgb = ['00','33','66','99','cc','ff']; $colors = 0; foreach ($rgb as $red) { foreach ($rgb as $green) { foreach ($rgb as $blue) { echo $red . $green . $blue . ', '; ++$colors; } } echo '<br><br>'; } echo 'there are ' . $colors . ' colors in this palette'; exit; ?> Thank you very much and i hope that you all have a fantastic day 🙂
  25. wow! Thank you for this info! I really did not know that this is a Windows-specific situation. Your post has saved me a huge headache because my host will be a linux machine. Thus my website would not work correctly at launch because of this case mismatch in my code. Thank You, mac_gyver! meantime, i am too tired to code today. I cannot believe that i missed the i modifier when i posted. alot like locking a door then asking why the door doesn't open. LOL! Best wishes to all.
×
×
  • 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.