Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
deleting info from tables
Old 03-28-2005, 05:12 PM deleting info from tables
Junior Talker

Posts: 4
Trades: 0
I am using the following code to display and edit some information in a database.


Code:
<?
$MYSQLCONN = mysql_connect("host","user","pass") 
or die("<b>Error connecting to mySQL database.</b><br><br>Please try again later.");
mysql_select_db("DB",$MYSQLCONN) 
or die("<b>table  could not be reached. Please try again later.</b><br><br>Script execution terminating.");
	

        if(isset($ends_design_edit_go)) //Displays form to edit database info.
	{
		$query = "SELECT `Link_ID`,`Link_Display`,`Link_Description`,`Link_URL`,`Category`
					FROM `Link_Info` WHERE `Link_ID` = '$uid' LIMIT 1"; //where does uid come from
		$result = mysql_query($query);									//why it is needed, why can Link_ID be used?	
		 while($row = mysql_fetch_array($result)) 
		 	{
				$ends_Link_ID = $row['Link_ID'];
				$ends_Link_Display = $row['Link_Display'];
				$ends_Link_Description = $row['Link_Description'];
				$ends_Link_URL = $row['Link_URL'];
				$ends_Category = $row['Category']; 


				$Link_ID = stripslashes($Link_ID);
				$Link_Display = stripslashes($Link_Display);
				$Link_Description = stripslashes($Link_Description);
				$Link_URL = stripslashes($Link_URL);
				$Category = stripslashes($Category);
?>
				
				<!-- need to link 'Category' values to values in table -- use drop down selection box
				possibly add option to delete this entry from table -->
					
				<form method="post" action="Update_Link_Info2.php" name="editForm">
				<table border="1" cellpadding="2" cellspacing="2">
				<tr><td>ID</td>
				<td><input type="hidden" name="Link_ID" value="<? echo $ends_Link_ID; ?>"></td></tr>
				<tr><td>Link_Display</td>
				<td><input type="text" name="Link_Display" value="<? echo $ends_Link_Display; ?>"></td></tr>
				<tr><td>Link_Description</td>
				<td><input type="text" name="Link_Description" value="<? echo $ends_Link_Description; ?>"></td></tr>
				<tr><td>Link_URL</td>
				<td><input type="text" name="Link_URL" value="<? echo $ends_Link_URL; ?>"></td></tr>
				<tr><td> Category</td>
				<td><input type="text" name="Category" value="<? echo $ends_Category; ?>"></td></tr>
				<tr><td>&nbsp;</td>
				<td><input type="hidden" name="ends_design_edit_save" value="TRUE"></td></tr>
				<tr><td colspan="2"><input type="submit" value="Save Changes"></td></tr></table>
				
				<!--//End edit form -->

<?
									

 			}			
			
	} 
	else if(isset($ends_design_edit_save)) 
	{					
	 	$Link_ID = addslashes($Link_ID);
		$Link_Display = addslashes($Link_Display);
		$Link_Description = addslashes($Link_Description);
		$Link_URL = addslashes($Link_URL);
		$Category = addslashes($Category);

		$query = "UPDATE `Link_Info` SET `Link_ID` = '$Link_ID',`Link_Display` = '$Link_Display',
		`Link_Description` = '$Link_Description',`Link_URL` = '$Link_URL',`Category` = '$Category'
		WHERE `Link_ID` = '$Link_ID' LIMIT 1";
		
			if(!mysql_query($query)) 
			{ 
				echo "Database update failed."; 
			} 
			
			else 
			{ 
				echo "Database update was successful."; 
			}

		echo "<br><br><a href=Update_Link_Info2.php>Back to Data Entry</a>";
   } 
   else 
		{
		$query = "SELECT `Link_ID`,`Link_Display`,`Link_Description`,`Link_URL`,`Category`
		FROM `Link_Info` ORDER BY `Link_ID` ASC";

		if(!mysql_query($query)) 
		{ 
			echo "Could not select from database."; die(); 
		} 
		$result = mysql_query($query);
		echo "<p><b>Select Record to Edit</b></p><p><table>";
		while($row = mysql_fetch_array($result)) 
		{
	     	$ends_Link_ID = $row['Link_ID'];
						
			$ends_Category = $row['Category'];
			echo "<tr><td>Category: $ends_Category</td></tr>";
									
			$ends_Link_Display = $row['Link_Display'];
			echo "<tr><td>Display Name: $ends_Link_Display</td></tr>";

			$ends_Link_Description = $row['Link_Description'];
			echo "<tr><td>Link Description: $ends_Link_Description</td></tr>";

			$ends_Link_URL = $row['Link_URL'];
			echo "<tr><td>Link URL: $ends_Link_URL</td></tr>";
									
			echo "<tr><td><a href='Update_Link_Info2.php?uid=$ends_Link_ID&ends_design_edit_go=1'> 
			<font color=#0000FF>EDIT</font></a></td></tr>"; //does 1=true?
			
			//possibly add 'DELETE' database entry here?
			//echo "<tr><td><a href='Update_Link_Info.php?uid=$ends_Link_ID&ends_design_edit_go=SOME VALUE'> 
			//<font color=#0000FF>DELETE this entry</font></a></td></tr>";
			
			echo "<tr><td>&nbsp;</td></tr>";
									
		}
		echo "</table>";

?>
<?
		} 
								
?>
I would like to change this a little and i'm not sure how. In addition to having the option to edit the information in the table, i'd like to be able to delete an entry. I'm assuming that the MySQL for this would be somethign like:
DELETE * FROM Link_Info WHERE WHERE `Link_ID` = '$Link_ID'

I don't know where to put this in exactly or how to do it.

Last edited by artist-ink; 03-28-2005 at 09:20 PM..
artist-ink is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-28-2005, 08:56 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
Sorry bud, that code is terrible.

I cannot keep my mind interested in it, purely because you have not used a decent ident system.

I might take the code and re-format it, if I have time, but please consider that help is usually here if you do a little bit for yourself.

Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 03-28-2005, 09:21 PM
Junior Talker

Posts: 4
Trades: 0
thanks for offering to help - i was able to figure out what to do, with a little help.

Quote:
I cannot keep my mind interested in it, purely because you have not used a decent ident system.
sorry about the messiness - when i put in 'php' tags, the formatting got all messed up. i changed it to 'code' and it seems to look much better

Last edited by artist-ink; 03-28-2005 at 09:36 PM..
artist-ink is offline
Reply With Quote
View Public Profile
 
Old 03-28-2005, 09:25 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
Great stuff bud. Sorry if I seemed a tad forward, but I like code to be a certain way, which is obviously not everyones thinking.

Nice to see you got it sorted.

Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Reply     « Reply to deleting info from tables
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13130 seconds with 12 queries