Solved

PHP not updating database - QUESTION

Posted on 2011-09-08
7
243 Views
Last Modified: 2012-05-12
I have a php page that I duplicated exactly. It works on the original site, but on the new site, it does not work. It will not update the database content.

Strangely - it will update the "title" field, but none of the other fields. The title field is the first field after the ID field.

ALSO - using phpAdmin, I can update everything fine. Its just my update form php code that is not working.

Below is the query code.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// save the data to the database

mysql_query("UPDATE themes SET title='$title', layout='$layout', m_color_show='$m_color_show', m_color='$m_color', WHERE id='$id' LIMIT 1") or die(mysql_error());

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

edittheme.php
0
Comment
Question by:msvarts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36507931
You can check the database table fields contains any space or mismatch with these field names ... also you can print the SQL and execute it in the phpMyAdmin...
mysql_query("UPDATE themes SET title='$title', layout='$layout', m_color_show='$m_color_show', m_color='$m_color', WHERE id='$id' LIMIT 1") or die(mysql_error()); 

Could be,


$sql = "UPDATE themes SET title='$title', layout='$layout', m_color_show='$m_color_show', m_color='$m_color', WHERE id='$id' LIMIT 1";

echo $sql;

$res = mysql_query ($sql) or die(mysql_error());

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36507938
remove , near WHERE,


$sql = "UPDATE themes SET `title`='$title', `layout`='$layout', `m_color_show`='$m_color_show', `m_color`='$m_color  WHERE` id`='$id' LIMIT 1";
0
 

Author Comment

by:msvarts
ID: 36507977
You can see the page here:

http://www.lauraphelpsrogers.com/admin/index_main.php?pg=edittheme&id=1

Note that when you change the TITLE, it works, but every other field will not update.

username: zen
password: binder

the form code is attached in the original question post...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 36508025
you need to initialize the variables. Try:
<?php
/* 
 EDIT.PHP
 Allows user to edit specific entry in database
*/
// ----------------------------------------
// ********** FUNCTION renderForm S T A R T
// ----------------------------------------
function renderForm($id, $title, $layout, $m_color_show, $m_color, $m_img, $s_color_show, $s_color, $s_img, $s_img_repeat, $p_color_show, $p_color, $p_img, $p_img_repeat, $f_color_show, $f_color, $f_fontcolor, $f_img, $h_color, $h_face, $h_size, $b_color, $b_face, $b_size, $l_color_show, $l_off, $l_over, $l_bg_off, $l_bg_over, $l_bg_option, $l_bg_img, $error){

	// if there are any errors, display them
 	if ($error != ''){
 		echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 	}
?>

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>

	<table width="100%" border="0" cellpadding="0" cellspacing="0">
    	<tr>
			<td>
            <p style="font-size:1em;padding-left:7px;color:#57996b">Click the titles below to edit the parameters of the themes:</p>
            </td>
        	<td align="right" style="padding-right:7px">
        	<input name="submit" value="Update Now" type="submit" style="font-size:12px;font-weight:bold;text-align:center;margin:-12px -8px 0 0;padding:5px;color:#ffffff;background-color:#ff9900;border:1px solid #000000;display:block;width:150px"></td>
       		</td>
    	</tr>
	</table>
    <table width="100%" border="0" cellpadding="2" cellspacing="1" align="center">
						<tr>
							<td colspan="2">&nbsp;</td>
                        <tr>
							<td>&nbsp;</td>
                           	<td align="right" nowrap>*Theme Title:</td>
        					<td><input type="text" name="title" value="<?php echo $title; ?>" class="admin_250" /></td>
    					</tr>
                        <tr>
							<td colspan="2">&nbsp;</td>
                        <tr>
     	</table>








<div class="accord_menu">
	<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Layout</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
				<table width="100%" border="0" cellpadding="15" cellspacing="1">
					<tr>
						<td valign="top" colspan="5"><strong>Choose Basic Page Layout</strong></td>
					</tr>
					<tr bgcolor="#b5db8c" align="center">
						<td width="20%"><img src="../img/pg_01.gif"></td>
						<td width="20%"><img src="../img/pg_02.gif"></td>
						<td width="20%"><img src="img/pg_03.gif"></td>
						<td width="20%"><img src="img/pg_04.gif"></td>
						<td width="20%"><img src="img/pg_05.gif"></td>
					</tr>
					<tr bgcolor="#b5db8c" align="center">
						<td><input type="radio" name="layout" value="1" <?php if ($layout=='1'){ echo 'CHECKED'; } ?> /> 1</td>
						<td><input type="radio" name="layout" value="2" <?php if ($layout=='2'){ echo 'CHECKED'; } ?> /> 2</td>	
						<td><input type="radio" name="layout" value="3" <?php if ($layout=='3'){ echo 'CHECKED'; } ?> /> 3</td>		
						<td><input type="radio" name="layout" value="4" <?php if ($layout=='4'){ echo 'CHECKED'; } ?> /> 4</td>		
						<td><input type="radio" name="layout" value="5" <?php if ($layout=='5'){ echo 'CHECKED'; } ?> /> 5</td>		
					</tr>
					<tr bgcolor="#b5db8c">
						<td align="center" colspan="5">
							<table cellpadding="3" cellspacing="0" border="0">
								<tr>
									<td><img src="img/dot_nav.gif" align="left">&nbsp;&nbsp;Navigation</td>
									<td><img src="img/dot_blog.gif" align="left">&nbsp;&nbsp;Binder Pages</td>
									<td><img src="img/dot_links.gif" align="left">&nbsp;&nbsp;Links</td>
									<td><img src="img/dot_local.gif" align="left">&nbsp;&nbsp;Promo</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr><td valign="top" colspan="5">&nbsp;</td></tr>
				</table>
			</p>
			</li>
		</ul>
	</div>



<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Fonts</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
		<table width="100%" border="0" cellpadding="5" cellspacing="1">
				<tr>
					<td valign="top" colspan="4"><strong>Choose Font, Colors and Sizes</strong></td>
				</tr>
				<tr align="center" bgcolor="#b5db8c">
					<td>Headlines:</td>
					<td><input class="color" name="h_color" value="<?php echo $h_color; ?>" type="text" maxlength="50" style="font-size:16px;width: 85px;" /></td>
					<td>
					<select name="h_face" style="font-size:16px; background-color: #7ab13e; color: #ffffff; width:250px">
						<option value="<?php echo $h_face; ?>"><?php echo $h_face; ?></option>
                        <option value="Arial, Helvetica, sans-serif">Arial</option>
						<option value="Arial Black", sans-serif">Arial Black</option>
						<option value="font-family: Capitals, serif">Capitals Serif</option>
						<option value="Charcoal, Chicago, sans-serif">Charcoal</option>
						<option value="Chicago, Charcoal, sans-serif">Chicago</option>
						<option value="Courier New", Courier, monospace">Courier</option>
						<option value="Georgia, serif">Georgia</option>
						<option value="Helvetica, Arial, sans-serif">Helvetica</option>
						<option value="Impact, sans-serif">Impact</option>
						<option value="Lucida Sans Unicode, Lucida Grande, sans-serif">Lucida</option>
						<option value="Myriad, sans-serif">Myriad</option>
						<option value="Tahoma, serifSansSerifMonospace">Tahoma</option>
						<option value="Trebuchet MS, Arial, Helvetica, sans-serif">Trebuchet</option>
						<option value="Times New Roman, Times, serif">Times New Roman</option>
						<option value="VerdaVerdana, Geneva, sans-serif">Verdana</option>
						<option value="VT-100", monospace">VT 100</option>
					</select>
					</td>
					<td>
					<select name="h_size" style="font-size:16px; background-color: #7ab13e; color: #ffffff;">
						<option value="<?php echo $h_size; ?>"><?php echo $h_size; ?></option>
                        <option value="12pt">12pt</option>
						<option value="13pt">13pt</option>
						<option value="14pt">14pt</option>
						<option value="15pt">15pt</option>
						<option value="16pt">16pt</option>
						<option value="17pt">17pt</option>
						<option value="18pt">18pt</option>
						<option value="20pt">20pt</option>
						<option value="22pt">22pt</option>
					</select>
					</td>
				</tr>
				<tr align="center" bgcolor="#b5db8c">
					<td nowrap>Body Text:</td>
					<td><input class="color" name="b_color" value="<?php echo $b_color; ?>" type="text" maxlength="50" style="font-size:16px;width: 85px;" /></td>
					<td>
					<select name="b_face" style="font-size:16px; background-color: #7ab13e; color: #ffffff; width:250px">
						<option value="<?php echo $b_face; ?>"><?php echo $b_face; ?></option>
                        <option value="Arial, Helvetica, sans-serif">Arial</option>
						<option value="Arial Black, sans-serif">Arial Black</option>
						<option value="font-family: Capitals, serif">Capitals Serif</option>
						<option value="Charcoal, Chicago, sans-serif">Charcoal</option>
						<option value="Chicago, Charcoal, sans-serif">Chicago</option>
						<option value="Courier New, Courier, monospace">Courier</option>
						<option value="Georgia, serif">Georgia</option>
						<option value="Helvetica, Arial, sans-serif">Helvetica</option>
						<option value="Impact, sans-serif">Impact</option>
						<option value="Lucida Sans Unicode, Lucida Grande, sans-serif">Lucida</option>
						<option value="Myriad, sans-serif">Myriad</option>
						<option value="Tahoma, serifSansSerifMonospace">Tahoma</option>
						<option value="Trebuchet MS, Arial, Helvetica, sans-serif">Trebuchet</option>
						<option value="Times New Roman, Times, serif">Times New Roman</option>
						<option value="VerdaVerdana, Geneva, sans-serif">Verdana</option>
						<option value="VT-100, monospace">VT 100</option>
					</select>
					</td>
					<td>
					<select name="b_size" style="font-size:16px; background-color: #7ab13e; color: #ffffff">
						<option value="<?php echo $b_size; ?>"><?php echo $b_size; ?></option>
                        <option value="8pt">8pt</option>
						<option value="9pt">9pt</option>
						<option value="10pt">10pt</option>
						<option value="11pt">11pt</option>
						<option value="12pt">12pt</option>
						<option value="13pt">13pt</option>
						<option value="14pt">14pt</option>
						<option value="15pt">15pt</option>
						<option value="16pt">16pt</option>
					</select>
					</td>
				</tr>
				<tr><td valign="top" colspan="4">&nbsp;</td></tr>
			</table>
			</p>
			</li>
		</ul>
	</div>




<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Navigation</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
			<table width="100%" border="0" cellpadding="5" cellspacing="1">
			<tr>
				<td valign="top" colspan="5"><strong>Option 1: Use Simple Colors</strong></td>
			</tr>
			<tr bgcolor="#b5db8c" align="center">
				<td rowspan="5" width="90" align="center"><img src="../../master_img/adm/pg_links.gif"></td>	
				<td colspan="4" width="480" nowrap align="left">
                	<select name="l_color_show" class="admin_55">
						<option value="<?php echo $l_color_show; ?>"><?php echo $l_color_show; ?></option>
                        <option value="yes">yes</option>				
						<option value="no">no</option>
					</select>&nbsp;&nbsp;Use background color underneath the text links?
				</td>
			</tr>
			<tr bgcolor="#b5db8c">	
				<td width="110" align="center">Text Color<br />(off-state)</td>
				<td width="110" align="center">Text Color<br />(hover-over)</td>
				<td width="110" align="center">Background Color<br />(off-state)</td>
				<td width="110" align="center">Background Color<br />(hover-over)</td>
			</tr>
			<tr bgcolor="#b5db8c" align="center">
				<td><input class="color" name="l_off" value="<?php echo $l_off; ?>" type="text" maxlength="10" value="#333333" style="width: 90px; font-size:16px;" /></td>
				<td><input class="color" name="l_over" value="<?php echo $l_over; ?>"type="text" maxlength="10" value="#000000" style="width: 90px; font-size:16px;" /></td>
				<td><input class="color" name="l_bg_off" value="<?php echo $l_bg_off; ?>" type="text" maxlength="10" value="#efefef" style="width: 90px; font-size:16px;" /></td>
				<td><input class="color" name="l_bg_over" value="<?php echo $l_bg_over; ?>" type="text" maxlength="10" value="#dddddd" style="width: 90px; font-size:16px;" /></td>
			</tr>	
			</table>
			
<br />			
			<table width="100%" border="0" cellpadding="5" cellspacing="1">
			<tr>
				<td valign="top" colspan="2"><strong>Option 2: Use Image as Button</strong></td>
			</tr>
			<tr bgcolor="#b5db8c">
				<td rowspan="2" width="90" align="center"><img src="img/pg_links.gif"></td>	
				<td alin="left" width="480">
                	<select name="l_bg_option" class="admin_55">
						<option value="<?php echo $l_bg_option; ?>"><?php echo $l_bg_option; ?></option>
                        <option value="no">no</option>			
						<option value="yes">yes</option>
					</select>&nbsp;&nbsp;Use Custom Rollover Graphic for Background?
				</td>
			</tr>
			<tr bgcolor="#b5db8c">
				<td>
					<?php
						//Open images directory
						$dir = dir("upload_assets/");

						echo "<select name='l_bg_img' class='admin_250'>";
						echo "<option value=''>Select Image</option>";
						echo "<option value='".$img."'>".$img."</option>";

						//List files in images directory
						while (($image = $dir->read()) !== false){
							echo "<option value='".$image."'>".$image."</option>";
						}
						echo "</select>";

						$dir->close();
					?>
					<br />
					This graphic must be <u>EXACTLY</u> 470 pixels wide X 25 pixels tall and in GIF formatted image. The first 235 pixels from the left side to the center, will appear as the "off" state - The 235 pixels from the center to the right edge will appear as the "hover" state.
					<p style="padding:10px 0 10px 0; margin:0px"><img src="../../master_img/adm/but_235-25px.gif"></p>
				</td>
			</tr>
			<tr><td valign="top" colspan="2">&nbsp;</td></tr>
			</table>
			</p>
			</li>
		</ul>
	</div>  





	<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Block 1: Mast Head</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
            <table width="100%" border="0" cellpadding="3" cellspacing="1">
				<tr>
					<td valign="top" colspan="4"><strong>Use Simple Colors</strong></td>
				</tr>
				<tr bgcolor="#b5db8c">
					<td rowspan="2" width="60" align="center"><img src="img/pg_site.gif"></td>
					<td width="75" nowrap align="center">Use BG Color</td>
					<td width="75" nowrap align="center">BG Color</td>
					<td width="265" align="center">Background Image</td>
				</tr>
				<tr bgcolor="#b5db8c" align="center">
					<td>
					<select name="m_color_show" class="admin_55">
						<option value="<?php echo $m_color_show; ?>"><?php echo $m_color_show; ?></option>
                        <option value="yes">yes</option>				
						<option value="no">no</option>
					</select>
					</td>
					<td><input class="color" name="m_color" value="<?php echo $m_color; ?>" type="text" maxlength="50" style="font-size:16px;width:85px"></td>
					<td>
					<?php
							//Open images directory
							$dir = dir("upload_assets/");

							echo "<select name='m_img' class='admin_250'>";
							
							if($m_img=='') {	
								echo "<option value=''>None</option>";			// Checks to see if field is empty
							} else {
								echo "<option value='".$m_img."'>".$m_img."</option>";
								echo "<option value=''>None</option>";
							}
							//List files in images directory
							while (($image = $dir->read()) !== false){
								echo "<option value='".$image."'>".$image."</option>";
							}
							echo "</select>";
							$dir->close();
							?>
					</td>
				</tr>
				<tr><td valign="top" colspan="4">&nbsp;</td></tr>
			</table>
			</p>
			</li>
		</ul>
	</div>





<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Block 2: Footer</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
            <table width="100%" border="0" cellpadding="3" cellspacing="1">
				<tr>
					<td valign="top" colspan="5"><strong>Use Simple Colors</strong></td>
				</tr>
				<tr bgcolor="#b5db8c">
					<td rowspan="2" width="60" align="center"><img src="img/pg_site.gif"></td>
					<td width="75" nowrap align="center">Use BG Color</td>
					<td width="75" nowrap align="center">BG Color</td>
                    <td width="75" nowrap align="center">Font Color</td>
					<td width="265" align="center">Background Image</td>
				</tr>
				<tr bgcolor="#b5db8c" align="center">
					<td>
					<select name="f_color_show" class="admin_55">
						<option value="<?php echo $f_color_show; ?>"><?php echo $f_color_show; ?></option>
                        <option value="yes">yes</option>				
						<option value="no">no</option>
					</select>
					</td>
					<td><input class="color" name="f_color" value="<?php echo $f_color; ?>" type="text" maxlength="50" value="#000000" style="font-size:16px;width:85px"></td>
					<td><input class="color" name="f_fontcolor" value="<?php echo $f_fontcolor; ?>" type="text" maxlength="50" value="#000000" style="font-size:16px;width:85px"></td>
					<td>
					<?php
						//Open images directory
						$dir = dir("upload_assets/");

						echo "<select name='f_img' class='admin_250'>";
						
						if($f_img=='') {	
							echo "<option value=''>None</option>";			// Checks to see if field is empty
						} else {
							echo "<option value='".$f_img."'>".$f_img."</option>";
							echo "<option value=''>None</option>";
						}

						//List files in images directory
						while (($image = $dir->read()) !== false){
							echo "<option value='".$image."'>".$image."</option>";
						}
						echo "</select>";

						$dir->close();
					?>
					</td>
				</tr>
				<tr><td valign="top" colspan="5">&nbsp;</td></tr>
			</table>
			</p>
			</li>
		</ul>
	</div>




	





	<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Block 3: Page Background</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
			<table width="100%" border="0" cellpadding="3" cellspacing="1">
				<tr>
					<td valign="top" colspan="5"><strong>Define Page Background Options</strong></td>
				</tr>
				<tr bgcolor="#b5db8c">
					<td rowspan="2" width="60" align="center"><img src="img/pg_page.gif"></td>
					<td width="75" nowrap align="center">Use BG Color</td>
					<td width="75" nowrap align="center">BG Color</td>
					<td width="265" align="center">Background Image</td>
					<td width="60" align="center">Repeat</td>
				</tr>
				<tr bgcolor="#b5db8c" align="center">
					<td>
					<select name="p_color_show" class="admin_55">
						<option value="<?php echo $p_color_show; ?>"><?php echo $p_color_show; ?></option>
                        <option value="yes">yes</option>				
						<option value="no">no</option>
					</select>
					</td>
					<td><input class="color" name="p_color" value="<?php echo $p_color; ?>" type="text" maxlength="50" style="font-size:16px;width: 85px;" /></td>
					<td>
					<?php
						//Open images directory
						$dir = dir("upload_assets/");

						echo "<select name='p_img' class='admin_250'>";
						
						if($p_img=='') {	
							echo "<option value=''>None</option>";			// Checks to see if field is empty
						} else {
							echo "<option value='".$p_img."'>".$p_img."</option>";
							echo "<option value=''>None</option>";
						}

						//List files in images directory
						while (($image = $dir->read()) !== false){
							echo "<option value='".$image."'>".$image."</option>";
						}
						echo "</select>";

						$dir->close();
					?>
					</td>
					<td>
					<select name="p_img_repeat" class="admin_75">
						<option value="<?php echo $p_img_repeat; ?>"><?php echo $p_img_repeat; ?></option>
                        <option value="no-repeat">No Repeat</option>				
						<option value="repeat-x">x-Horizontally</option>
						<option value="repeat-y">y-Vertically</option>				
						<option value="repeat">Tile (repeat)</option>			
					</select>
					</td>
				</tr>
				<tr><td valign="top" colspan="5">&nbsp;</td></tr>
			</table>
			</p>
    		</li>
		</ul>
	</div>



<a class="menuitem submenuheader"><img src="img/plus.gif" width="14" height="17" alt="Expand">Block 4: Site Background</a>
	<div class="submenu">
		<ul>
			<li>
    		<p>
            <table width="100%" border="0" cellpadding="3" cellspacing="1">
				<tr>
					<td valign="top" colspan="5"><strong>Use Simple Colors</strong></td>
				</tr>
				<tr bgcolor="#b5db8c">
					<td rowspan="2" width="60" align="center"><img src="img/pg_site.gif"></td>
					<td width="75" nowrap align="center">Use BG Color</td>
					<td width="75" nowrap align="center">BG Color</td>
					<td width="265" align="center">Background Image</td>
					<td width="60" align="center">Repeat</td>
				</tr>
				<tr bgcolor="#b5db8c" align="center">
					<td>
					<select name="s_color_show" class="admin_55">
						<option value="<?php echo $s_color_show; ?>"><?php echo $s_color_show; ?></option>
                        <option value="yes">yes</option>			
						<option value="no">no</option>
					</select>
					</td>
					<td><input class="color" name="s_color" value="<?php echo $s_color; ?>" type="text" maxlength="50" style="font-size:16px;width:85px"></td>
					<td>
					<?php
						//Open images directory
						$dir = dir("upload_assets/");

						echo "<select name='s_img' class='admin_250'>";
						
						if($s_img=='') {	
							echo "<option value=''>None</option>";			// Checks to see if field is empty
						} else {
							echo "<option value='".$s_img."'>".$s_img."</option>";
							echo "<option value=''>None</option>";
						}

						//List files in images directory
						while (($image = $dir->read()) !== false){
							echo "<option value='".$image."'>".$image."</option>";
						}
						echo "</select>";

						$dir->close();
					?>
					</td>
					<td>
					<select name="s_img_repeat" class="admin_75">
						<option value="<?php echo $s_img_repeat; ?>"><?php echo $s_img_repeat; ?></option>
                        <option value="no-repeat">No Repeat</option>				
						<option value="repeat-x">x-Horizontally</option>
						<option value="repeat-y">y-Vertically</option>	
						<option value="repeat">Tile (repeat)</option>						
					</select>
					</td>
				</tr>
				<tr><td valign="top" colspan="5">&nbsp;</td></tr>
			</table>
			</p>
			</li>
		</ul>
	</div>





</div>
</form>
<?php
 }
// ----------------------------------------
// ********** FUNCTION renderForm END
// ----------------------------------------


// ********** Connection Script and Test
// -----------------------------------------------------
		include("../inc/config.php"); 						// Config script - makes connection
// -----------------------------------------------------
 
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit'])) { 		// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id'])) {
	// get form data, making sure it is valid
 	$id = $_POST['id'];
 	$title = mysql_real_escape_string(htmlspecialchars($_POST['title']));

	$layout = mysql_real_escape_string( $_POST['layout']);
	$m_color_show = mysql_real_escape_string( $_POST['m_color_show']);
	$m_color = mysql_real_escape_string( $_POST['m_color']);
	$m_img = mysql_real_escape_string( $_POST['m_img']);
	$s_color_show = mysql_real_escape_string( $_POST['s_color_show']);
	$s_color = mysql_real_escape_string( $_POST['s_color']);
	$s_img = mysql_real_escape_string( $_POST['s_img']);
	$s_img_repeat = mysql_real_escape_string( $_POST['s_img_repeat']);
	$p_color_show = mysql_real_escape_string( $_POST['p_color_show']);
	$p_color = mysql_real_escape_string( $_POST['p_color']);
	$p_img = mysql_real_escape_string( $_POST['p_img']);
	$p_img_repeat = mysql_real_escape_string( $_POST['p_img_repeat']);
	$f_color_show = mysql_real_escape_string( $_POST['f_color_show']);
	$f_color = mysql_real_escape_string( $_POST['f_color']);
	$f_fontcolor = mysql_real_escape_string( $_POST['f_fontcolor']);
	$f_img = mysql_real_escape_string( $_POST['f_img']);
	$h_color = mysql_real_escape_string( $_POST['h_color']);
	$h_face = mysql_real_escape_string( $_POST['h_face']);
	$h_size = mysql_real_escape_string( $_POST['h_size']);
	$b_color = mysql_real_escape_string( $_POST['b_color']);
	$b_face = mysql_real_escape_string( $_POST['b_face']);
	$b_size = mysql_real_escape_string( $_POST['b_size']);
	$l_color_show = mysql_real_escape_string( $_POST['l_color_show']);
	$l_off = mysql_real_escape_string( $_POST['l_off']);
	$l_over = mysql_real_escape_string( $_POST['l_over']);
	$l_bg_off = mysql_real_escape_string( $_POST['l_bg_off']);
	$l_bg_over = mysql_real_escape_string( $_POST['l_bg_over']);
	$l_bg_option = mysql_real_escape_string( $_POST['l_bg_option']);
	$l_bg_img = mysql_real_escape_string( $_POST['l_bg_img']);
 
	// check that these fields are both filled in
if ($title == ''){
	// generate error message
 	$error = 'ERROR: Please provide a title name!';
 
	//error, display form
 	renderForm($title, $layout, $m_color_show, $m_color, $m_img, $s_color_show, $s_color, $s_img, $s_img_repeat, $p_color_show, $p_color, $p_img, $p_img_repeat, $f_color_show, $f_color, $f_fontcolor, $f_img, $h_color, $h_face, $h_size, $b_color, $b_face, $b_size, $l_color_show, $l_off, $l_over, $l_bg_off, $l_bg_over, $l_bg_option, $l_bg_img, $error);
	
} else {
	// save the data to the database
mysql_query("UPDATE themes SET title='$title', layout='$layout', m_color_show='$m_color_show', m_color='$m_color', m_img='$m_img', s_color_show='$s_color_show', s_color='$s_color', s_img='$s_img', s_img_repeat='$s_img_repeat', p_color_show='$p_color_show', p_color='$p_color', p_img='$p_img', p_img_repeat='$p_img_repeat', f_color_show='$f_color_show', f_color='$f_color', f_fontcolor='$f_fontcolor', f_img='$f_img', h_color='$h_color', h_face='$h_face', h_size='$h_size', b_color='$b_color', b_face='$b_face', b_size='$b_size', l_color_show='$l_color_show', l_off='$l_off', l_over='$l_over', l_bg_off='$l_bg_off', l_bg_over='$l_bg_over', l_bg_option='$l_bg_option', l_bg_img='$l_bg_img' WHERE id='$id' LIMIT 1") or die(mysql_error()); 
	// once saved, redirect back to the view page
	echo '<script language="JavaScript" type="text/javascript">';
	echo 'self.location="index_main.php?pg=listtheme"';
	echo '</script>'; 
 }
 } else {
 	// if the 'id' isn't valid, display an error
 	echo 'Error!';
 }
 } else { // if the form hasn't been submitted, get the data from the db and display the form
 
 // get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
 if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0){
 	// query db
 	$id = $_GET['id'];
 	$result = mysql_query("SELECT * FROM themes WHERE id=$id")
 		or die(mysql_error()); 
 	$row = mysql_fetch_array($result);
 
 // check that the 'id' matches up with a row in the databse
 if($row){ 
 	// get data from db
	$title = $row['title'];
	$layout = $row['layout'];
	$m_color_show = $row['m_color_show'];
	$m_color = $row['m_color'];
	$m_img = $row['m_img'];
	$s_color_show = $row['s_color_show'];
	$s_color = $row['s_color'];
	$s_img = $row['s_img'];
	$s_img_repeat = $row['s_img_repeat'];
	$p_color_show = $row['p_color_show'];
	$p_color = $row['p_color'];
	$p_img = $row['p_img'];
	$p_img_repeat = $row['p_img_repeat'];
	$f_color_show = $row['f_color_show'];
	$f_color = $row['f_color'];
	$f_fontcolor = $row['f_fontcolor'];
	$f_img = $row['f_img'];
	$h_color = $row['h_color'];
	$h_face = $row['h_face'];
	$h_size = $row['h_size'];
	$b_color = $row['b_color'];
	$b_face = $row['b_face'];
	$b_size = $row['b_size'];
	$l_color_show = $row['l_color_show'];
	$l_off = $row['l_off'];
	$l_over = $row['l_over'];
	$l_bg_off = $row['l_bg_off'];
	$l_bg_over = $row['l_bg_over'];
	$l_bg_option = $row['l_bg_option'];
	$l_bg_img = $row['l_bg_img'];
 
 	// show form
	renderForm($id, $title, $layout, $m_color_show, $m_color, $m_img, $s_color_show, $s_color, $s_img, $s_img_repeat, $p_color_show, $p_color, $p_img, $p_img_repeat, $f_color_show, $f_color, $f_fontcolor, $f_img, $h_color, $h_face, $h_size, $b_color, $b_face, $b_size, $l_color_show, $l_off, $l_over, $l_bg_off, $l_bg_over, $l_bg_option, $l_bg_img, '');
 } else {	// if no match, display result	
	echo "No results!";
 	}
 } else { 	// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
 	echo 'Error!';
 	}
 }
?>

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36508030
I'm unable to run and see ..

can  you try to print whether you receive the values from the input like this...

print_r ($_POST);

exit;

It has to be after you submit the form...
0
 

Author Closing Comment

by:msvarts
ID: 36508069
Excellent!
0
 
LVL 82

Expert Comment

by:hielo
ID: 36508074
>>Strangely - it will update the "title" field, but none of the other fields
>>Note that when you change the TITLE, it works, but every other field will not update.
Look at lines 551-552 of my previous post (ID:36508025). You DID initialize those variables, that's why the title IS getting updated, but you are missing the lines that I added (554-582), which are initializing the variables you used in your update.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question