NameSilo

Script not working

Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
12
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:
<?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>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
What is your problem exactly? What isn't working? Anyway..i've corrected a couple things that _could_ cause it to not work:
PHP:
<?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>
 
0
•••
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ยฃ
 
0
•••
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
 
0
•••
Thanks, does anyone know how to solve the other bit with it coming up again?
 
0
•••
If it automatically refreshes it should get rid of that problem...
 
0
•••
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?
 
0
•••
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

Add that.. I think it'll work. :X
 
0
•••
where do i put that?
 
0
•••
Anywhere inbetween <head> and </head>
 
0
•••
Thanks dan, all works now.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back