TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   php and mysql (http://www.talkphp.com/absolute-beginners/2677-php-mysql.html)

kororo203 04-22-2008 05:18 AM

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...

sarmenhb 04-22-2008 06:27 AM

i actually have the same question, your basically asking how php knows which record to delete from the database when you select it.

kororo203 04-22-2008 06:49 AM

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,...

zxt3st 04-22-2008 10:20 AM

Quote:

Originally Posted by kororo203 (Post 13742)
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..

kororo203 04-23-2008 01:53 AM

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

Orc 04-23-2008 02:28 AM

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.

kororo203 04-23-2008 02:44 AM

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..

Orc 04-23-2008 02:47 AM

Quote:

Originally Posted by kororo203 (Post 13782)
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.


All times are GMT. The time now is 03:06 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0