problem of update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
begeiste
Forum Newbie
Posts: 1
Joined: Wed Sep 15, 2004 6:33 pm

problem of update

Post by begeiste »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I created the updated page with update button, for some reasons the LargeImage field isn't updated. Don't know why? Can you help me to figure out ? Thanks.

Code: Select all

<?php require_once('Connections/victorphoto.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;    
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE billboard SET thumb=%s, name=%s, Gallery=%s WHERE billboardID=%s",
GetSQLValueString($_POST['thumb'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['Gallery'], "text"),
GetSQLValueString($_POST['billboardID'], "int"));

mysql_select_db($database_victorphoto, $victorphoto);
$Result1 = mysql_query($updateSQL, $victorphoto) or die(mysql_error());

$updateGoTo = "success.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_victorphoto, $victorphoto);
$query_r_result = "SELECT billboardID, thumb, LargeImage, name, Gallery FROM billboard";
$r_result = mysql_query($query_r_result, $victorphoto) or die(mysql_error());
$row_r_result = mysql_fetch_assoc($r_result);
$totalRows_r_result = mysql_num_rows($r_result);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>billboard</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<link href="photos.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="strip">
<div id="nav">
<?php require_once('inc_nav.htm'); ?>
</div>
</div>
<div id="strip-orange">
<a href="#" class="title">Gallery photos of Billboard</a>
</div>
<div id="strip-y">
<a href="addrecord.php" class="addrecord">Add your Gallery photos</a> | <a href="billboard_new.php">Go back to result</a>
<div id="records">Total Records:<?php echo ($startRow_r_result + 1) ?> 
	to<?php echo min($startRow_r_result + $maxRows_r_result, $totalRows_r_result) ?>  
of<?php echo $totalRows_r_result ?>
</div> 
</div>
<div id="container">
    
<p>&nbsp;</p>

     
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">BillboardID:</td>
<td><?php echo $row_r_result['billboardID']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Thumb:</td>
<td><input type="text" name="thumb" value="<?php echo $row_r_result['thumb']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">LargeImage:</td>
<td><input type="text" name="LargeImage" value="<?php echo $row_r_result['LargeImage']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="name" value="<?php echo $row_r_result['name']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Gallery:</td>
<td><textarea name="Gallery" value="<?php echo $row_r_result['Gallery']; ?>" size="32"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Update record"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="billboardID" value="<?php echo $row_r_result['billboardID']; ?>">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($r_result);
?>

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

First, read this
viewtopic.php?t=8815
:) Good Luck.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

What is the type of the LargeImage in db?
If it is BLOB, you cannot use

Code: Select all

<input type="text" name="LargeImage" value="<?php echo $row_r_result&#1111;'LargeImage']; ?>" size="32">
it wont work.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. for one thing.. there's no LargeImage in the update query.....
Post Reply