Jump to content

UPDATE query doing nothing!


slaterino

Recommended Posts

Does anyone know what is wrong with this code. I am getting no errors or anything, the page is simply refreshing without updating anything.

 

  error_reporting(E_ALL);
  ini_set("display_errors", 1);
include ('../library/config.php');
include ('../library/opendb.php');
$id = $_GET['id'];
if(isset($_POST['submit']))
		  {
		  $postage_id = addslashes($_POST['postage_id']);
		  $country = addslashes($_POST['country']);
		  $band = addslashes($_POST['band']);
		  $start = addslashes($_POST['start']);
		  $end = addslashes($_POST['end']);
		  $postage = addslashes($_POST['postage']);

$postage_result = mysql_query("UPDATE postage SET country='$country', band='$band', start='$start', end='$end', postage='$postage' WHERE id='$postage_id' " ,$conn) or die('Error, query failed');

		  header("location: status.php?id=1");
		  }
		  elseif($id)
		  {
      <?php
		 }
          	$postage_result = mysql_query("SELECT * FROM postage",$conn);
        	while($myrow = mysql_fetch_assoc($postage_result))
             {
		$postage_id = $myrow['id'];
		$country = $myrow['country'];
		$band = $myrow['band'];
		$start = $myrow['start'];
		$end = $myrow['end'];
		$postage = $myrow['postage'];
?>
<?php echo "<tr><td><input name='postage_id' type='hidden' value='".$postage_id."'></input></td>";
echo "<td><input name='country' type='text' value='".$country."' size='50'></input></td><td><input name='band' type='text' value='".$band . "' size='2'></input></td><td><input name='start' type='text' value='".$start . "' size='2'></input></td><td><input type='text' name='end' value='".$end . "' size='2'></input></td><td><input name='postage' type='text' value='".$postage . "' size='3'></input></td></tr>"; 

		 }
}
?>

 

I've checked over everything so many times but can't seem to find the problem!!!

Link to comment
https://forums.phpfreaks.com/topic/187287-update-query-doing-nothing/
Share on other sites

$postage_result = mysql_query("UPDATE postage SET country='$country', band='$band', start='$start', end='$end', postage='$postage' WHERE id='$postage_id' " ,$conn)

 

What's $conn ? according to the code you posted $conn isn't set.

Okay, so I made a few mistakes in copying my code down, but only minor things. This is how it should look:

 

<?php

  error_reporting(E_ALL);

  ini_set("display_errors", 1);

include ('../library/config.php');

include ('../library/opendb.php');

$id = $_GET['id'];

if(isset($_POST['submit']))

          {

          $postage_id = addslashes($_POST['postage_id']);

          $country = addslashes($_POST['country']);

          $band = addslashes($_POST['band']);

          $start = addslashes($_POST['start']);

          $end = addslashes($_POST['end']);

          $postage = addslashes($_POST['postage']);

 

$postage_result = mysql_query("UPDATE postage SET country='$country', band='$band', start='$start', end='$end', postage='$postage' WHERE id='$postage_id' " ,$conn) or die('Error, query failed');

 

          header("location: status.php?id=1");

          }

          elseif($id)

          {

            $postage_result = mysql_query("SELECT * FROM postage",$conn);

          while($myrow = mysql_fetch_assoc($postage_result))

            {

        $postage_id = $myrow['id'];

        $country = $myrow['country'];

        $band = $myrow['band'];

        $start = $myrow['start'];

        $end = $myrow['end'];

        $postage = $myrow['postage'];

?>

<?php echo "<tr><td><input name='postage_id' type='hidden' value='".$postage_id."'></input></td>";

  echo "<td><input name='country' type='text' value='".$country."' size='50'></input></td><td><input name='band' type='text' value='".$band . "' size='2'></input></td><td><input name='start' type='text' value='".$start . "' size='2'></input></td><td><input type='text' name='end' value='".$end . "' size='2'></input></td><td><input name='postage' type='text' value='".$postage . "' size='3'></input></td></tr>";

 

          }

}

?>

 

There was a rogue open bracket and php tag in there, but have corrected this now. Is there anything wrong with this code????

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.