Jump to content

[SOLVED] Display (No Registration Pending)


php?

Recommended Posts

Hi, title basically explains it. How do you i make the script below display "No Registrations Pending" if there are 0 usernames in the database

 

<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
      die('Could not connect: ' . mysql_error());
}

mysql_select_db("mylogin", $con);

if(!isset($_POST['submit'])) {
      if (!$result = mysql_query("SELECT * FROM pending")) {
            die('MySQL Error: ' . mysql_error());
      }
      echo "<form method=\"POST\"";
      while($row = mysql_fetch_array($result)) {
            echo  "<b>" . $row['Username'];
            echo "</b> ";
            echo "<input type=radio name=\"". $row['ID'] ."\" value=1>Accept<br>"; 
            echo " <input type=radio name=\"". $row['ID'] ."\" value=2>Decline<br>";
            echo " <br />";
      }
      echo "<br><input type=submit name=submit value=Submit>";
} else {
      foreach($_POST as $key => $val){
            if($val == 1) {
                  $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'"));
                  echo "Inserting $key into new table....";
                  mysql_query("INSERT INTO accepted SET 
                  Username='".$info['Username']."',
                  Password='".$info['Password']."',
                  Email='".$info['Email']."'"); // Moves user to new table
                  echo "Done!<br>\n";
            }
            echo "Deleting $key from old table....";
            mysql_query("DELETE FROM pending WHERE ID='".$key."'");
            echo "Done!<br>\n";
            /*
            this deletes the user from the table users regardless if you selected
            to accept or deny. If you chose to accept the user, it runs the
            query above first and then this one
            */
      }
}
mysql_close($con);
?>

Link to comment
Share on other sites

Before you retrieve the rows from the sql query, use mysqli_num_rows (or something like that, I don't remember the function name) to see if there are any pending users. Follow that with an if-else statement for the possible options: if there is 0 pending or if there is at least 1.

Link to comment
Share on other sites

heres the code to what duclet was talkin bout ..i think ^^

 

<?php

$a = myql_query("SELECT * FROM `pending`");
$b = mysql_num_rows($a)

if($b == '0')
{
echo 'No pending requests at the moment.';
}
else
{
//anythin below here, is the code that will display pendin requests, if there are any
}

?>

Link to comment
Share on other sites

<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
      die('Could not connect: ' . mysql_error());
}

mysql_select_db("mylogin", $con);

$a = myql_query("SELECT * FROM `pending`");
$b = mysql_num_rows($a);

if($b == '0')
{
echo 'No pending requests at the moment.';
}
else
{
if(!isset($_POST['submit'])) {
      if (!$result = mysql_query("SELECT * FROM pending")) {
            die('MySQL Error: ' . mysql_error());
      }
      echo "<form method=\"POST\"";
      while($row = mysql_fetch_array($result)) {
            echo  "<b>" . $row['Username'];
            echo "</b> ";
            echo "<input type=radio name=\"". $row['ID'] ."\" value=1>Accept<br>"; 
            echo " <input type=radio name=\"". $row['ID'] ."\" value=2>Decline<br>";
            echo " <br />";
      }
      echo "<br><input type=submit name=submit value=Submit>";
} else {
      foreach($_POST as $key => $val){
            if($val == 1) {
                  $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'"));
                  echo "Inserting $key into new table....";
                  mysql_query("INSERT INTO accepted SET 
                  Username='".$info['Username']."',
                  Password='".$info['Password']."',
                  Email='".$info['Email']."'"); // Moves user to new table
                  echo "Done!<br>\n";
            }
            echo "Deleting $key from old table....";
            mysql_query("DELETE FROM pending WHERE ID='".$key."'");
            echo "Done!<br>\n";
            /*
            this deletes the user from the table users regardless if you selected
            to accept or deny. If you chose to accept the user, it runs the
            query above first and then this one
            */
      }
}
mysql_close($con);
}

?>

 

see if it works..

Link to comment
Share on other sites

<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
      die('Could not connect: ' . mysql_error());
}

mysql_select_db("mylogin", $con);

if(!isset($_POST['submit'])) {
 $result = mysql_query("SELECT * FROM pending")
      if (!$result) {
            die('MySQL Error: ' . mysql_error());
      }
      echo "<form method=\"POST\"";
      while($row = mysql_fetch_array($result)) {
            echo  "<b>" . $row['Username'];
            echo "</b> ";
            echo "<input type=radio name=\"". $row['ID'] ."\" value=1>Accept<br>"; 
            echo " <input type=radio name=\"". $row['ID'] ."\" value=2>Decline<br>";
            echo " <br />";
      }
      echo "<br><input type=submit name=submit value=Submit>";
} else {
      foreach($_POST as $key => $val){
            if($val == 1) {
                  $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'"));
                  echo "Inserting $key into new table....";
                  mysql_query("INSERT INTO accepted SET 
                  Username='".$info['Username']."',
                  Password='".$info['Password']."',
                  Email='".$info['Email']."'"); // Moves user to new table
                  echo "Done!<br>\n";
            }
            echo "Deleting $key from old table....";
            mysql_query("DELETE FROM pending WHERE ID='".$key."'");
            echo "Done!<br>\n";
            /*
            this deletes the user from the table users regardless if you selected
            to accept or deny. If you chose to accept the user, it runs the
            query above first and then this one
            */
      }
}
mysql_close($con);
?>

try

Link to comment
Share on other sites

One more thing.. after i delete a username from the database when it displays the message it comes up with this...

 

Deleting 11 from old table....Done!

Deleting submit from old table....Done!

 

 

the name is username... dunno where the 11 and submit came from

Link to comment
Share on other sites

The "11" and "submit" comes from the your POST data. Those are the names for the fields on your form, the radio array and your submit button.

You don't sanitize your input at all, and that's extremely insecure. Someone could inject any type of command on their side and it could be executed on your MySQL server.

Making the loop based off of something other than pure POST data would be best. You need to better define your application's limits.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.