0

So guys i'm trying to get a number from the input tag as shown below:

<form method="post" action="#">
  <input type="number" name="delete" id="delete" maxlength="2" placeholder="Enter year in 2 digits" pattern="[0-9][0-9]" required="required">
  <br> <br>
  <div class="input-group">
        <input type="submit" class="btn btn-primary  btn-flat" value="Delete" name="del" id="del" />  
  </div>
</form>

After getting the value from the input tag, I use php to concatenate it with another string so I can obtain a proper output

if(isset($_POST['del']))
{
echo("<script>confirm('Are you sure?<br>Once deleted accounts cannot be recovered.')</script>");
$d=$_POST['delete'];
$yr='4so'.'$d'.'%';
echo ("<script>alert('$yr')</script>");
$query=mysqli_query($con,"delete * from student where usn like $yr;");
echo("<script>alert('Deleted.')</script>")
}

When I load my page containing this code the alert automatically displays, without me clicking the button at all.

Also another main issue I face is that when i click submit it doesnt display the value of $yr properly when using echo statement. In the image below if i enter 23 as input, in the alert it should display 4so.23.% but it displays 23 as %d

Adhip Rebello
  • 135
  • 2
  • 12
  • `$yr='4so'.'$d'.'%';`..... why the quotes (`'`) around `$d`? That simply tells PHP to treat it as a literal `$` character followed by a `d` character, which results in the output that you're getting – Mark Baker May 03 '16 at 14:29
  • 1
    @PaulCrovella - or even better, no quotes required at all around `$d` in that concatenation – Mark Baker May 03 '16 at 14:31

0 Answers0