Current location: Hot Scripts Forums » General Web Coding » JavaScript » Deleteing from mysql table

Deleteing from mysql table

Reply
  #1 (permalink)  
Old 07-06-09, 02:00 PM
playa4002 playa4002 is offline
Newbie Coder
 
Join Date: Feb 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Deleteing from mysql table

Hi Im not sure if this should be in javascript or php, kinda same problem. I am working on a ajax script to auto-update requests (for radio) and I am having trouble getting them to delete my old method before this isn't working now any help would be greatly appreciated.

And this current one isnt working or Im doing something wrong lol heres the codes:

boo.php

Code:
<table width="675" border="1"> 
<tr><td>ID</td><td>Song</td><td>Artist</td><td>Requested by</td><td>IP</td><td>Delete</td></tr> 
<?php

// Configure connection settings

$db = '-';
$db_admin = '-';
$db_password = '-';
$tablename = 'request_song';

// Title

echo "Contents of the table:";

// Connect to DB

$sql = mysql_connect("localhost", $db_admin, $db_password)
or die(mysql_error());

mysql_select_db("$db", $sql);

// Fetch the data

$query = "SELECT * FROM request_song ORDER BY id ASC";
$result = mysql_query($query);

// Delete function
if(isset($_GET['delreq']))
{
 
   $query = mysql_query("DELETE FROM request_song WHERE id = '{$_GET['id']}'")or die('Error : ' . mysql_error());  
 
   header('Location: ' . $_SERVER['HTTP_REFERER']);
   exit;
}
// Return the results, loop through them and echo

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if ($_GET['del']) { 
$delete = $_GET['del']; 
$delque = "DELETE FROM request_song WHERE id='{$delete}'"; 
mysql_query($delque); 
} 
$id = $row['id']; 
echo "<tr><td>{$row['id']}</td><td>{$row['song']}</td><td>{$row['artist']}</td><td>{$row['name']}</td><td>{$row['ip']}</td><td><a href=\"javascript:delreq({$row['id']})\">Delete</a></td></tr>";
}
?>
ajax.js

Code:
// Customise those settings

var seconds = 10;
var divid = "timediv";
var url = "boo.php";

////////////////////////////////
//
// Refreshing the DIV
//
////////////////////////////////

function refreshdiv(){

// The XMLHttpRequest object

var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}

// Timestamp for preventing IE caching the GET request

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// The code...

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
setTimeout('refreshdiv()',seconds*1000);
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}

// Start the refreshing process

var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv()',seconds*1000);
}


function delreq(id)
{
   if (confirm("Are you sure you want to delete"))
   {
      window.location.href = 'boo.php?delreq=' + id;
   }
}
and finally index.html
Code:
<script src="ajax.js"></script>

<strong>Current Requests(Every 10 Seconds):</strong>

<script type="text/javascript"><!--
refreshdiv();
// --></script>
<div id="timediv"></div>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-07-09, 01:20 AM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
are you actually storing the id in the DB with {}'s around it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-07-09, 04:08 AM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,531
Thanks: 5
Thanked 17 Times in 16 Posts
Quote:
Originally Posted by =OTS=G-Man View Post
are you actually storing the id in the DB with {}'s around it?
PHP: Strings - Manual
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-07-09, 07:28 PM
=OTS=G-Man =OTS=G-Man is offline
Newbie Coder
 
Join Date: Jun 2009
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico View Post
Thanks for that, had never seen that used in PHP. Guess I'm old fashion using ".$var." still
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to search im mysql table morten44 Script Requests 0 06-13-09 07:02 PM
Syntax Error Nikas Database 4 05-15-08 11:48 AM
MYSQL database countll Database 2 06-19-07 05:20 PM
Inserting data to mysql table using php Tjobbe PHP 4 09-28-06 07:37 AM
Newbie MySQL fccolon PHP 2 03-16-04 11:54 AM


All times are GMT -5. The time now is 05:42 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.