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>
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');
?>
Forgive my ignorance, because I'm pretty new to programing. I've been beating out my brains on this one. Can anyone tell me why this doesn't work? I know it will be something dumb:
addText(){
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button>
Original Content
</p>
</body>
</html>
You haven't declared addTest() as a function. Should be:
<script>
function addTest() {
...
}
</script>
function addText() {
document.getElementById("demo").innerHTML = "New Content";
}
<!DOCTYPE html>
<html>
<head>
<title>InnerHTML Example</title>
</head>
<body>
<p id="demo">
<Button onclick="addText()">Change</Button> Original Content
</p>
</body>
</html>
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
I have connected to my database to edit stored records and I’ve used a variable for the errors.
When I try to submit with empty fields it redirects and displays the changes have been saved message instead of displaying empty fields message
I’m sure there is something wrong with the structure of my loop and I am putting something in the wrong place?
<?php
//session_start();
// connect to the database
include('connect.php');
$message = $_GET['message'];
// check if the form has been submitted then process it
if (isset($_POST['submit']))
{
// Get data from table
//set the id manually for test purposes
$id = "429";
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
// check for empty fields and display error message
if (empty($forename) &&!empty($surname) &&!empty($username) &&!empty ($password) &&!empty ($email))
{
$message = "Please enter data in all fields" ;
header("Location: edit.php?message=$message");
}
else
{
// save the data to the table
mysql_query("UPDATE registration SET forename='$forename', surname='$surname', username='$username', email='$email', password='$password' WHERE id='$id'")
or die(mysql_error());
}
// redirecr and display message
$message = "Your changes have been saved";
header("Location: edit.php?message=$message");
exit;
}
$id=429;// this line could have been $id=$_SESSION['id'];
$result = mysql_query("SELECT * FROM registration WHERE id=$id LIMIT 1")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from the table
$forename = $row['forename'];
$surname = $row['surname'];
$username = $row['username'];
$email = $row['email'];
$password = $row['password'];
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="styles/all.css" />
<link rel="stylesheet" href="styles/forms.css" />
<script type="text/javascript" src="javascript/jquery-1.7.1.min.js"></script>
<link href='//fonts.googleapis.com/css?family=Cantora+One' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Voltaire' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Ubuntu:400,500' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Chocolate Review</title>
<meta name="Description" content="Chocolate Review" />
<meta name="Keywords" content="Chocolate Review" />
</head>
<body>
<div class="container">
<div id="navigation">
<ul>
<li>Home</li>
<li>Dairy Milk</li>
<li>Ferrero Rocher</li>
<li>Kit Kat</li>
<li>Mars</li>
<li>Snickers</li>
<li>Twix</li>
<li>Register</li>
<li>Logout</li>
</ul>
</div>
<form action="" method="post" enctype="multipart/form-data" name="edit" id="editrecord">
<fieldset>
<legend><span class="headingreg">Edit Details</span></legend>
<div class="formreg">
<br style="clear:left;"/>
<label class="editlabel" for="forename">Forename</label><div><input type="text" id="forename" name="forename" class="insetedit" value="<?php echo $forename; ?>"/><br/></div>
<label class="editlabel" for="forename">Surname</label><div><input type="text" name="surname" class="insetedit" value="<?php echo $surname; ?>"/><br/></div>
<label class="editlabel" for="forename">Username</label><div><input type="text" name="username" class="insetedit" value="<?php echo $username; ?>"/><br/></div>
<label class="editlabel" for="forename">Password</label><div><input type="text" name="password" class="insetedit" value="<?php echo $password; ?>"/><br/></div>
<label class="editlabel" for="forename">email</label><div><input type="text" name="email" class="insetedit" value="<?php echo $email; ?>"/><br/></div>
<input type="submit" name="submit" class="submit2" value="submit">
</div>
<?php print $message; ?>
</fieldset>
</form>
<br style="clear:left;"/>
<br style="clear:left;"/>
</body>
</html>
Try This
if (empty($forename) || empty($surname) || empty($username) || empty ($password) || empty ($email))
{
$message = "Please enter data in all fields" ;
header("Location: edit.php?message=$message");
}