Jump to content

Search the Community

Showing results for tags '$_post variables'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. Hello PHP freaks I'm a newbie so bear with me. I have a generic problem and I'm sure code already exists to solve it. I need to have a dynamic sql string variable that will only produce an insert statement with database column names corresponding to input fields on the form that contain values, ignoring the blank ones. I know some looping function like foreach might be used, but if I use it on the $_POST array I'll get the values, not the keys. (the first field, well_no, is a primary key and is held in a session variable, so I know I'll be inserting a value for that column) $ins = "well_no,"; foreach($_POST as $field) if (!empty($field)){ $ins .=$_POST[$field].","; } And I get a warning "Warning: Undefined array key "production in... Here "production" is actually a form input. the problem is my insert statement is hard-coded: $sql = "INSERT INTO well_parent (well_no, easting, northing, purpose, country, admin1, admin2, admin3, settlement, orig_wellno, date_completed, coord_sys, elev, status) VALUES (:well_no, :easting, :northing, ... How can I adjust the sql statement and also the $data array holding the variables. Here's the context: $sql = "INSERT INTO well_parent (well_no, easting, northing, purpose, country, admin1, admin2, admin3, settlement, orig_wellno, date_completed, coord_sys, elev, status) VALUES (:well_no, :easting, :northing, :purpose, :country, :admin1, :admin2, :admin3, :settlement, :orig_wellno, :date_completed, :coord_sys, :elev, :status)"; $stmnt = $pdo->prepare($sql); $data = [':well_no'=>$well_no, ':easting'=>$easting, ':northing'=>$northing, ':purpose'=>$purpose, ':country'=>$country, ':admin1'=>$admin1, ':admin2'=> $admin2, ':admin3'=>$admin3, ':settlement'=>$settlement, ':orig_wellno'=>$orig_wellno, ':date_completed'=> $date_completed, ':coord_sys'=> $coord_sys, ':elev'=>$elev, ':status'=>$status]; $stmnt->execute($data);
  2. Hi there. My problem is quite simple, but carries lots of questions of why the hell is this happening. I'm new at PHP but I'm familiar with the syntax, since It's been 3 years since I code in C, 1 in Java and half year in JS (with HTML and CSS of course). I was creating a page where I could validate a HTML form using PHP script, it was going everything allright, until I couldn't use the data that was going to the $_POST array. I tested it on some other file and It was like the server just didn't allowed me to do it so. I searched around on internet and I found the print_r() function, which shows the data as an associative array in $_POST, like this: array(KeyName => ValueName). Check the code and please, help me find why is this happening. I'm brazillian and all I know about english came from netflix, so i'm sorry if I wrote anything wrong. Thanks S&Z <!DOCTYPE html> <html lang = "pt-br" > <head> <title> Formulário </title> <meta charset="utf-8"> </head> <body> <form method = "POST" action = "<?php htmlspecialchars($_SERVER["PHP_SELF"]);?>" autocomplete = "off"> Nome: <br> <input type = "text" name = "Name" placeholder = "Ex: Guilherme" required autofocus> <?php if($_SERVER["REQUEST_METHOD"] == $_POST){ echo $_POST["Name"]; } ?> <br><br> <input type = "submit" value = "Enviar"> </form> <?php print_r($_POST); ?> </body> </html>
  3. I have an attached header (database.php) file which does all the connecting to the MySQL database and has all the db connection variables, etc., and does all the logical heavy lifting. But the form on the previous page (quiz_selector.php) doesn't point to database.php but to the file it's included in (quiz.php). Should that make a difference? Database.php never gets the $_POST data but the file it is included in (quiz.php) gets the data. I'm wondering if I shouldn't just send the form data directly to database.php. Nah. That doesn't seem like the right solution. How do I get the data into database.php? Category_selector.php's form action is set to quiz.php. Quiz.php includes database.php. Database.php does all the work but quiz.php gets all the input from the form on category_selector.php. (I realize I'm asking the same question twice or three times in the same message. Sorry. I'm trying to make sure I clearly state my problem.) I could attach my code here to this thread (I will include relevant parts of the code if asked to do so,) but my code does not seem to be the problem. I believe the problem is that my thinking is all screwed up. If all the logic is done in database.php, how do I get the data there from quiz_selector.php when I am calling quiz.php and database.php is only an included file? (How do I rewrite my code when it's my brain that needs rewiring? But I digress.) This quiz program is in the VERY early stages of development. I'm thinking about including yet a third file. I could open and close the database in database.php, and then move all the logical operations to another included file. Seems simpler. Even then, the same question about where to send the $_POST data would still apply. P.S. I'm using PDO in case that makes any difference. Thanks 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.