Jump to content

Database wont update


kiwisi

Recommended Posts

This is doing my head in. 

I have another page on a different table (same database) where this works fine. Yet now when I try to update the record, the eventbody (text area) just echos the data with formatting and it says "unable to update record" - which is defined error.

 

All I did was change the field names on this page...

 

 

 

Hope you can help  :confused:

<?php
error_reporting(E_ALL);
  ini_set("display_errors", 1);

//include database connection

include 'db_connect.php';

//check any user action

$action = isset( $_POST['action'] ) ? $_POST['action'] : "";

if($action == "update"){ //if the user hit the submit button

//write our update query

//$mysqli->real_escape_string() function helps us prevent attacks such as SQL injection

$query = "update eventguide 

set

eventtitle = '".$mysqli->real_escape_string($_POST['eventtitle'])."',
eventbody = '".$mysqli->real_escape_string($_POST['eventbody'])."',
eventdate = '".$mysqli->real_escape_string($_POST['eventdate'])."',
where eventid = S'".$mysqli->real_escape_string($_REQUEST['eventid'])."'";

//execute the query

if( $mysqli->query($query) ) {

//if updating the record was successful

echo "<h1><strong>User was updated.</strong></h1>";

}else{

//if unable to update new record

echo "Database Error: Unable to update record.";

}

}

//select the specific database record to update

$query = "select eventid, eventtitle, eventbody, eventdate

from eventguide

where eventid = '".$mysqli->real_escape_string($_REQUEST['eventid'])."'

limit 0,1";

//execute the query

$result = $mysqli->query( $query );

//get the result

$row = $result->fetch_assoc();

//assign the result to certain variable so our html form will be filled up with values

$eventid = $row['eventid'];

$eventtitle = $row['eventtitle'];

$eventbody = $row['eventbody'];

$eventdate = $row['eventdate'];


?>
Link to comment
https://forums.phpfreaks.com/topic/279302-database-wont-update/
Share on other sites

You have a trailing comma at this line which would cause an error in your sql syntax

eventdate = '".$mysqli->real_escape_string($_POST['eventdate'])."',

You also have a syntax error here

where eventid = S'".$mysqli->real_escape_string($_REQUEST['eventid'])."'";

"S" should be within the quotes

God what a nump....

 

 

Doddsey -the S wasn't meant to be there! And the comma was the killer - presumably because it precedes the 'where'?

 

DaveyK - cheers. knew the error reporting had to be in the somewhere, just wasn't sure where to put it.

 

Thanks for your help guys.

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.