Jump to content

My update code is not updating the database with values


sonnieboy

Recommended Posts

<?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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.