Jump to content

$update


hinchcliffe

Recommended Posts

Hey guys can you take a look over my code my update query isn't working. Ty

 

$update = "UPDATE articles SET 
title = '".$_POST['title']."',
body = '".$_POST['body']."'
WHERE id ='".$_GET['idr']."'";
$check = mysql_query($update);	
echo "<div><center>Success! Job Saved!</center></div>";
echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=\"index.php\">";

Link to comment
https://forums.phpfreaks.com/topic/77351-update/
Share on other sites

Change your code to this and tell us what it gives you

 

<?php

$update = "UPDATE articles SET title = '".$_POST['title']."', body = '".$_POST['body']."' WHERE id ='".$_GET['idr']."'";
$check = mysql_query($update)or die("ERROR - ". mysql_error() ."<br>" . $update);	

?>

Link to comment
https://forums.phpfreaks.com/topic/77351-update/#findComment-391591
Share on other sites

weird still not updating, there are no errors in the code though. hmm Maybe take a look at more of my code.

 

<?php
// if the submit button is clicked, do this.
if($_POST['update'])
	{
	$table = $_POST['table'];
	$returnurl1 = "find_articles.php"; // this is the redirect url after succes
	$returnurl2 = "edit_articles.php?id=".$_GET['idr']."&mode=modify"; // this is the redirect url after success

		if($_GET['mode']=='add')
			{
				$insert = "INSERT INTO articles (title, body) VALUES ('".$_POST['title']."', '".$_POST['body']."')";
				mysql_query($insert);

				// redirect after 2 seconds
		echo "<div><center>Success! Article Added!</center></div>";
		echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=".$returnurl1."\">";
			}

			//if mod eis not add, then the mode is modify 
			else
			{ 
				$update = "UPDATE articles SET 
				title = '".$_POST['title']."',
				body = '".$_POST['body']."'
				WHERE id ='".$_GET['idr']."'";
				$check = mysql_query($update);	
				echo "<div><center>Success! Job Saved!</center></div>";
				echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=\"index.php\">";
			}		


	}
?>

Link to comment
https://forums.phpfreaks.com/topic/77351-update/#findComment-391597
Share on other sites

Use this code and copy and paste anything you see on the screen

 

<?php
// if the submit button is clicked, do this.
if ($_POST['update']) {
    $table = $_POST['table'];
    $returnurl1 = "find_articles.php";
    // this is the redirect url after succes
    $returnurl2 = "edit_articles.php?id=".$_GET['idr']."&mode=modify";
    // this is the redirect url after success
    
    if ($_GET['mode']=='add') {
        $insert = "INSERT INTO articles (title, body) VALUES ('".$_POST['title']."', '".$_POST['body']."')";
        mysql_query($insert);
        
        // redirect after 2 seconds
        echo "<div><center>Success! Article Added!</center></div>";
        echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=".$returnurl1."\">";
    }
    
    //if mod eis not add, then the mode is modify
    else
    {
        echo "This line should show up...<p>";
        
        $update = "UPDATE articles SET title = '".$_POST['title']."', body = '".$_POST['body']."' 
        WHERE id ='".$_GET['idr']."'";
        $check = mysql_query($update)or die("ERROR - ". mysql_error() ."<br>" . $update);
        
        echo $update.'<p>';
        
        echo "<div><center>Success! Job Saved!</center></div>";
        //echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=\"index.php\">";
    }
    
    
}
?>

Link to comment
https://forums.phpfreaks.com/topic/77351-update/#findComment-391600
Share on other sites

<?php
// if the submit button is clicked, do this.
if ($_POST['update']) {
    $table = $_POST['table'];
    $returnurl1 = "find_articles.php";
    // this is the redirect url after succes
    $returnurl2 = "edit_articles.php?id=".$_GET['idr']."&mode=modify";
    // this is the redirect url after success
    
    if ($_GET['mode']=='add') {
        $insert = 'INSERT INTO articles (title, body) 
VALUES ('{.$_POST['title'].}', '{.$_POST['body'].}')';
        mysql_query($insert);
        
        // redirect after 2 seconds
        echo "<div><center>Success! Article Added!</center></div>";
        echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=".$returnurl1."\">";
    }
    
    //if mod eis not add, then the mode is modify
    else
    {
        echo "This line should show up...<p>";
        
        $update = 'UPDATE articles SET title = '{.$_POST['title'].}',
body = '{.$_POST['body'].}' 
        WHERE id ='{.$_GET['idr'].}'';
        $check = mysql_query($update)or die("ERROR - ". mysql_error() ."<br>" . $update);
        
        echo $update.'<p>';
        
        echo "<div><center>Success! Job Saved!</center></div>";
        //echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=\"index.php\">";
    }
    
    
}
?>

 

try using single quotes and curly brackets around your Super Global Variables like post and get  ;D

Link to comment
https://forums.phpfreaks.com/topic/77351-update/#findComment-391628
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.