Jump to content

[SOLVED] Update Query not working


PC Nerd

Recommended Posts

hi,

 

Im creating a script where administration can update database entries.

 

the form directs to itself... eg edit_tour.php?id=33 directs to edit_tour.php?id=33&action=update

 

here is the code that runs on action==update

 

 

if ($_GET['action'] == 'update' && isset($_GET['id']) && !empty($_GET['id'])) {


$Day = date("j", $_POST['Start_date_day']);
$Month = date("n", $_POST['Start_date_day']);
$Year = date("Y", $_POST['Start_date_day']);
$Hour = date("G", $_POST['Start_Date_hour']);
$Minute = date("i", $_POST['Start_date_minute']);


$Start_Date = mktime($Hour, $Minute, 0, $Month, $Day, $Year);

$Day = date("j", $_POST['Finish_date_day']);
$Month = date("n", $_POST['Finish_date_day']);
$Year = date("Y", $_POST['Finish_date_day']);
$Hour = date("G", $_POST['Finish_Date_hour']);
$Minute = date("i", $_POST['Finish_date_minute']);

$Finish_Date = mktime($Hour, $Minute, 0, $Month, $Day, $Year);

$SQL = "UPDATE tours SET `Tour_Name` = '".$_POST['Tour_Name']."', `Destination` = '".$_POST['Destination']."', `Departs` = '".$_POST['Departs']."', `Description` = '".$_POST['Description']."', `Seats_Total` = '".$_POST['Seats_Total']."', `Seats_Avail` = '".$_POST['Seats_Avail']."', `Start_Date` = '".$Start_Date."', `Finish_Date` = '".$Finish_Date."' WHERE `User_ID` = ".$_GET['id']."";
echo "<br>".$SQL."<br>\n";
$Create_Query = MYSQL_DATABASE_QUERY($SQL, $DB_Server);

}

 

 

 

now this is the output of my query:

 

UPDATE tours SET `Tour_Name` = 'Sydney - Sport', `Destination` = 'Sydney Stadium', `Departs` = 'Katoomba Train Station', `Description` = 'NEW', `Seats_Total` = '12', `Seats_Avail` = '8', `Start_Date` = '1201912200', `Finish_Date` = '1197936000' WHERE `User_ID` = 33

 

Im also using a different MYSQL connection method.  ive had to comment out most of it becausae i had troube with it, but this is the file:

 

<?php



function CONNECT_MYSQL_DATABASE() {

$host = "***";  #usually localhost
$account = "***"; # username for access.  eg. root
$password = "***"; 
$db_name = "***"; #name of database on the server that you want to connect.

global $db_type;
$db_type = 4.1; # MySQL version

#if ($db_type <= 4.0) {
#	$DB_Server = mysql_connect($host, $account, $password) or die("Cannot conenct to the selected MySQL ".$db_Type." on the selected server.  Invalid Parameters");
#	$DB_Select = mysql_select_db($db_name, $DB_Server) or die("Connection established to server, however unable to find selected database.");
#}

#else if($db_Type >= 4.1) {
	#echo "connecting to a 4.1 or higher";
	$DB_Server = mysqli_connect($host, $account, $password);# or die("Cannot conenct to the selected MySQL ".$db_Type." on the selected server.  Invalid Parameters");
	$DB_Select = mysqli_select_db($DB_Server, $db_name);# or die("Connection established to server, however unable to find selected database.");
#}
return $DB_Server;
}

function MYSQL_DATABASE_QUERY($SQL, $DB_Server) {

#if($db_type <= 4.0) {
#	$QUERY = mysql_query($SQL, $DB_Server) or die(mysql_error());
#}

#else 
#if($db_type >= 4.1) {
	$QUERY = mysqli_query($DB_Server, $SQL);# or die(mysqli_error($DB_Server));
	#echo $SQL;
	#if(isset($QUERY)) {echo "$QUERY is set";}
	#if(empty($QUERY)) {echo "$QUERY is empty";}
	#echo "<br><br>";
	#echo "QUERY: ".$QUERY;
	#echo "<br> and query";
#}
return $QUERY;
}

function MYSQL_GET_ARRAY($QUERY) {

$ROW = mysqli_fetch_array($QUERY);
return $ROW;
}


$DB_Server = CONNECT_MYSQL_DATABASE();

?>

 

 

Now i know that these functions work because they are workign for all my INSERT and SELECT queries, which makes me think that its the actual SQL that ismy problem, and nto the connection etc.

 

 

Does anyone have any suggestions on how i can fix this problem.

 

*** there are no errors echoed out.

*** when checking the database with phpmyadmin - the database hasnt been updated with the new values..... which means the UPDATE query didnt work.

 

 

 

Thanks for any suggestions in advance.

Link to comment
Share on other sites

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.