6 Replies - 1006 Views - Last Post: 25 January 2010 - 05:49 AM Rate Topic: -----

#1 RandomEntity  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-June 09

Can't get this to update into the table

Post icon  Posted 13 January 2010 - 05:16 AM

Ive got some issues. When I click on the "Edit" image it opens a part to update the database table, however once I put the information in, it doesn't actually update. I have no clue what I have done, and I have tried a few things and it still doesn't seem to be working right.

<p><a href="/shop-admin-home">Dragon admin panel</a></p>

{temp:g_item_id="{get.item,safesql}"}
{if:g_item_id}
	<!-- {* Edit item *} //-->

	{if:get.delete}
		<!-- {* Delete item *} //-->
		{sql:delete_item="DELETE FROM `shop_items` WHERE `id` = '{g_item_id}'"}
		{sql:delete_user_items="DELETE FROM `shop_user_items` WHERE `item_id` = '{g_item_id}' "}

		{delete_user_items.error_message}   

		<p><strong>Item deleted</strong> <br /> <a href="/shop-admin-home">Dragon admin panel</a> - <a href="/{page_url}">Edit Dragons</a></p>
	{else:}
		{if:post.submit}

			<!-- {* update item *} //-->  
			{temp:name_len="{post.name,length}"}
			
			<!-- {* Check that the name field is filled in *} //-->  
			{if:name_len<"3"}
				<p>* Please enter a name for the category, 3 or more characters</p>
			{else:}
				<!-- {* Name field filled in *} //-->
				{temp:species="{post.species,safesql}"}
				{temp:DOH="{post.DOH,safesql}"}
				{temp:CQ="{post.CQ,safesql}"}
				{temp:dam_id="{post.dam_id,safesql}"}
				{temp:sire_id="{post.sire_id,safesql}"}
				{temp:gene_base="{post.base,safesql}"}
				{temp:gene_abilities="{post.abilities,safesql}"}
				{temp:gene_markings="{post.markings,safesql}"}
				{temp:icon_url="{post.icon,safesql}"}
				{temp:img_url="{post.img,safesql}"}
			{/if}
		{/if}

		{sql:update_item="UPDATE `shop_items` SET `name` = '{post.name,safesql}', `species` = '{post.species,safesql}', `DOH` = '{post.DOH}', `CQ` = '{post.CQ}', `gene_base` = '{post.base,safesql}', `gene_abilities` = '{post.abilities,safesql}', `gene_markings` = '{post.markings,safesql}', `icon_url` = '{post.icon,safesql}', `img_url` = '{post.img,safesql}' WHERE `id` = '{g_item_id}'"}	  

		{update_item.error_message}
		<p>Dragon Updated - <a href="/shop-admin-home">Dragon Admin Home</a> - <a href="/{page_url}">Edit Dragons</a></p>
	{/if}

	{sql:item="SELECT `id`, `name`, `species`, `DOH`, `CQ`, `dam_id`, `sire_id`, `gene_base`, `gene_abilities`, `gene_markings`, `icon_url`, `img_url`  FROM `shop_items` WHERE `id` = '{g_item_id}'LIMIT 1 "}

	{if:item.rows_found>0}  
		{sql:loop="item"}
			<form action="/{page_url}?item={g_item_id}" method="post">
				<table>
					<tr>
						<td>Dragon Name</td>
						<td><input type="text" name="name" value="{item.name}" /></td>
					</tr>
					<tr>
						<td>Species</td>
						<td>
							<select name="species">
								<option value="Terra">Terra</option>
								<option value="Flame">Flame</option>
								<option value="Frost">Frost</option>
								<option value="Tempest">Tempest</option>
								<option value="Shadow">Shadow</option>
								<option value="Aurora">Aurora</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>Date of Hatching : DOH</td>
						<td><input type="text" name="DOH" value="{item.DOH}" /><br /><small>Please write in the form of daymonthyear eg: 29012010</small></td>
					</tr>
					<tr>
						<td>Clutching Quantity : CQ</td>
						<td><input type="text" name="CQ" value="{item.CQ}" /></td>
					</tr>
					<tr>
						<td valign="top">Basic Genes</td>
						<td><textarea cols="30" rows="2" name="base">{item.base}</textarea></td>
					</tr>
					<tr>
						<td valign="top">Ability Genes</td>
						<td><textarea cols="30" rows="2" name="abilities">{item.abilities}</textarea></td>
					</tr>
					<tr>
						<td valign="top">Marking Genes</td>
						<td><textarea cols="30" rows="2" name="markings">{item.markings}</textarea></td>
					</tr>
					<tr>
						<td>Icon</td>
						<td><input type="text" name="icon" value="{item.icon}" /></td>
					</tr>
					<tr>
						<td>Image</td>
						<td><input type="text" name="img" value="{item.img}" /></td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td><input type="submit" name="submit" value="Edit item" /></td>
					</tr>
				</table>
			</form>
		{/loop}
	{else:}
		<p><strong>Item not found.</strong></p>
	{/if}
{else:}
	<!-- {* Display all items *} //-->
	<p><strong>Note:</strong> Deleting a dragon will remove it from the user profile and database, this process can not be reversed.</p>

	{sql:list_items="SELECT shop_user_items.id, shop_user_items.item_id, shop_items.name FROM `shop_items` LEFT JOIN `shop_user_items` ON shop_items.id = shop_user_items.item_id ORDER BY shop_items.id ASC"}

	{if:list_items.rows_found>0}
		<table border="0">
			<tr>
				<th>Dragon Name</th>
				<th>Species</th>
				<th>&nbsp;</th>
			</tr>
			{sql:shop_items="SELECT `id`, `name`, `species`, `icon_url` FROM `shop_items` ORDER BY id"}
			{sql:loop="shop_items"}
				<tr>
					<td><img src="{shop_items.icon_url}" alt="{shop_items.name}" title="{shop_items.name}" /></td>
					<td>{shop_items.species}</td>
					<td><a href="/{page_url}?item={shop_items.id}" title="Edit" ><img src="http://admin.acornrack.com/files/images/view.png" alt="Edit" style="border: medium none;" /></a> &nbsp; <a href="/{page_url}?item={shop_items.id}&delete=1" title="Delete" class="remove"><img src="http://admin.acornrack.com/files/images/remove.png" alt="Delete" style="border: medium none;" /></a></td>
				</tr>
			{/sql}
		</table>
	{/if}
{/if}

<script type="text/javascript">
$(document).ready(function(){
	$(".remove").click(function(){
		if(confirm("Are you sure you want to delete this item?")){
			return true;	 
		}
		return false;	
	});
});	 
</script>


Is This A Good Question/Topic? 0
  • +

Replies To: Can't get this to update into the table

#2 ForcedSterilizationsForAll  Icon User is offline

  • D.I.C Addict

Reputation: 33
  • View blog
  • Posts: 506
  • Joined: 16-July 09

Re: Can't get this to update into the table

Posted 13 January 2010 - 07:36 AM

Are you able to take the syntax of the SQL query that is going to be executed and run it on the database directly (hopefully in a test environment)?
Was This Post Helpful? 0
  • +
  • -

#3 RandomEntity  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-June 09

Re: Can't get this to update into the table

Posted 13 January 2010 - 04:14 PM

View PostForcedSterilizationsForAll, on 13 Jan, 2010 - 06:36 AM, said:

Are you able to take the syntax of the SQL query that is going to be executed and run it on the database directly (hopefully in a test environment)?


I failed to mention that I really don't know what I am doing.
Did you mean to just have the part that is supposed to update the database by itself and see if it works that way? Ill try it.

Nope. When I single out that part of the sql (I think it's all of it) it still doesn't work.
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3106
  • View blog
  • Posts: 19,145
  • Joined: 14-September 07

Re: Can't get this to update into the table

Posted 13 January 2010 - 04:18 PM

He meant for you to take your UPDATE SQL statement and run it directly on the database through your app of choice. If it goes through that means you have a problem with your current implementation rather then a DB issue. It's important to sort that out early otherwise you'll tear your hair out for no reason.
Was This Post Helpful? 0
  • +
  • -

#5 RandomEntity  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-June 09

Re: Can't get this to update into the table

Posted 21 January 2010 - 12:26 AM

Ok , I think I get what you mean now.
I tried to run the sql thru an inbuilt check, it tells you if you have errors. It came back clear.


{sql:update_item="UPDATE `shop_items` SET `name` = '{post.name,safesql}', `species` = '{post.species,safesql}', `DOH` = '{post.DOH}', `CQ` = '{post.CQ}', `gene_base` = '{post.base,safesql}', `gene_abilities` = '{post.abilities,safesql}', `gene_markings` = '{post.markings,safesql}', `icon_url` = '{post.icon,safesql}', `img_url` = '{post.img,safesql}' WHERE `id` = '{g_item_id}'"} 



thats the part i ran thru. so that means there is a problem elsewhere, right?
Was This Post Helpful? 0
  • +
  • -

#6 RandomEntity  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-June 09

Re: Can't get this to update into the table

Posted 25 January 2010 - 12:59 AM

--see post below--

This post has been edited by RandomEntity: 25 January 2010 - 05:52 AM

Was This Post Helpful? 0
  • +
  • -

#7 RandomEntity  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-June 09

Re: Can't get this to update into the table

Posted 25 January 2010 - 05:49 AM

Ok, now it updates into the database, however i cant keep the info showing.

I input the information. Right before I click the update button this is a screen shot.
here

After I click the button this is the new screen shot.
here

Now, it wants to update the moment I click on the 'edit icon' that takes me to the update form. So if I go back, it saves the blank fields again.

The problems:

--I cant get it to show the fields information properly.
--The drop down menu wont stay on the correct selection, it reverts back to the first one again.
--It tries to auto save as I go into the edit page, not ONLY when I click on the button like its supposed to.
when I click on this code it is supposed to take me to the edit page and NOT try and run the UPDATE query automatically.
<td><a href="/{page_url}?item={shop_items.id}" title="Edit" ><img src="http://admin.acornrack.com/files/images/view.png" alt="Edit" style="border: medium none;" /></a>


I is supposed to run the UPDATE query when I click on the "Edit Item" button.
{if:post.submit}

			<!-- {* update item *} //--> 


This post has been edited by RandomEntity: 25 January 2010 - 05:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1