Jump to content

Update script is not working, any ideas?


joshgarrod

Recommended Posts

Hi all, I have used this script dozens of times, but it won't work all of a sudden, it performs as though it has but the update is not being made. Any help please?

 

<?php

/***********************Get Record***********************/
$ref = (!empty($_GET['ref']))?trim($_GET['ref']):"";
$table = (!empty($_GET['table']))?trim($_GET['table']):"";

# connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid){
echo("ERROR: " . mysql_error() . "\n");
}
$db_selected = mysql_select_db('quest', $cid); //UPDATE

$query = sprintf("SELECT * FROM $table where ref like '%s' LIMIT 1","%".mysql_real_escape_string($ref)."%");
$result = mysql_query($query) or die($query."<br>".mysql_error());  
$record = mysql_fetch_assoc($result);
if(mysql_num_rows($result) > 0)
{
$ref=$record["ref"];
$title=$record["title"];
$descr=$record["descr"];
$partno=$record["stocknu"];
$price=$record["price"];
$category=$record["category"];
}else{
echo "NOT FOUND";
$ref=0;
$title="";
$descr="";
$partno="";
$price="";
$category="";
}


/***********************Save Record***********************/
# this is processed when the form is submitted
# back on to this page (POST METHOD)
if (isset($_POST['submit'])){
$ref=$_POST["ref"];
$title=$_POST["title"];
$descr=$_POST["descr"];
$partno=$_POST["stocknu"];
$price=$_POST["price"];
$category=$_POST["category"];

# setup SQL statement
$query = sprintf("UPDATE `$table` SET `title` = '%s',`descr` = '%s',`stocknu` = '%s',`price` = '%s',`category` = '%s' WHERE `$table`.`ref` ='%s' LIMIT 1",	mysql_real_escape_string($title),mysql_real_escape_string($descr),mysql_real_escape_string($partno),mysql_real_escape_string($price),mysql_real_escape_string($avail),mysql_real_escape_string($category),mysql_real_escape_string($ref));

#execute SQL statement
$result = mysql_db_query($db,$query,$cid) or die($query."<br>".mysql_error());

# check for error
if (!$result){
	echo("ERROR: " . mysql_error() . "\n$SQL\n");
}
echo "<P>Part updated</P><br />";
}
   
?>

Link to comment
https://forums.phpfreaks.com/topic/179629-update-script-is-not-working-any-ideas/
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.