Jump to content

Recommended Posts

I got the following code :

$username = strip_tags($_POST['username']);
   $password = strip_tags($_POST['password']);
   $email = strip_tags($_POST['email']);
   
   $username = strip_tags($username,"<i></i>");
   $password = strip_tags($password);
   $email = strip_tags($email);

 

But when I later put each varible into the database, it still shows up with <h1> if I type it...

Link to comment
https://forums.phpfreaks.com/topic/152271-solved-how-to-use-strip-tags/
Share on other sites

<?php
if (isset($_SESSION['user']))
{echo "<p align=\"center\" class=\"paragraph\">You are already logged in. Do you maybe want to log        out? If so <a href=\"logout\">click here.</a>";
}
else
{if (isset ($_POST['username']) && ($_POST['password']) && ($_POST['email']) )
  {$username = strip_tags($_POST['username']);
   $password = strip_tags($_POST['password']);
   $email = strip_tags($_POST['email']);
   
   $username = strip_tags($username,"<i></i>");
   $password = strip_tags($password);
   $email = strip_tags($email);
  
   $con = mysqli_connect ("$dbhost","$dbuser","$dbpass","$dbname")
          or die ("Couldn't connect to server");

   $sql = "INSERT INTO users (username, password, email)
	  VALUES
	  ('$_POST[username]', '$_POST[password]', '$_POST[email]')";
   mysqli_query($con,$sql);

   echo "Congratulations you have sucsessfully registered you can now login!";
}

You're inserting the unmodified values in $_POST.

 

Change:

<?php
   $sql = "INSERT INTO users (username, password, email)
	  VALUES
	  ('$_POST[username]', '$_POST[password]', '$_POST[email]')";
?>

to

<?php
   $sql = "INSERT INTO users (username, password, email)
	  VALUES
	  ('$username', '$password', '$email')";
?>

 

You should also use mysql_real_escape_string on those values also:

<?php
   $username = mysql_real_escape_string(strip_tags($_POST['username']));
   $password = mysql_real_escape_string(strip_tags($_POST['password']));
   $email = mysql_real_escape_string(strip_tags($_POST['email']));
?>

 

Also, you're "if" statement is wrong. It should be:

<?php
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email']))
?>

 

 

Ken

Well for one... You don't need to put closing tags in the second argument for strip_tags. So you can leave out </i>

 

Second, this is not related to your question, but..... You should use htmlspecialchars and mysql_real_escape_string on any text strings you plan on inserting into your database. Someone could easily use a register form with that code you posted to inject anything they want into your database.

 

edit-- Ya ken found it

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.