Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Problem with UPDATE query

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Problem with UPDATE query

Postby Alpha36Steve » Sat Feb 01, 2014 4:08 am

Hello,
I am fairly new to PHP but ancient with HTML. I have created a page that my client uses to update their gigs on a display page. After the gig, which is a charity event, they want to update the MySQL record that hols the details of the gig with the amount of donations they received. I have amended the code to include an update query but no matter what I try it will not update the MySQL table. It may be a very silly mistake that I as a noobie cannot see. Could anyone help please? The code is below:
<!DOCTYPE HTML>
<?php
Include('Includes/sig_connect.php');
IF(isset($_POST['form_sub']))
{
$query = 'INSERT INTO gigs (
DATE, VENUE, DETAILS)
VALUES (
"'.$_POST['DATE'].'",
"'.$_POST['VENUE'].'",
"'.$_POST['DETAILS'].'"
)';
if(!mysql_query($query, $db_link))
{
Echo 'Query failed to run'.mysql_error();
exit;
}
# header('Location: '.$_SERVER['PHP_SELF']);
# exit;
} #End if isset form sub
?>
<html>
<head>
<title> Upcoming Appearances </title>
<br>
<BR>
<link rel="stylesheet" type="text/css" href="wightsupp.css">
<script src="jquery.js">
</script>
<div id="content"></div> </div>
</head>
<BODY background="clouds3.jpg">
<script type="text/javascript">
$(document).ready(function(){
$("tr:nth-child(even)").addClass("red");
$("tr:nth-child(odd)").addClass("yellow");
});
</script>
<?PHP
# Delete Record Here
if(isset($_GET['delete_id']))
{
$query = 'DELETE FROM gigs WHERE ID = "'.$_GET['delete_id'].'"';

if(!mysql_query($query, $db_link))
{
Echo 'Query failed to run'.mysql_error();
exit;
}
} #End if isset delete
# THIS IS THE PROBLEM AREA! IT JUST WON'T UPDATE THE TABLE
IF(isset($_POST['update']))
{
$query = 'update gigs SET donations = ("'.$_GET[DONATIONS].'") WHERE ID = "'.$_GET[update_id].'"';
if(!mysql_query($query, $db_link))
{
Echo 'Query failed to run'.mysql_error();
exit;
}
} #End if isset delete
# header('Location: '.$_SERVER['PHP_SELF']);
# exit;
#Add a record Here
IF(isset($_GET['add']))
{
$query = "SELECT * FROM gigs";
$result = mysql_query($query, $db_link);
$row = mysql_fetch_assoc($result);

?>
<Form action = "<?PHP $_SERVER['PHP_SELF']?>" method = "post" name = "ADD" >
<Table name = "add a part" WIDTH = "650">
<TR>
<td><b>DATE</b>
<input type = "text" name = "DATE" ></td><TD></td>
<td><b>VENUE</b>
<input type = "text" name = "VENUE" ></td><TD></td>
<td><B>DETAILS</B>
<input type = "text" name = "DETAILS">
</td>
<td><b>DONATIONS</b>
<input type="text" name="DONATIONS"></td><TD></td>
</tr>
<tr><td><input type = "submit" name = "form_sub" value = "Submit Details."></td>
</form>
<?PHP
?>
<?PHP
}// close main if
// ?>
<nav name="addgig" id="add gig">
<a href="<?php $_SERVER['PHP_SELF'] ?>?add">Add Gig DETAILS</a></td></tr><BR><BR>
<br><A HREF="gig_admin.php">Return To Gigs Page<br><br><br></a></td></tr></nav>
<center><table name="gigstable" id="gigstable" border = "1px" cell_padding ="0" >
<tr >
<td align="left" WIDTH = "5">ID</td>
<td align="left" WIDTH = "15">DATE</td>
<td align="center" WIDTH = "125">VENUE</td>
<td align="center" WIDTH = "125">DETAILS</td>
<td align="center" WIDTH = "125">DONATIONS</td>
<td align="center" WIDTH = "5">£££</td>
<td align="center" WIDTH = "5">Del</td>
</tr>
<?php
# Main Display Select
# Starts Here
$query = "SELECT * FROM gigs Order by DATE";
$result = mysql_query($query, $db_link);
while($row = mysql_fetch_assoc($result))
{
?>
<TR>
<td height = "25" width = "5%" align="center">
<a href="<?= $_SERVER['PHP_SELF'].'?edit_id='.$row['ID'] ?>"><?PHP echo $row['ID'] ?></a></td>
<td height = "25" width = "10%" align="center"><?PHP ECHO $row['DATE'] ?></td>
<td height = "25" width = "40%" align="center"><?PHP ECHO $row['VENUE'] ?></td>
<td height = "25" width = "70%" align="center"><?PHP ECHO $row['DETAILS'] ?></td>
<td height="25" width="70%" align="center"><?PHP ECHO $row['DONATIONS']?></td>
<td height = "25" width = "20%" align="left">
<a href="<?= $_SERVER['PHP_SELF'].'?update_id='.$row['ID'] ?>">£</a></td>
<td height = "25" width = "20%" align="left">
<a href="<?= $_SERVER['PHP_SELF'].'?delete_id='.$row['ID'] ?>">x</a></td>
</TR>
<?PHP
} #End while
?>
</table></center>
</body>
</html>
Alpha36Steve
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat Feb 01, 2014 4:02 am

Re: Problem with UPDATE query

Postby paintitblack » Mon Feb 17, 2014 9:03 pm

Your HTML form is using Post, but in your MySQL Update statement, you're using $_GET.

Should this use $_POST, like your Insert statement does?
paintitblack
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Feb 17, 2014 8:53 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.