TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-22-2008, 05:18 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default php and mysql

i think it's a bit off topic here vut i guess i'll try..

hm... the situation is that im using mysql for the database...

lets say i have a table...

id name addr
1 xxx vvv
2 sss eee
3 qqq rrr

now my web program uses to add edit and delete data in the database

lets say that i have delete record 1 and insert a new record...


id name addr
4 ooo ppp
2 sss eee
3 qqq rrr

here is my code"


mysql_connect('localhost','','') or die(mysql_error());
mysql_select_db('test') or die(mysql_error());

function delete()
{

}

$sql=mysql_query("SELECT * FROM weh");

echo '<table cellpadding = 8 cellspacing = 0>';
while ($row=mysql_fetch_assoc($sql)) {


echo'<tr>
<td>'.
$row['id'].'
</td>
<td>'.
$row['name'].'
</td>
<td>'.
$row['addr'].'
</td>
<td>
<form>
<input type = "button" value="delete" id = "" name="delete" style=" width:60 px;height:20px"onclick = ""/>
</td>
<td>
<input type= "button" value="edit" id = "" name = "edit" style=" width:60 px;height:20px"onclick = ""/>
</td>
</form>';
$cdel=$cdel+1;
$cedit=$cedit+1;}
echo '</table>';
?>


got the problem up in the input button since i can't figure it out how to determine which data to delete...
hope you understand my explanation thanx...
kororo203 is offline  
Reply With Quote
Old 04-22-2008, 06:27 AM   #2 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

i actually have the same question, your basically asking how php knows which record to delete from the database when you select it.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 04-22-2008, 06:49 AM   #3 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default

hm... i know what to delete but the problem is ho to determine it in that format since i can't name the cation button and they are only generated 1 by 1 by the looping structure,...
kororo203 is offline  
Reply With Quote
Old 04-22-2008, 10:20 AM   #4 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Quote:
Originally Posted by kororo203 View Post
hm... i know what to delete but the problem is ho to determine it in that format since i can't name the cation button and they are only generated 1 by 1 by the looping structure,...
you make a function delete that would delete a certain row in the database. After it has been deleted you again get the rows of the database and loop back again to display the new records.

hope its clear enough..good luck..
zxt3st is offline  
Reply With Quote
Old 04-23-2008, 01:53 AM   #5 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default

er... thats the problem...

coz in my statement i can't figure out what row to delete hehehe
try reading my code...

probably i just skipped and just need an answer for

how can i assign the value of variable to a input in a form.. (is that possible..)

i have tried making the statement like this...

echo '<input type="hidden" value='{$val}' name="hide"/>';

but it returns an error message...

thanx again your help is really appriciated
kororo203 is offline  
Reply With Quote
Old 04-23-2008, 02:28 AM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

PHP Code:

$table 
'' // Your table;
$id $_GET['id']; // Or something else?
if (
!empty(
$_POST['button_delete']) // the delete button
&& isset($_POST['button_delete']
)
{
  
mysql_query("DELETE FROM `$table` WHERE `id` = '$id'");
  

  if (
mysql_affected_rows()) echo "Deleted!"; else die(mysql_error);

Try this, the button_delete post is a button, radio, check, whatever.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Old 04-23-2008, 02:44 AM   #7 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 15
Thanks: 0
kororo203 is on a distinguished road
Default

uh... btw


echo '<input type="hidden" value='{$val}' name="hide"/>';

how can i rephrase my statement to come up with something like this.. because this doesn't work.. and i would like to know ip there are any possible alternate solution for my statement..
kororo203 is offline  
Reply With Quote
Old 04-23-2008, 02:47 AM   #8 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by kororo203 View Post
uh... btw


echo '<input type="hidden" value='{$val}' name="hide"/>';

how can i rephrase my statement to come up with something like this.. because this doesn't work.. and i would like to know ip there are any possible alternate solution for my statement..
Um, are you trying to make a button for deleting something cause just do this:
Code:
echo '<input type="checkbox" name="button_delete"/>';
My code checks to see if the button isset by just ticking it, the value is what you can use as something to be placed inside mysql, so you don't need it really.
__________________
VillageIdiot can have my babbies ;d
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:47 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design