Space in value of input type="submit"

<?php
	session_start();
	include("connection.php");
	if(mysqli_connect_error()) echo "db connection error";
	$userid=$_SESSION['id'];
	if($_POST['submit']){
		if($_POST['currentpassword']!="" AND $_POST['newpassword']!="" AND $_POST){
			
			$_SESSION['id'];
			$query="SELECT * FROM `users` WHERE  id=$userid";
			$result=mysqli_query($link,$query);
			$res=mysqli_fetch_array($result); 
			$oldpassword=$res[2];
			
			if($oldpassword!=$_POST['currentpassword']){
				$error.= "please check your old password";
			}
			if($_POST['newpassword']!=$_POST['retypenewpassword']){
				$error.= "Password didn't matched";
			}
			if(!strlen($_POST['newpassword'])<8 && !preg_match('`[A-Z]`',$_POST['newpassword'])){
				$error.="password must atleast 8 character and have one capital letter ";
			}
			if($_POST['newpassword']==$oldpassword){
				$error.="You have recently used this password.";
			}
			if($error){
				echo "there are error".$error;
			}
			else if(!$error){
				$query="UPDATE `users` SET password='".mysqli_real_escape_string($link,$_POST['newpassword'])."' WHERE id=".$res['id']."" ;
				
				if(mysqli_query($link,$query)){
					echo "password changed successfully";
						$ButtonDisp="go back";
						echo "<input type=".submit." value="go back" ></input>";
				}else{
					$error.="sorry!some error occured";
				}
		
			}
				
			 
			 
			 
			 
			
			
		}
		
	}


?>
<!DOCTYPE html>
<html lang="en">
<html>
	<head>
	
	</head>
	<body>
	<form method="post">
		<input name="currentpassword" value="<?php echo addslashes($_POST['currentpassword']) ?>" ></input><br />
		<input name="newpassword" value="<?php echo addslashes($_POST['newpassword']) ?>"></input><br />
		<input name="retypenewpassword"value="<?php echo addslashes($_POST['retypenewpassword']) ?>"></input><br />
		<input name="submit" type="submit"  ></input>
		
	
	</form>
	</body>
</html>

Welcome to the forums satyamk134.

Is there a question you want to ask about this code?
You must explain what you are trying to achieve and what you are having a problem with.

I want the value of button to be go back
but it’s showing only go.
I tried to concatenate also like value=“.‘go’.’ ’ .‘back’.”
But its not working.

It should be OK to write the value normally with the space, like:-

<input name="submit" type="submit" value="Go Back">

Also note that the input element is self-closing, it does not require the closing tag (</input>).

If I remove the echo before the input tag like I have done then it throws error

Parse error: syntax error, unexpected ‘<’ in C:\xampp\htdocs\mysql\mysqlproject\changepassword.php on line 36
.So what should I do?
So I am not able to use

Sorry, I was looking at the wrong input. You mean the one echoed out in the php:-

echo "<input type=".submit." value="go back" ></input>";

The problem here is the quote marks. The easiest way would be to put the string in single quotes, so the double quotes do not exit the string.

echo '<input type="submit" value="go back">';

Alternatively you could escape the double quotes:-

echo "<input type=\"submit\" value=\"go back\" >";

Sorry but these don’t work.
When I used the first one the type button becomes the input itself.
and in the second one I got the error
Parse error: syntax error, unexpected '' (T_NS_SEPARATOR), expecting ‘,’ or ‘;’ in C:\xampp\htdocs\mysql\mysqlproject\changepassword.php on line 36.

Can you show your revised code then? Either of these should work without any trouble.

<?php
	session_start();
	include("connection.php");
	if(mysqli_connect_error()) echo "db connection error";
	$userid=$_SESSION['id'];
	if($_POST['submit']){
		if($_POST['currentpassword']!="" AND $_POST['newpassword']!="" AND $_POST){
			
			$_SESSION['id'];
			$query="SELECT * FROM `users` WHERE  id=$userid";
			$result=mysqli_query($link,$query);
			$res=mysqli_fetch_array($result); 
			$oldpassword=$res[2];
			
			if($oldpassword!=$_POST['currentpassword']){
				$error.= "please check your old password";
			}
			if($_POST['newpassword']!=$_POST['retypenewpassword']){
				$error.= "Password didn't matched";
			}
			if(!strlen($_POST['newpassword'])<8 && !preg_match('`[A-Z]`',$_POST['newpassword'])){
				$error.="password must atleast 8 character and have one capital letter ";
			}
			if($_POST['newpassword']==$oldpassword){
				$error.="You have recently used this password.";
			}
			if($error){
				echo "there are error".$error;
			}
			else if(!$error){
				$query="UPDATE `users` SET password='".mysqli_real_escape_string($link,$_POST['newpassword'])."' WHERE id=".$res['id']."" ;
				
				if(mysqli_query($link,$query)){
					echo "password changed successfully";
						$ButtonDisp="go back";
						echo '<input type="submit" value="Go back" />';	
				}else{
					$error.="sorry!some error occured";
				}
		
			}
				
			 
			 
			 
			 
			
			
		}
		
	}


?>
<!DOCTYPE html>
<html lang="en">
<html>
	<head>
	
	</head>
	<body>
	<form method="post">
		<input name="currentpassword" value="<?php echo addslashes($_POST['currentpassword']) ?>" ></input><br />
		<input name="newpassword" value="<?php echo addslashes($_POST['newpassword']) ?>"></input><br />
		<input name="retypenewpassword"value="<?php echo addslashes($_POST['retypenewpassword']) ?>"></input><br />
		<input name="submit" type="submit"  ></input>
		
	
	</form>
	</body>
</html>

I can’t see anything specifically wrong with that line. In the event of a problem with the submission, though, where is the rest of the form around the button you’re creating on line 36? How does anything know what to do when someone clicks the “go back” button? And there’s no opening HTML or body tags for it either, unless it’s in your connection.php file for some reason, which might in itself be enough to stop it displaying properly.

1 Like

When I include my index.html file with .
Its works fine.
My only issue is with the html which is not reflecting properly…
So…if you can fix that display issue then it will be great help to me.

I’m struggling to see anything specifically wrong with that line of code, other than without the opening html tags it probably won’t draw a button. But if you have that in some included code, then it can’t be that.

/* I have put the out of condition can you now please help me get rid of this space problem.
If I put double quotes instead of single and concatenate it then also the space then the same issue.
Please look after my code at the php section last echoed button.*?

<?php
	session_start();
	include("connection.php");
	if(mysqli_connect_error()) echo "db connection error";
	$userid=$_SESSION['id'];
	if($_POST['submit']){
		if($_POST['currentpassword']!="" AND $_POST['newpassword']!="" AND $_POST){
			
			$_SESSION['id'];
			$query="SELECT * FROM `users` WHERE  id=$userid";
			$result=mysqli_query($link,$query);
			$res=mysqli_fetch_array($result); 
			$oldpassword=$res[2];
			
			if($oldpassword!=$_POST['currentpassword']){
				$error.= "please check your old password";
			}
			if($_POST['newpassword']!=$_POST['retypenewpassword']){
				$error.= "Password didn't matched";
			}
			if(!strlen($_POST['newpassword'])<8 && !preg_match('`[A-Z]`',$_POST['newpassword'])){
				$error.="password must atleast 8 character and have one capital letter ";
			}
			if($_POST['newpassword']==$oldpassword){
				$error.="You have recently used this password.";
			}
			if($error){
				echo "there are error".$error;
			}
			else if(!$error){
				$query="UPDATE `users` SET password='".mysqli_real_escape_string($link,$_POST['newpassword'])."' WHERE id=".$res['id']."" ;
				
				if(mysqli_query($link,$query)){
					echo "password changed successfully";
						$ButtonDisp="go back";
						
				}else{
					$error.="sorry!some error occured";
				}
		
			}
				
			 
			 
			 
			 
			
			
		}
		
	}

echo "<input type=".submit." value=".Go.'    ' .back." />";	
?>
<!DOCTYPE html>
<html lang="en">
<html>
	<head>
	
	</head>
	<body>
	<form method="post">
		<input name="currentpassword" value="<?php echo addslashes($_POST['currentpassword']) ?>" ></input><br />
		<input name="newpassword" value="<?php echo addslashes($_POST['newpassword']) ?>"></input><br />
		<input name="retypenewpassword"value="<?php echo addslashes($_POST['retypenewpassword']) ?>"></input><br />
		<input name="submit" type="submit"  ></input>
		
	
	</form>
	</body>
</html>

I’m a bit surprised that works at all without an “action”

<form method="post">

https://www.w3.org/TR/html401/interact/forms.html#h-17.3

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
<!ATTLIST FORM
  %attrs;                              -- %coreattrs, %i18n, %events --
  action      %URI;          #REQUIRED -- server-side form handler --

Can you point out where the mistake is?
It would be a great help if you fixed that.

What @Mittineague is saying is that your form attribute in the first-level form, where you ask for the new password, doesn’t specify what to do when the user presses the button. You would normally specify that in the “action” parameter:

<form method="post" action="mypage.php">
..or..
<form method="post" action="">  // to load the same page file

I did see that there was no action, and presumed that was some kind of shorthand to reload the same page.

I don’t see anything outputting the button any more. Is there something missing from your post? Also if you start the code with [code] on a line by itself, and then end it with [/code] also on a line by itself, the formatting will look better.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.