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