JsusSalv Posted February 12, 2008 Share Posted February 12, 2008 Hello: I wrote the script below. It works fine in IE6 but amazingly fails in Firefox and Opera. It doesn't make sense why Firefox and Opera wouldn't save my info after submitting the data to this script. Does anyone have any clue as to what I may be doing wrong? Some more info that might help: 1) I am using PDO constructors 2) I have set up a persistent connection to MySQL database. 3) This script is for an Ajax / PHP inline editing feature. 4) My comments are within the code in case there were any questions regarding a particular area. 5) I made this script work with ALL browsers using REPLACE. While REPLACE is fine, I would like to get UPDATE working as well. Am I writing the UPDATE statement incorrectly or is there a better way to do all of this? Thank you in advance. Hugo Persistent Connection script: <?php // This script uses the PHP Data Object (PDO) connection style (for use with PHP5.1 / MySQL 4.1 or later). // PDO (PHP Data Object or Portable Data Object) is the new object-oriented data access abstraction. function dbConnect() { // Include the USERS DATABASE INFORMATION file here. require('db_info.inc.php'); // Try/Catch Block. // When PDO can't connect to the database, it displays the Username and Passcode onscreen. // This is because PDO uses a type of error handling called 'exceptions.' // Unless you catch the exception, PHP displays debugging information onscreen (e.g. Username, Passcode). // So, use the following try/catch to catch any exceptions. try { // Encapsulate the connection code and return it within the variable ($conn). // This variable now becomes a reference to the database connection object (in this case, PDO). // String containing hostname & database name must be presented in the following format: 'mysql:host=HOSTNAME;dbname=DATABASE_NAME'. // The hostname, database_name, username, and passcode can be set within a variable (in this case $hostname, $dbname, $username & $passcode). Just make sure to sure double-quotes around the DSN, hostname, and dbname. // A Persistent Connection to the database will be establish by appending the PDO::ATTR_PERSISTENT in the array of driver options passed to the PDO constructor. // Set error handling options for the PDO connection in the fourth argument to the PDO constructor. Example: PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION. $conn = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $passcode, array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); return $conn; } // Type of exception (PDOException) and variable to catch the exception ($e). The variable can be anything desired. catch (PDOException $e) { // Some error handling; Provide useful error message. echo 'Error: Database facilities cannot be accessed at this time.<br /> Please try again later or contact <a href=\"mailto:[email protected]?Database_Connection_Error\"></a><br /><br />'; // Display technical database base error. echo($e->getMessage()); exit; } } ?> MySQL $_POST Processing Script: <?php include('persistentconnection_pdo.inc.php'); include('corefuncs.php'); // Call the function [ nukeMagicQuotes() ] in order to remove backslashes from the $_POST array. nukeMagicQuotes(); // Grab submitted data and assign it to variables. $title = $_POST['title']; $subtitle = $_POST['subtitle']; $forename = $_POST['forename']; $surname = $_POST['surname']; $article = $_POST['article']; // BEGIN BUILDING SQL QUERY IN PREPARATION FOR PDO PREPARED STATEMENT. // Create database connection by calling function [ dbConnect() ] $conn = dbConnect(); // "UPDATE table_name SET column_name=value, column_name2=value2"; $sql="UPDATE articles SET title=$title, subtitle=$subtitle, forename=$forename, surname=$surname, article=$article WHERE article_id=0"; // After binding the parameters, execute the Prepared Statement // The execute() method runs the SQL query. $stmt->execute($_POST); // Generate successful update message and display it within the alert box that pops up after hitting the save button on the toolbar. $updatedMessage = 'Website Updated!'; ?> Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/ Share on other sites More sharing options...
awpti Posted February 12, 2008 Share Posted February 12, 2008 You need to quote string values in a query if they are not integer values. $query = "UPDATE table SET blah='{$bleh}', bleh='{$blargh}' WHERE moo='{$cow}'" Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/#findComment-465347 Share on other sites More sharing options...
JsusSalv Posted February 13, 2008 Author Share Posted February 13, 2008 While that is correct...and I have added single-quotes around my variables, Firefox and Opera are NOT updating the information. IE6 continues to work, however. REPLACE works fine in all browsers but I'd like to use UPDATE. Any other ideas or suggestions? Thanks! Hugo Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/#findComment-465464 Share on other sites More sharing options...
revraz Posted February 13, 2008 Share Posted February 13, 2008 The UPDATE command doesn't care what browser you use. Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/#findComment-465551 Share on other sites More sharing options...
awpti Posted February 13, 2008 Share Posted February 13, 2008 Right. In the end, this is likely an issue with your AJAX script not working on those browsers - not the script. The script works fine. Fix your clientside code. Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/#findComment-465560 Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 That's spot on. PHP is a serverside language, and as such is processed by the server and will not be affected by the browser unless explicitly told to do so. Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/#findComment-465567 Share on other sites More sharing options...
JsusSalv Posted February 13, 2008 Author Share Posted February 13, 2008 Awesome! I am glad comments were posted to help me out. I knew it wasn't my scripts. I have spent three days going over the PHP code am can't see anything wrong. I'm still stumped, however, as to why my script works with REPLACE on all browsers but when I change it to UPDATE Firefox and Opera stop working. I didn't change the javascript file at all when I made the change. Weird eh? Hugo Link to comment https://forums.phpfreaks.com/topic/90785-php-script-to-process-update-via-mysql/#findComment-465648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.