Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Mysql Edit, editing info in a MYSQL database
kopythat
post Mar 24 2005, 06:18 PM
Post #1


Newbie
*

Group: Members
Posts: 5
Joined: 7-March 05
Member No.: 4,236



I have a simple database with a php form thats inserts the info into the database, and another file that extracts the info to display the info on another page....

Now my question is ......how do i add the EDIT button to edit the database???

here is my database
CODE

CREATE TABLE `businesses` (
 `id` int(10) NOT NULL auto_increment,
 `business` varchar(255) NOT NULL default '',
 `description` text NOT NULL,
 `emailaddress` varchar(255) NOT NULL default '',
 `website` varchar(255) NOT NULL default '',
 PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2;



here is my form to add
CODE
<?
include("include/common.php");
global $conn
?>
<style type="text/css">
<!--
.style1 {
font-size: 18px;
font-weight: bold;
}
-->
</style>


<div align="center" class="style1">ADD A NEW BUSINESS TO THE LINK PAGE</div>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<table border=".01" align="center">
<tr>
<td width="146"><B>Business Name:</b></td>
<td width="172"><input type="text" name="business_name" /></td>
</tr>
<tr>
<td><b>Business Description:</b></td>
<td><textarea name="business_desc" rows="15" cols="20"></textarea></td>
</tr>
<tr>
<td><b>E-Mail Address:</b></td>
<td><input type="text" name="business_email" /></td>
</tr>
<tr>
 <td><B>Website:</b></td>
 <td><div align="center">
       <input name="business_website" type="text" />
       <strong><BR>
       NO HTTP:// </strong>just<strong> WWW<BR>
       eg. www.yahoo.com </strong></div></td>
</tr>
<tr>
<td><input type="submit" name="add" value="Add!" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
<?php

if(isset($_POST['add'])) {

mysql_query("INSERT INTO businesses SET business='{$_POST['business_name']}',description='{$_POST['business_desc']}',emailaddress='{$_POST['business_email']}',website='{$_POST['business_website']}'") or die(mysql_error());

echo '<tr bgcolor="red"><td><b>Business added.</b></td></tr>';

} else {

echo '';

}

?>
</body>
</html>



Here is my display links Page
CODE

<?
$business = $_GET['business'];
global $conn
?>

<?

$query=mysql_query("SELECT business,description,emailaddress, website FROM businesses ");

while($row=mysql_fetch_row($query)) echo '<table width="495"><tr><TD><div align="center"><strong>'.$row[0].'</strong></div><BR></td></TR><TR><td><div align="center">'.$row[1].'</div></td></TR><TR><td><div align="center"><B>E-mail:  </B><a href="mailto:'.$row[2].'?subject=test">'.$row[2].'</a><BR></div></td></TR><TR><TD><div align="center"><B>Website:  </B><a href="http://'.$row[3].'"target="_blank">'.$row[3].'</div></td></tr></table><HR width="400">';

?>

now i have all the info put in to the database and it displays ok, but how do i edit it to change the info, either email, website, description, and/or even delete

Thank you in advance

Kopy
Go to the top of the page
 
+Quote Post
Galahad
post Mar 24 2005, 09:54 PM
Post #2


Neurotical Squirrel
*********

Group: [HOSTED]
Posts: 590
Joined: 4-November 04
From: Novi Sad, Vojvodina
Member No.: 2,127



To edit some data in MySQL database, use UPDATE syntax:

CODE

UPDATE 'businesses' SET 'business' = 'some business', 'description' = 'some description', 'emailaddress' = 'some email', 'website' = 'some website' WHERE 'id' = 'id of data to edit';


Using this code, and of course, modifying 'some something' parts, you can change the data of any record with certain id.

Something that might work instantly for you:
CODE

mysql_query("UPDATE businesses SET business='{$_POST['business_name']}',description='{$_POST['business_desc']}',emailaddress='{$_POST['business_email']}',website='{$_POST['business_website']}' WHERE id='{$_POST['business_id']}'") or die(mysql_error());


Hope this helped smile.gif
Go to the top of the page
 
+Quote Post
kopythat
post Mar 26 2005, 05:54 PM
Post #3


Newbie
*

Group: Members
Posts: 5
Joined: 7-March 05
Member No.: 4,236



thanks galahad

That worked great

now if i want to be able to delete from this database the code should be
CODE
if(isset($_POST['delete'])) {

mysql_query("DELETE FROM businesses SET business='{$_POST['business_name']}',description='{$_POST['business_desc']}',emailaddress='{$_POST['business_email']}',website='{$_POST['business_website']}'") or die(mysql_error());


i have the business id="business_name", but when i delete i get an error
CODE
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET business='sphere',description='',emailaddress='',website=''' at line 1

am i doing something wrong????

ACTUALLY....is there a way to see a list of the links, click on the link to edit/delete and have the info show up on the same form i use and update form there.
as of now i have to retype everything, and as long as i have the buusiness name correct it will update, but not delete.

Thanks in advance
Kopy
Go to the top of the page
 
+Quote Post
Carsten
post Mar 27 2005, 02:22 AM
Post #4


Member [Level 1]
****

Group: Members
Posts: 51
Joined: 22-March 05
Member No.: 4,813



QUOTE(kopythat @ Mar 26 2005, 06:54 PM)
thanks galahad

That worked great

now if i want to be able to delete from this database the code should be
CODE
if(isset($_POST['delete'])) {

mysql_query("DELETE FROM businesses SET business='{$_POST['business_name']}',description='{$_POST['business_desc']}',emailaddress='{$_POST['business_email']}',website='{$_POST['business_website']}'") or die(mysql_error());


i have the business id="business_name", but when i delete i get an error
CODE
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET business='sphere',description='',emailaddress='',website=''' at line 1

am i doing something wrong????
*

If you want to delete something from your database, use the following MySQL query:
CODE
[/code]mysql_query("DELETE FROM businesses WHERE business='{$_POST['business_name']}'")
Go to the top of the page
 
+Quote Post
FaLgoR
post Mar 27 2005, 02:59 AM
Post #5


Super Member
*********

Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



QUOTE(kopythat @ Mar 26 2005, 02:54 PM)
thanks galahad

That worked great

now if i want to be able to delete from this database the code should be
CODE
if(isset($_POST['delete'])) {

mysql_query("DELETE FROM businesses SET business='{$_POST['business_name']}',description='{$_POST['business_desc']}',emailaddress='{$_POST['business_email']}',website='{$_POST['business_website']}'") or die(mysql_error());


i have the business id="business_name", but when i delete i get an error
CODE
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET business='sphere',description='',emailaddress='',website=''' at line 1

am i doing something wrong????

ACTUALLY....is there  a way to see a list of the links, click on the link to edit/delete and have the info show up on the same form i use and update form there.
as of now i have to retype everything, and as long as i have the buusiness name correct it will update, but not delete.

Thanks in advance
Kopy
*



Beware, it's highly recomended that you clean your vars with some function, just like stripslashes, to prevent SQL Injection.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Problem On Mysql "order By"(5)
  2. Php News Script(19)
  3. Increment A Mysql Column(7)
  4. Can You Add Images Into A Mysql Database?(21)
  5. Subquery In Mysql(5)
  6. Creating Profiles In Php/mysql ?(7)
  7. Php Search Engine Script For Mysql Database(11)
  8. Some Mysql Basics(4)
  9. Problem With A Mysql Join(2)
  10. Can Database Column Names Start With A Number?(1)
  11. The Artists Tutorials :mysql Basic Commands(0)
  12. Connecting Php Site To Database(6)
  13. Php And Flash Image Gallery(5)
  14. [mysql]get Id Of Loged In User?(7)
  15. [mysql/php]need Som Basic Help(13)
  1. [php/mysql]id Trouble [resolved](3)
  2. Mysql Won't Update(5)
  3. Php + Mysql Question!(4)
  4. Tools Needed!(9)
  5. Best Sites For Learning Php-mysql(4)
  6. How Do I Connect To Live Database With Php Script?(6)
  7. Ms-access Database Question(3)
  8. Php And Mysql Programming(2)
  9. Best Php And Mysql Editor For Noobs(6)
  10. Html Form!(4)
  11. Mysql Error(3)
  12. Create Table - Mysql Code - Help(1)
  13. Mccodes Registration Edit(2)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 04:06 PM