Jump to content

dalecosp

Members
  • Content count

    463
  • Joined

  • Last visited

  • Days Won

    7

dalecosp last won the day on February 2

dalecosp had the most liked content!

Community Reputation

28 Good

About dalecosp

  • Rank
    Advanced Member

Contact Methods

  • Website URL
    https://www.ombe.com

Profile Information

Recent Profile Visitors

21,782 profile views
  1. dalecosp

    PHP Update Script Help

    Instead of just dumping mysqli_error(), also dump the statement you tried to make. See if you can see why it wouldn't work. If necessary, try it against a test database.
  2. <?php $foo = "Foobar"; echo "$foo"; // Foobar. echo $foo; // Foobar. Functionally equivalent to above, no quotes needed. echo '$foo'; // $foo. A literal string, and not what we wanted. $foo = "/home/dalecosp/php"; file_put_contents($foo . "/" . 'bar', "This is file content"); // writes the given sentence into /home/dalecosp/php/bar. file_put_contents("$foo/" . "bar", "This is file content"); // does the same thing; because of double-quote variable interpolation, the trailing slash is added to /home/dalecosp/php (it was not given when $foo was assigned). file_put_contents("$foo" . "/bar", "This is file content"); // does the same thing. The slash is still in the string. file_put_contents("$foo/" . '/bar', "This is file content"); // does the same thing, because we literally want '/bar' to be appended to the path given by $foo. file_put_contents('$foo' . '/bar', "This is file content"); // will almost certainly fail, "no such directory $foo/bar". Single quotes are a literal string. Double quotes do variable interpolation. They aren't needed if the variable is all that's required; it's an easy way to concatenate strings or insert a variable into a string.
  3. dalecosp

    New member Introduction

    Welcome to PHPFreaks! There sure are some around here.
  4. dalecosp

    All languages into one page.

    Google Translate works for me! (For some subset of languages we're interested in, that is....)
  5. dalecosp

    PHP sessions

    Goodness gracious, great balls of AJAX! What in God's green earth are you selling? Because if it's not blow, crypto-currency or heavily-discounted precious metals ain't no one got time to load a page with one data item on it.
  6. dalecosp

    Looking for Donut Chart code

    That might be worth a try. You'd have to be careful about where you put your labels ....
  7. dalecosp

    file name change help

    Sounds an interesting use case. All in the same folder? 'Cause if the path is different, "config.php" (or 'myApp.ini' or something similar) at least has the distinction of being an appropriate name for a configuration file. I once created 65 sites in one day using logic files, templates, and a config munger that changed "config.php" to contain appropriate defaults for the DOCROOT they were in. One of my proud "not proud" moments, I guess. 😉😉
  8. I'm not sure I understand 100% ... loop them for creation or reading? For reading, you'd need to know the element's name attributes (from the HTML) when processing the data in the handler script.
  9. Well, can you put them in the form somehow? Traditionally that might be done with <input type='hidden'>, if it's not possible to move the <form> tags to the appropriate locations. If you can't do that, I'm not sure what to tell you, because that sounds like front-end type magic (AJAX). Well, I kind of showed that in a more/less procedural style in my post above. If you want you could wrap that in a function; keep in mind you'd need to either declare $db to be global or establish a connection (or connection object) INSIDE your function. As Barand showed you, PDO or the newer MySQL(i) both assign the ID of the last inserted value to $db->insert_id; you can assign this to a variable and use it in your final SQL statement.
  10. He's just telling you how to get the ID of the last inserted row. You wrote pseudo-code, so that's not the only thing you need help with, I'd expect? Here's your pseudo-code with comments that I hope will help. I'll post again with some direct answers to your two points, above. <?php # First off, your code is accepting $_POST data at face value. # An attacker might be able to do something evil with that. # # Next, where's the SQL connection happening? I'll do a mysqli ... $db = mysqli_connect("localhost", "user", "pass", "db_name"); # NOTE: I don't do ANY error checking in this script. You'll NEED # to do that, because almost any invalid hit on the MySQL server will # halt execution of the script. $title = $_POST['$title']; $pageType = $_POST['$value']; # This code (and 3 others later) will make PHP expect a var named '#areaSelect' # in the POST data. You may need to do a print_r(), var_dump(), or use other debug-type # technique to ensure that you are indeed getting a var with that name from the browser. # (In other words, I wonder if you're confusing JS's DOM element ID's with POST data). $displayId = $_POST['#areaSelect']; # yields a UNIX_TIMESTAMP. As it's only used in one SQL statement, you # might just use MySQL's UNIX_TIMESTAMP() function and omit this. $start_time = now(); # see note above $end_time = $_POST['#datePicker']; $slide_order = $_POST['#orderSet']; $duration = $_POST['#durationSet']; # depending on the data type, you might not want to quote all the values (e.g. # MySQL may try to store integers as strings if they're quoted, and that might be # "not what you want" or even cause your statement to fail). $sql = "INSERT INTO pages(title, page_type_id, display_id, start_time, end_time, slide_order, duration) VALUES ('$title','$pageType','$displayId','$start_time','$end_time','$slide_order','$duration')"; $db->query($sql); $page_id = $db->insert_id; //Here, pass the content from the included fullwidth.php extarea content and the panel_type_id # you have a table named 'content', with a column named 'content', into which # you want to insert a variable named '$content' ... OK. But can we discuss naming? ;-) $content = $_POST['textArea'] $sql = "INSERT INTO content(content) Values('$content')"; $db->query($sql); $content_id = $db->insert_id; # typo here? $id is a PHP variable. # Also bug: I'm fairly sure you want ($id == "FullPage") ... not an assignment. if(#id = FullPage){ $panel_type = 1; } # This is where Barand's comment is helpful ... knowing how to get the Insert ID. $sql = INSERT INTO panels (panel_type_id, page_id, cont_id) VALUES ('$panel_type', $page_id, $content_id); $db->query($sql);
  11. dalecosp

    music fonts required

    Another good font, free ... "Gonville", by Simon Tatham: https://git.tartarus.org/?p=simon/gonville.git
  12. dalecosp

    Intoduce myself

    Indeed, welcome to PHPFreaks ... 🙂
  13. dalecosp

    New Guru: maxxd

    Yeah, but does anyone ever actually punch it .... and follow through? Congrats, Maxxd ... I'm sure you'll be a tip-top rep for the community :-)
  14. dalecosp

    how to update null

    NULL is trouble. In PHP it's approximately zero, it's special in the DB and requires that you use differrent syntax to set and/or check for it. Avoid it when possible and use some other value (like 0).
  15. dalecosp

    music fonts required

    Noteflight.com Bet they wrote a ship-load of JS for that ....
×

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.