MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 5th, 2000, 02:31 AM
Yokhannan Yokhannan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 2 Yokhannan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi All.

First time poster at this forum!

Great to see the support here.

Well, my question is a newbie question, that I'm sure is pretty easy, but I just can't figure it out!

I've got a simple PHP & MySQL database script that I'm working with. I have figured out how to 'add' and 'view' the data in the database, but I can't figure out how to delete the data.

To get to the code here...

Here are my variables: (not real, just for example sake)


$hostname = "YourHostName";
$username = "YourUsername";
$password = "YourPassword";
$userstable = "LinksTable";
$dbName = "YourDatabaseName";

Here are my tables fields:

ID
LinkName
LinkURL
LinkDescription
email
UserName
UserPassword (which I don't use yet!)


Ok, with that stuff out of the way...

I am in need of the syntax code to be able to place within my admin.php3 file to be able to delete a line from within the database table.


Ok, now here is my complete admin.php3 code:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<html>
<head>
<title> Links Database - Admin Page </title>
</head>
<body text=black link=red vlink=red alink=yellow>

<?

/* declare variables */
$hostname = "YourHostName";
$username = "YourUsername";
$password = "YourPassword";
$userstable = "LinksTable";
$dbName = "YourDatabaseName";
$VLDir = "http://www.PathToYour/Diretory";
// set this to the directory where your main files are!
// DO NOT include a closing "/" on the $VLDir variable!

/* make connection to database */
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");

@mysql_select_db( "$dbName") or die( "Unable to select database");

/* Select all from within database */
$query = "SELECT * FROM $userstable";

$result = MYSQL_QUERY($query);

/* How many users are there? */
$number = MYSQL_NUMROWS($result);

/* Print these results to the screen */
$i = 0;

IF ($number == 0) :
PRINT "<P><font face=Verdana Size=1><a href="$VLDir/insert.php3"><B>Add A Link</B></a>";
PRINT "<p><br>";
PRINT "<I><B>There Are Presently No Links!</B></I>";
ELSEIF ($number > 0) :
PRINT "<P><font face=Verdana Size=1>Total Number of Links: $number | <a href="$VLDir/insert.php3"><B>Add Your Link</B></a>";
PRINT " <hr color=black width=60% align=left><BR>";
WHILE ($i < $number):
$LinkName = mysql_result($result,$i,"LinkName");
$LinkURL = mysql_result($result,$i,"LinkURL");
$LinkDescription = mysql_result($result,$i,"LinkDescription");
$email = mysql_result($result,$i,"email");
$UserName = mysql_result($result,$i,"UserName");
$UserPassword = mysql_result($result,$i,"UserPassword");
PRINT "<font face=Verdana Size=1><B>Site Name:</B> $LinkName<BR>";
PRINT "<font face=Verdana Size=1><B>Site URL:</B> <a href="$LinkURL" target="_blank">$LinkURL</a><BR>";
PRINT "<font face=Verdana Size=1>S<B>ite Description:</B> $LinkDescription<BR>";
PRINT "<font face=Verdana Size=1><B>* User Name:</B> $UserName<BR>";
PRINT "<font face=Verdana Size=1><B>* User Password:</B> $UserPassword<BR>";
PRINT "<font face=Verdana Size=1><B>* Email address:</B> <a href="mailto:$email">$email</a><BR>";
PRINT "<BR><BR>";
$i++;
ENDWHILE;
PRINT "</CENTER>";
ENDIF;
?>
<p><br>
<hr width=40% align=left color=black>
Copyright © 4CM, 1996-2000 - <a href="http://www.4cm.com" target="_blank">www.4cm.com</a><br>
Links Database Powered By: <a href="http://www.4cm.com" target="_blank">www.4cm.com</a>
</body>
</html>
[/code]

Can anyone here help me with the next step of this admin page... I need a way to be able to "DELETE" a given entire.

I would be really grateful!

(sure hope all this makes sense!)

Later All.

------------------
--- -- -- --- -- -- ---
John B. Abela
Owner, 4CM
http://www.4cm.com/
URL

Reply With Quote
  #2  
Old May 5th, 2000, 07:15 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

i am writing a simple delete script.

just try in this way...

$deleteresult = mysql_query ("DELETE FROM tablename WHERE id = '$id'");

if (mysql_affected_rows($deleteresult) >= 1)
{ print "Successfully deletedn";
}
else
{
print "not deleted any rows";
exit;
}

------------------
SR -
shiju.dreamcenter.net

Reply With Quote
  #3  
Old May 5th, 2000, 12:37 PM
Yokhannan Yokhannan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 2 Yokhannan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the bit of code!

However, I'm still unsure what to do.

Should I place the code you wrote in a seperate file? (for instance: delete.php3)??

Or should I include it within the existing "admin.php3" file that I have?

And, either way, what would the html code be to call it?

Sorry for the real basic questions...

Later.

------------------
--- -- -- --- -- -- ---
John B. Abela
Owner, 4CM
http://www.4cm.com/
URL

Reply With Quote
  #4  
Old May 6th, 2000, 01:53 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
Yokhannan,

you can include that delete script inside the "admin.php3" or you can create a separate delete.php3.either way it should work fine.

include the following html tag in your admin.php3(or where ever you want to place it).

<b>Delete a link:</b>
<form action="delete.php3" method="post">
Link name<input type="text" name="link_name">
<input type="submit" name="delete" value="Remove Now">
</form>

In delete.php3:


if($delete=="Remove Now"){
$deleteresult = mysql_query ("DELETE FROM tablename WHERE linkname = '$link_name'");

if (mysql_affected_rows($deleteresult) >= 1)
{ print "Link has been removed successfullyn";
}
else
{
print "Error !! couldn't remove the link";
exit;
}
}


if you are using this delete script in admin.php3 then use the form html tag

<form action="admin.php3" method="post">
---
--

and use delete script inside the admin.php3.


(you can modify the above script according to your requirment)

Hope this may help you to finish your assainment successfully.

GOOD LUCK!!!!!





------------------
SR -
shiju.dreamcenter.net

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Need Help With: mysql_query to delete *

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap