how can i get a token that a user has requested if he/she clicks cancel NOTE the user doesnt have to input anything if cancel is clicked that particular token is deleted from the d.b and the user is redirected to index.php i really dont know where and how to start so bear with me thanks anyway below is the token.php

<?php
error_reporting(0);
session_start();
$token=$_GET['token'];
include("settings.php");
connect();
if(isset ($_POST['submit'])){
$q="select email from tokens where token='".$token."' and used=0";
$r=mysql_query($q);
while($row=mysql_fetch_array($r))
   {
$email=$row['email'];
   }
If ($email!=''){
          $_SESSION['email']=$email;
}
else die("Invalid link or Password already changed  <a href='../index.php'>Click here to go back to the HOME PAGE<a/>");}

$pass=$_POST['password'];
$email=$_SESSION['email'];

if(isset($_POST['password'])&&isset($_SESSION['email']))
{
$q="update registration set password='".md5($pass)."' where email='".$email."'";
$r=mysql_query($q);
if($r)mysql_query("update tokens set used=1 where token='".$token."'");echo "Your password is changed successfully  <a href='../index.php'>Click here to go back to the HOME PAGE<a/>";
if(!$r)echo "An error occurred";
    }

and below is the formreset.php

<h3><strong>Forgot Password</strong></h3>
      <form name="forgot" method="POST" id="forgot" action="includes/reset.php?token=<?php echo $_GET['token']; ?>">
        <div align="center">
          <table width="372" border="0">
            <tr>
              <td width="181"><p>&nbsp;</p>
              <p><strong>Password</strong></p></td>
              <td width="181"><span id="sprytextfield1"><span id="sprypassword1">
              <label for="password2"></label>
              <br />
            <input type="password" name="password" id="password2" />
                <br />
                <span class="passwordRequiredMsg">Your PASSWORD is need</span></span>
<label for="label"></label>
              </span></td>
</tr>
            <tr>
              <td height="22"><p>&nbsp;
              <p><strong>Confirm Password</strong></p></td>
              <td><span id="spryconfirm2">
              <label for="password"></label>
              <span id="spryconfirm1">
              <label for="password1"></label>
              <br />
              <input type="password" name="password1" id="password1" />
              <br />
              <span class="confirmRequiredMsg">Please re-confirm your PASSWORD</span><span class="confirmInvalidMsg">The PASSWORDS don't match.</span></span></span></td>
</tr>
</table>
</div>
    <div align="center">
      <p>&nbsp;</p>
      <table width="372" border="0">
        <tr>
          <th width="132" scope="row"><input type="submit" name="submit" id="submit" value="submit" /></th>
          <th width="113" scope="row"><a href="includes/cancel.php?token=<?php echo $_GET['token']; ?>">Cancel</a></td></th>
          <th width="113" scope="row"><input type="reset" name="clear" id="clear" value="Clear" /></th>
        </tr>
      </table>

    </div>
    <div align="center">
      <table width="372" border="0">
        <tr> </tr>
        <tr> </tr>
      </table>
    </div>thanks in advance
  </form>

so how do i go about this

Member Avatar for LastMitch

if he/she clicks cancel NOTE the user doesnt have to input anything if cancel is clicked that particular token is deleted from the d.b and the user is redirected to index.php i really dont know where and how to start so bear with me thanks anyway below is the token.php

I think you need an id to be delete from the tokens table.

You can try this (it's not tested):

For your token file:

token.php

You need to create a function getToken & deleteToken:

<?php
function getToken() {
$sql = "SELECT * FROM tokens";
if ($stmt = $conn->query($sql)) {
if ($stmt->fetchColumn() > 0) {
$sql = "SELECT * FROM tokens";
foreach ($conn->query($sql) as $row) {
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['email'] . "</td></tr>";
}
}
}

$stmt = null;
$conn = null;
}

function deleteToken($id) {
$id = (int) $id;
$sql = "DELETE FROM tokens WHERE id='$id'";
$stmt = $conn->prepare($sql);
$stmt->execute(array($id));
$conn = null;
}
?>

For your formreset file:

formreset.php

<a href="formreset.php?id="<?php echo $row['id'];?>">Delete</a>

<?php
include('token.php');
deleteToken($_GET['id']);
echo "Content Delete!";
echo "<br>";
echo '<a href="index.php">Return to homepage</a>';    
?>

If the person click delete

<a href="formreset.php?id=".$row['id'] .">Delete</a>

it will delete the token.

I hope that make sense.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.