Jump to content

Database wont update


Go to solution Solved by 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

Edited by doddsey_65
  • Solution

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.

Edited by kiwisi
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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