[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-12-2006, 11:46 PM   #1 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
Script not working

I am making myself a tutorial management script for a tutorial site like good-tutorials. im sure everything works except the accept script, so if you know whats wrong please say, i will donate you some rep.



Thanks

Steven

Code:

PHP Code:

<?php

error_reporting
(E_ALL ^ E_NOTICE);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Untitled Document</title>

</head>



<body>

<?php

mysql_connect
("localhost", "root", "");

mysql_select_db("tutorials");

$query = "SELECT url, id FROM tutorials WHERE status = 'no'";

$result = @mysql_query($query);

$num = mysql_num_rows ($result);



if (
$num > 0) {

echo
'<table>';

while (
$row = mysql_fetch_array($result)) {

$id = $row[1];

echo
"<tr>

<td></td>

<td>$row[1]</td><form action=edit.php method=post>

<td><input type=hidden value=$row[1] name=ID> </td>

<td><select name=action><option value=Delete>Delete<option value=Approve>Approve</select><input type=submit value=Submit name=submit></td></form>

</tr>"
;

}



echo
'</table>';

} else {

echo
"The query didnt find any results.";

}

if (
$_POST['ID'] && $_POST['submit'] && $_POST['action']) {

$id2 = $_POST['ID'];

if (
$_POST['action'] == Delete) {

$query2 = "DELETE FROM tutorials WHERE id='".$id2."' LIMIT 1";

$result2 = @mysql_query($query2);

} else {

$query3 = "UPDATE tutorials SET status='yes' WHERE id='".$id2."' LIMIT 1";

$result3 = @mysql_query($query3);

}



}

?>

</body>

</html>
Xyzer is offline  
Old 05-13-2006, 12:35 AM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services

 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
What is your problem exactly? What isn't working? Anyway..i've corrected a couple things that _could_ cause it to not work:
PHP Code:
<?php

error_reporting
(E_ALL ^ E_NOTICE);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<?php

$db
= mysql_connect("localhost", "root", "");
mysql_select_db("tutorials", $db);

$query = "SELECT url, id FROM tutorials WHERE status = 'no'";

$result = @mysql_query($query);

$num = mysql_num_rows($result);

if(
$num > 0)
{
  echo
'<table>';

  while(
$row = mysql_fetch_array($result))
  {
    
$id = $row[1];
    echo
"<tr>
    <td></td>
    <td>$row[1]</td>
    <form action=edit.php method=post>
    <td><input type=hidden value=$row[1] name=ID> </td>
    <td>
    <select name=action>
      <option value=Delete>Delete</option>
      <option value=Approve>Approve</option>
    </select>
    <input type=submit value=Submit name=submit></td>
    </form>
    </tr>"
;
  }
  echo
'</table>';
}
else
{
  echo
"The query didnt find any results.";
}

if(isset(
$_POST['submit']) && $_POST['submit'] != '')
{
  
//never trust user input ;)
  //even setting values yourself, select, etc..it can be injected
  
$action = trim(strip_tags($_POST['action']));
  
$id2 = intval($_POST['ID']);
  
  if(!empty(
$id) && !empty($action))
  {
    if(
$action == 'Delete')
    {
      
$query2 = "DELETE FROM tutorials WHERE id='".$id2."' LIMIT 1";
      
$result2 = @mysql_query($query2);
    }
    else
    {
      
$query3 = "UPDATE tutorials SET status='yes' WHERE id='".$id2."' LIMIT 1";
      
$result3 = @mysql_query($query3);
    }
  }
  else
  {
    
//hmm, that shouldn't happen
  
}
}
?>

</body>
</html>
__________________
Eric is offline  
Old 05-13-2006, 12:44 AM   #3 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
Thanks, i only have one other problem, how can i make it so after i click submit and it does it, it refreshes the page so that that option will go becuase it does when i manually refresh.

ok, another problem is that when i click delete or approve and refresh it comes up again with a different id and its only in the database once. Please help for NP£
Xyzer is offline  
Old 05-13-2006, 09:57 AM   #4 (permalink)
NamePros Member
 
Join Date: Apr 2006
Location: Central PA
Posts: 98
0.00 NP$ (Donate)

NonProphet is on a distinguished road


Code:
echo '<meta http-equiv="Refresh" content="0; url=WEBSITE.php">';
Put that at the bottom of each if statement and it will automatically refresh for you
NonProphet is offline  
Old 05-13-2006, 10:00 AM   #5 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
Thanks, does anyone know how to solve the other bit with it coming up again?
Xyzer is offline  
Old 05-13-2006, 10:01 AM   #6 (permalink)
NamePros Member
 
Join Date: Apr 2006
Location: Central PA
Posts: 98
0.00 NP$ (Donate)

NonProphet is on a distinguished road


If it automatically refreshes it should get rid of that problem...
NonProphet is offline  
Old 05-13-2006, 10:03 AM   #7 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
oh ok, ill try it and get back to you.

right now the only problem is if theres several waiting to be moderated i accept one, it refreshes and the rest disapear until i refresh a few time, What can be causing this?
Xyzer is offline  
Old 05-13-2006, 02:39 PM   #8 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

Add that.. I think it'll work. :X
Dan is offline  
Old 05-13-2006, 02:41 PM   #9 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
where do i put that?
Xyzer is offline  
Old 05-13-2006, 02:53 PM   #10 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
Anywhere inbetween <head> and </head>
Dan is offline  
Old 05-13-2006, 03:01 PM   #11 (permalink)
Senior Member
 
Xyzer's Avatar
 
Join Date: Aug 2005
Location: United Kindom
Posts: 1,506
90.70 NP$ (Donate)

Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all

Tsunami Relief AIDS/HIV
Thanks dan, all works now.
Xyzer is offline  
Closed Thread


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

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 10:50 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85