sonnieboy Posted November 13, 2017 Share Posted November 13, 2017 <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); // Initialize connection to database $conn=mysqli_connect("localhost","myuser","mypass","mydb"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } function render_error($settings = array("title"=>"Failed","body"=>"Sorry, your submission failed. Please go back and fill out all required information.")) { ?> <h2><?php echo (isset($settings['title']))? $settings['title']:"Error"; ?></h2> <p><?php echo (isset($settings['body']))? $settings['body']:"An unknown error occurred."; ?></p> <?php } $sql = "UPDATE xphias SET pastorname=?, ministriesname=?, sermon_name=?, scripture=?, video_name=?, sermon_notes=?, sermon_date=? WHERE sermon_id=?"; $stmt = $conn->prepare($sql); // We have one datetime parameter, one integer parameter and 6 string data types // So that's 6 consecutive string params and then 1 datetime parameter and one integer param. $stmt->bind_param('sssssssd', $pastorname, $ministriesname, $sermon_name, $scripture, $video_name, $sermon_notes, $sermon_date, $sermon_id); $stmt->execute(); if ($stmt->errno) { echo "FAILURE!!! " . $stmt->error; } else echo "Updated {$stmt->affected_rows} rows"; $stmt->close(); ?> Greetings again, I am trying to use the following code to update some database fields. When I run the code, I get successful update message but no record is updated. I am not getting any errors. Any ideas what I could be doing wrong? Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 13, 2017 Share Posted November 13, 2017 Where are the magic variables in your query coming from? Quote Link to comment Share on other sites More sharing options...
sonnieboy Posted November 13, 2017 Author Share Posted November 13, 2017 Thank you very much. Stupid me. Quote Link to comment Share on other sites More sharing options...
phpmillion Posted November 13, 2017 Share Posted November 13, 2017 By the way, are you sure you need "d" for the last variable? Since sermon_id is a primary key in your table (I guess so according to your code), "i" would do the job fine. Of course, "d" won't prevent your code from working, but I don't see a point using double in this case. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.