I have this code that I want that $X to be updated in the form, so when I press the +1 button it just keep going adding 1 to the form
<html>
<head>
<title>7mada</title>
</head>
<body>
<?php $X = 7 ;?>
<form method="POST" >
<table border="0" width="60%">
<tr> <td width ="30%"> Number: </td><td><input type="test" name="newname" value="<?php echo $X ;?>" readonly></td></tr>
</table>
<input name="save" type="submit" value="+1"/>
</form>
<?php
if($_POST){
if($_POST['save'] == "+1"){
$_POST['newname']++;
echo $_POST['newname'];
$X = $_POST['newname'];
}
}else{echo "say smth";}
?>
</body>
</html>
thanks.
Hey Samy this is the answer for your question :D :D
It completely ignores HTML output, therefore PHP can't interact with events that should be javascript.
you have two options:
1-Do it in Javascript, Live
2-Do it in PHP, requires refresh
If you want to do it in JavaScript, you'd do this:
<html>
<body>
<button onclick="add()">Add</button>
<div id="showIt"><script type="text/javascript">document.write(x);</script></div>
</body>
<head>
<title></title>
<script type="text/javascript">
var x = 0;
function add() {
x++;
document.getElementById('showIt').innerHTML = x;
}
</script>
</head>
</html>
or in PHP:
<?php
session_start();
$_SESSION['x'] = ((isset($_SESSION['x'])) ? $_SESSION['x'] : 0);
if(isset($_GET['add'])){
$_SESSION['x']++;
}
?>
<html>
<head>
<title></title>
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="submit" name="add" value="add" />
</form>
<?php
echo $_SESSION['x'];
?>
</body>
</html>
I hope this helps you,
Mahmoud Elsaadany
Related
accidently adding space character( ) on md5 string when pasting password after generating a md5 encryption for my samp login page..
is there a way to accesing with broken code like this:
<?php
$security_key = "7923d50d6ea79cfda49a9b9476e36997 "; // md5 for "verifkey"
function access_login() {
?>
<!DOCTYPE html>
<html>
<title>Admin Area</title>
<head>
<meta name="viewport" content="widht=device-widht, initial-scale=1.0"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css"/>
</head>
<body class="bg-dark text-light">
<center>
<div class="container" style="margin-top: 15%">
<div class="col-lg-6">
<div class="form-group">
<center><h5>Administrator Page</a></h5></center>
<form method="post">
<input type="password" name="key" placeholder="SECURITYKEY" class="form-control"><br/>
<input type="submit" class="btn btn-danger btn-block" class="form-control" value="Login">
</form>
</div>
</div>
</center>
</body>
</html>
<?php
exit;
}
if(!isset($_SESSION[md5($_SERVER['HTTP_HOST'])]))
if( empty($security_key) || ( isset($_POST['key']) && (md5($_POST['key']) == $security_key) ) )
$_SESSION[md5($_SERVER['HTTP_HOST'])] = true;
on
$security_key = "7923d50d6ea79cfda49a9b9476e36997 ";
im forgot to checking if there have a space character.
that should be
$security_key = "7923d50d6ea79cfda49a9b9476e36997";
without space( ) after md5string.
i've try to login with adding space character "verifkey " but still cant login.
anyone can help?
I m so much confused about how to create docx files while I submitting the data from my given form and also I need to save that data into database.
<html>
<head>
<title>Create Docx File</title>
<script>
$('#myButton').click(function(){ var s = $('#myHTMLDiv').html($('#htmlstring').val(s); );
</script>
</head>
<body>
<h3>User Details</h3>
<form method="post" action="gendocx.php">
Enter Name:<input type="text" name="htmlstring" id="htmlstring" value="">
<input type="submit"id="MyButton" value="Generate Docx">
</form>
</body>
</html>
gendocx.php
<?php
require_once('vendor/autoload.php');
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $_POST['htmlstring']);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="myfirstdocfile.docx"');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');
?>
This is my code. I am getting an unidentified index error for the name of the file i.e 'userfile'. It's a very basic code but I don't get where I am going wrong.
<!DOCTYPE html>
<html>
<head>
<title>
File Upload
</title>
</head>
<body>
<h2> Your file contains : <br></h2>
<?php
$handle = fopen($_FILES['userfile']['tmp_name'], "r");
while (!feof($handle)) {
$text = fgets($handle);
echo $text, "<br/>";
}
fclose($handle);
?>
</body>
</html>
This should work to print file content
<!DOCTYPE html>
<html>
<head>
<title>
File Upload
</title>
<form name="myform" action="" method="post" enctype="multipart/form-data">
<input type="file" name="userfile"/>
<input type="submit" name="submit" value="submit">
</form>
</head>
<body>
<h2> Your file contains : <br> </h2>
<?php
$file = file_get_contents($_FILES['userfile']['tmp_name']);
echo $file;
?>
</body>
</html>
How to genera dynamic table it constant asp:textbox and sum other controls, when click on button in javascript.
Try This Code:
<html>
<head>
<script>
function changeLink()
{
document.getElementById('myAnchor').innerHTML="<table style='width: 100%'><tr><td> <input type='Text'/></td></tr></table>";
}
</script>
</head>
<body>
<div id="myAnchor">
</div>
<input type="button" onclick="changeLink()" value="Change link">
</body>
</html>
The login form won't redirect to the cloud.php.. i hav created session.. may i know wat is the problem..
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>MyCloud-Login</title>
<?php
//$un = 'abc';
//$pw = 'abc';
$mysql_hostname = "localhost";
$mysql_database = "mycloud_zymichost_register";
$mysql_user = "user";
$mysql_password = "pass";
$conn = mysql_connect($mysql_hostname,$mysql_user,$mysql_password);
mysql_select_db($mysql_database, $conn );
if (isset($_POST['login'])){
//$un = $_POST['name'];
$em = $_POST['email'];
$pw = $_POST['pass'];
//$un = mysql_real_escape_string($un);
$em = mysql_real_escape_string($em);
$pw = mysql_real_escape_string($pw);
$query = "SELECT * FROM Register WHERE email = '$em' AND pass = '$pw'";
//$query = "INSERT INTO Register (name,email,pass) VALUES ('$un','$em','$pw')";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
// Check username and password match
if (mysql_num_rows($result) == 1) {
// Set username session variable
$_SESSION['email'] = $_POST['email'];
// Jump to secured page
header('Location: cloud.html');
}
else {
// Jump to login page
header('Location: login.php');
}
}
?>
<link href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
</head>
<?php
// Inialize session
session_start();
// Check, if user is already login, then jump to secured page
if (isset($_SESSION['email'])) {
header('Location: cloud.php');
}
?>
<body>
<div data-role="page" id="login">
<div data-role="header">
<h1>My Cloud</h1>
</div>
<div data-role="content">Login
<form action="login.php" method="get" name="form">
<div data-role="fieldcontain">
<label for="email">Email:</label>
<input type="text" name="email" id="email" value="" />
</div>
<div data-role="fieldcontain">
<label for="pass">Password:</label>
<input type="password" name="pass" id="pass" value="" />
</div>
<button type="submit" data-theme="b" name="login" value="submit-value">Login</button>
</form>
</div>
<div data-role="footer">
<h4>Henry</h4>
</div>
</div>
</body>
</html>
The login form won't redirect to the cloud.php.. i hav created session.. may i know wat is the problem..
You cannot call the header function after any output is sent. Visit http://www.w3schools.com/php/func_http_header.asp
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>MyCloud-Login</title>
I seem to remember even blank lines causing issues with this as well. Move the top piece and get rid of blank lines and try again. There may be other issues but that is one of them.