hulika

Author Topic: help with PHP  (Read 1369 times)

Offline rjville

  • Senior Member
  • ***
help with PHP
« on: July 09, 2010, 08:00:53 AM »
sino po marunong mag php/mysql dito? may problem po ako tungkol sa code ko for delete record sa php. sana po may makatulong sakin :D

di ko po alam kung saan ko po hahatiin yung code para sa method action ng form.

ito po yung code ko:

salamat po sa magrereply! :D

---------------------------------

<?php
$host="localhost";
$username="root";
$password="";
$db_name="testing";


// Conn
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM poll order by ID asc";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

?>

<html>
<title>Delete Surveys</title>
<body style="margin-top: 100px;">
<table width="400" border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td><form name="form1" method="post" action="delete.php">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><strong><center>Delete Surveys</center></strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><b>Delete</b></td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['name']; ?></td>
</tr>

<?php
}
?>

<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"> &nbsp; | &nbsp; <a href="admin.php">Back</a></td>
</tr>

<?php
// checkbox validate
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql2 = "DELETE FROM poll WHERE id= '".$rows["id"]."' ";
$result2 = mysql_query($sql2);
}

// if successful redirect to delete_multiple.php
if($result2)
   {
      echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
   }
   
}
mysql_close();
?>

</table>
</form>
</td>
</tr>
</table>
</body>
</html>

Offline ryantetek

  • Veteran Member
  • ****
Re: help with PHP
« Reply #1 on: September 08, 2010, 10:43:25 AM »
kung dun mo lang ipaprocess sa page mo yung query yung form action mo set mo sa wala:

<form name="form1" method="post" action="">

tapos itong line of code mo na:

if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql2 = "DELETE FROM poll WHERE id= '".$rows["id"]."' ";
$result2 = mysql_query($sql2);
}

yung $delete palitan mo nang $_POST['delete']

Ask ko lang kung para saan yung redirect dun sa page na "delete_multiple.php" ?

sana makatulong  :wink:




Offline Hellghast

  • Forum Fanatic
  • ****
Re: help with PHP
« Reply #2 on: September 08, 2010, 11:16:12 PM »
bumagsak ako dito T_T deym bitter memories.....