When I run this program and enter Dan Dan inside of it, it works. Now when I enter http://sftpgamblerlotteryclub/www it doesn't work. I would like for it to catch the sftp, /, www and return back to the form and inform the user " this is not a username, please resubmit". Thanks you.
<?php
// define variables and set to empty values
$nameErr = $emailErr = "";
$name = $email = $subject = "";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (preg_match("/^[a-zA-Z-']*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Contact Form</title>
</head>
<body>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name:
<input type="text" name="name">
<span class="error">* <?php echo $nameErr; ?> </span>
<br><br>
<input name="submit_btn" type="submit" id="submit-btn" value="Send Mail">
</form>
</div>
</body>
</html>
<?php
echo $name;
?>
Your test_input function is striping out the / so that is removed before you do your preg_match. As such you will never catch the /.
If I understand your question you want to make sure the user name is not in a list of prohibited names. For that I would create an array of prohibited names and then do a stripos on the json_encoded output of the array within a if condition. This makes it easy to expand the list of prohibited names.
This is based on your code snip-it.
$array = ["sftp", "http", "www"];
if (stripos(json_encode($array),$name) !== false) {
$nameErr = "This is not a valid user name"
}
Related
I have hard time with this simple jscript for no reason. this code should display the time once clicked. but i get the error below. what am i doing wrong
{
"message": "Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')",
"filename": "https://stacksnippets.net/js",
"lineno": 30,
"colno": 43
}
function item(name)
{
var d = new Date();
document.getElementById("but1").innerHTML = d;
}
<!DOCTYPE html>
<html>
<body>
<script src="C:\Users\kalyanasundar.s\OneDrive - HCL Technologies Ltd\Desktop\proj\animation\index.Js"></script>
<h2>JavaScript Statements</h2>
<p id="demo">You cannot break a code line with a \ backslash.</p>
<button onclick="item(name)">Try it</button>
</body>
</html>
This id (#but1) does not exist, so innerHtml won't work, try changing it.
function item(name) {
var d = new Date();
document.getElementById("demo").innerHTML = d;
}
<!DOCTYPE html>
<html>
<body>
<script src="C:\Users\kalyanasundar.s\OneDrive - HCL Technologies Ltd\Desktop\proj\animation\index.Js"></script>
<h2>JavaScript Statements</h2>
<p id="demo">You cannot break a code line with a \ backslash.</p>
<button onclick="item(name)">Try it</button>
</body>
</html>
My mailer stopped working and I cant get it to work again. I downloaded the newest phpmailer 5.5 from githhub and recodeded the page . I used the examples to create my mailer and created my form and when I turned on error reporting I cant figure this error out. I looked at examples on ur site and the did not work i trued to use
Fatal error: Class 'PHPMailer' not found
my server is using PHP Version 7.3.15 with the corna virus this is essential for me to stay aflot can u help me???
<!DOCTYPE html>
<html lang="en" class="no-js">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<head>
<meta charset="utf-8">
<title>test | semndinbg mail</title>
<link rel="stylesheet" href="css/repairstatus.css" type="text/css" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<form id="form_1130906" class="appnitro" method="post" action="">
<div id="contact_slide1">
<div id="contact_name">FULL NAME: *<br>
<input id="element_4" name="name" class="element text medium" type="text" maxlength="50" value="" placeholder="FULL NAME"/></div>
<div id="contact_phone">PHONE NUMBER: *<br>
<input id="element_2_1" name="phone" class="element text" size="15" maxlength="15" value="" type="text" placeholder="PHONE NUMBER"></div>
</div> <!--contact_slide1-->
<div id="contact_slide2">
<div id="contact_email">VEHICLE MAKE: *<br>
<input id="element_1" name="email" class="element text medium" type="text" maxlength="40" value="" placeholder="Ex: FORD"/></div>
<div id="contact_contact">VEHICLE MODEL: *<br>
<input id="element_1" name="email" class="element text medium" type="text" maxlength="40" value="" placeholder="Ex: TAURUS"/></div>
</div> <!--contact_slide2-->
<div id="contact_message">MESSAGE:<br>
<textarea id="element_3" name="message" class="element textarea medium" placeholder="START TYPING MESAGE HERE..."></textarea></div>
<div id="contact_slide3">
<input id="saveForm" class="button_text" type="submit" name="submit" value="SEND" />
</div><!--contact_slide3-->
</form>
<?php
if (isset($_POST['submit'])){
//check if post form was submitted
if(isset($_POST)){
//check if hidden value was used
if(isset($_POST['miles']) && trim($_POST['miles']) !=''){
die('THERE WAS AN ERROR');
}
//implode all the post data and check against bad words in a text file
$my_bad_file = "inc/words.txt"; //make a new file and insert any bad items one per line, Phrases work as well
if(!file_exists($my_bad_file)){
die("Can't find $my_bad_file");
}
$check_content = implode(",", $_POST);
$bad_content_array = array_map('rtrim', file($my_bad_file));
foreach ($bad_content_array as $bad_content) {
$bad_content = strtolower($bad_content);
if (strpos(strtolower($check_content), $bad_content) !== false) {
die('THERE WAS A BAD ERROR');
}}
}
echo "Mailer Error:" . $mail->ErrorInfo;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require("inc/PHPMailer2/src/PHPMailer.php");
require("inc/PHPMailer2/src/SMTP.php");
$mail = new PHPMailer/PHPMailer/PHPMailer();
$mail->IsSMTP(); // enable SMTP
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = 'test#gmail.com';
//Password to use for SMTP authentication
$mail->Password = 'aaaa1111';
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
$mail->AddAddress('test#test.com');
$mail->Priority = 1;
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "FINE LINE AUTO BODY | Repair Status";
$mail->AltBody = "This is the text-only body";
$name = isset($_POST['name']) ? $_POST['name'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$make = isset($_POST['make']) ? $_POST['make'] : '';
$model = isset($_POST['model']) ? $_POST['model'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
// gets info from form
$name = $_POST['name'] ;
$phone = $_POST['phone'] ;
$make = $_POST['make'] ;
$model = $_POST['model'] ;
$message = $_POST['message'] ;
$ip = $_SERVER["REMOTE_HOST"] ?: gethostbyaddr($_SERVER["REMOTE_ADDR"]);
// defines how message looks in email
$mail->Body="
<html>
<head>
</head>
<body>
<center>
<span style='color:red;'>This is from a customer, We are repairing his vehicle. Lets not keep them waiting!</span>
<div style='width:750px;text-align:center;'>
<div style='float:;'>
<span style='font-size:px;'><b>Personal Info</b><br></span>
<br>
<span style='font-size:px;'>---------------<br></span>
<br>
<span style='font-size:px;'>Full Name: $name<br></span>
<br>
<span style='font-size:px;'>Phone Number: $phone<br></span>
<br>
<span style='font-size:px;'>Vehicle Make: $make<br></span>
<br>
<span style='font-size:px;'>Vehicle Model: $model<br></span>
<br>
<span style='font-size:px;'>Message: $message<br></span>
</div></div>
</center>
</body>
</html>
";
// looks good in your inbox
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error:" . $mail->ErrorInfo;
} else {
echo '<meta http-equiv="refresh" content="0;url=https://www.sucess.com/">';
}}
?>
</body>
</html>
You're doing the same thing twice, but incorrectly (and unnecessarily) the second time.
This method of creating an instance is correct for PHPMailer 6.0 and later (though you can make it look better by using an alias). Note the direction of the slashes:
$mail = new PHPMailer\PHPMailer\PHPMailer();
This is the same as saying:
use PHPMailer\PHPMailer\PHPMailer;
...
$mail = new PHPMailer();
Later in your code, you're doing this (without having an earlier use statement):
$mail = new PHPMailer;
This won't work unless you either declare the PHPMailer namespace, or import the namespaced class name into your own namespace. Regardless – this is a duplicate and you can simply delete this line.
You might want to read the upgrade guide provided with PHPMailer.
I am trying to build a Chrome plugin. In the main folder, I have a popup.html which runs by default and uses the following syntax in manifest.json
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
the popup.html is working absolutely fine
what is my popup.html is doing?
It is inputting email from the user and storing it in local phpmyadmin.
Following is the code of popup.html
<!doctype html>
<html style="min-width:350px;">
<head>
<title>Welcome</title>
</head>
<body>
<h3> Enter email </h3>
<form action=”info.php” method=”post”>
Enter email: <input type=”email” name=”email” />
<input type="submit" value="Submit" >
</form>
</body>
</html>
The form action is linked to info.php where the php connects the database and inserts the data into the table in phpMyAdmin.
Following is the info.php code
<html>
<body>
<?php
$con = mysql_connect('127.0.0.1','root','');
if (!$con)
{
echo'Could not connect to the server';
}
if (!mysqli_select_db($con,'test'))
{
echo 'Database Not Selected';
}
$Email = $_POST[email];
$sql = "INSERT INTO test_table(Email) VALUES ('$Email')";
if(!mysqli_query($con,$sql))
{
echo 'Could not add to database';
}
else
{
echo 'Thank you the data is added';
}
header("refresh:2; url=popup.html");
?>
</body>
</html>
What problem am I facing?
After I enter the email in the input field it gives an error that Your file was not found It may have been moved or deleted.
ERR_FILE_NOT_FOUND
Maybe I am getting this error because info.php has to added in the manifest file? If this is the problem then how can I add multiple urls in the manifest.json file?
Your header won't work, since you have already echoed output.
Instead of outputting immediately, stick the output into an $html variable.
This might not completely fix your issue? But it will fix the header.
<?php
$html = '';
$con = mysql_connect('127.0.0.1','root','');
if (!$con)
{
$html .= 'Could not connect to the server';
}
if (!mysqli_select_db($con,'test'))
{
$html .= 'Database Not Selected';
}
$Email = $_POST[email];
$sql = "INSERT INTO test_table(Email) VALUES ('$Email')";
if(!mysqli_query($con,$sql))
{
$html .= 'Could not add to database';
}
if (empty($html)) {
header("refresh:2; url=popup.html");
}
echo $html;
with #wOxxOm help the problem was solved.
In the popup.html instead of giving info.html directly, it would have been through the server such as http://localhost/foldername/info.php
I want to create a searchController, that searches the db for whatever keywords the user enters into a textbox. I have looked at this article and this and many more.
This is what I have so far:
public function searchAction(Request $request) {
if ($request->getMEthod() == 'GET') {
$title = $request->get('Search_term');
//echo "<div class=\"searchText\">Search Results</div><hr/>";
$em = $this->getDoctrine()->getManager();
$Search_terms = explode(' ', $title); //splits search terms at spaces
$query = "SELECT * FROM Entity/Adverts WHERE ";
foreach ($Search_terms as $each) {
// echo $each."<br/>";
$i = 0;
$i++;
if ($i == 1)
$query .= "Adv_title LIKE '%$each%' ";
else
$query .= "OR Adv_title LIKE '%$each%' ";
}
$query = $em->createQuery($query);
$numRow = $query->count();
if ($numRow > 0) {
while ($query->fetch()) {
$repository = $em->getRepository('YCRYcrBundle:Adverts')->findBy(array(
'advTitle' => $title
));
/* echo "<h2><a href='#'> $title</a> </h2>";
echo "$desc <br /> <br />";
echo"<a href='/201308/View/YCR/index.php' class='link-button right'><span>Apply</span></a>"; */
}
}
/* else
echo "none found for \"<b>$SearchTerm </b>\"</br>Check spelling"; */
}
return $this->render('YCRYcrBundle:Search:search.html.twig', array('title' => $title->getAdvTitle()));
}
What is missing from this code to make it work, and or what is wrong?
Edit:
sorry of I was unclear. I am getting the following error:
FatalErrorException: Error: Call to undefined method Doctrine\ORM\Query::count() in C:\wamp\www\201308\src\YCR\YcrBundle\Controller\SearchController.php line 28
and do not know what is wrong as I am new to Symfony and doctrine.
This is what I have in my search.html.twig:
{% extends "YCRYcrBundle::layout.html.twig" %}
{% block content %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>YCR Job Search</title>
<link href="stylesheets/style.css" rel="stylesheet" type="text/css" />
<link href="stylesheets/colour.css" rel="stylesheet" type="text/css" />
</head>
<body onload="b = setInterval('clear()', 0);">
<div class="topDiv">
<div style="float: left;">
<img src="/201308/View/images/ycr.jpg" alt="ycr"></div>
<br/>
<!--<H2>Search for a Job</H2>-->
<div class="searchform">
<form id="formsearch" name="p" method="get" action="index.php">
<span>
<input name="Search_term" class="editbox_search" id="editbox_search" maxlength="80" value="<?php $this; ?>" type="text" />
</span>
<input type="image" name="button_search" src="images/search.gif" class="button_search" alt="" />
</form>
<br/>
<div id="search_results">
</div>
</div>
<!-- </div>-->
<script type="text/javascript" src="http://code.jquery.com/jquery- 1.7.2.min.js"></script><!--javascript jquery library-->
<script type="text/javascript" src="../View/scripts/Script.js"></script>
{% endblock %}
When the user searches, for example programmer, to display like this:
-Programmer
-a summary of the description of what a programmer entails
-a button/link that reads: read more, that takes me to a page with full description
You are pretty far off the mark. Query has no count function, that's a querybuilder function. You may write raw sql, but you are better served learning querybuilder : http://docs.doctrine-project.org/en/latest/reference/query-builder.html. Remember, doctrine is designed to give you a list of entities, that you pass to the twig to do stuff with.
Also, your twig won't do much, see the basics of usage in the very crude twig I've included. use {{entity.method}} or {{entity.field}} to get the various display properties of each entity. Use a twig foreach to loop through them all. Take a look at my example in your context, and then go read the twig documents to fill in the gaps. http://twig.sensiolabs.org/documentation
The Controller
public function searchAction(Request $request) {
if ($request->getMethod() == 'GET') {
$title = $request->get('Search_term');
$em = $this->getDoctrine()->getManager();
$qb = $em->getRepository('YCRYcrBundle:Adverts')
->createQueryBuilder('a');
$searches= explode(' ', $title);
foreach ($searches as $sk => $sv) {
$cqb[]=$qb->expr()->like("CONCAT($sv, '')", "'%$sv%'");
}
$qb->andWhere(call_user_func_array(array($qb->expr(),"orx"),$cqb));
$adverts = $qb->getResult();
}
return $this->render('YCRYcrBundle:Search:search.html.twig'
, array('adverts' => $adverts));
}
And a twig file
{# Your other stuff #}
{% for advert in adverts %}
{{advert.getId}}
{# call the various method and fields for your display#}
{% endfor %}
you need to execute the query (with execute ) or you wont get an array. and you should be using the query builder instead DQL string concatenation. Read the doctrine doc on basic doctrine usage , the entity namespace seems to be incorrect too.
i quote you :
$query = $em->createQuery($query);
$numRow = $query->count();
should be at least :
$query = $em->createQuery($query);
$numRow = count($query->execute())
edit : not sure wether you would be getting an array or an ArrayCollection , check if the count fonction works on the ArrayCollection.
I am new to PHP, Javascript and HTML. So maybe I'm missing something obvious but, I can't for the life of me figure out what is wrong with my code. I am trying to use Paul Irish's Infinite Scroll with a PHP file that has an anchor point that links back to itself with different GET values. The problem is that Anything I do gives me this error:
Sorry, we couldn't parse your Next (Previous Posts) URL. Verify your the css selector points to the correct A tag.
I am at my wits end and desperately need someones help because I need this done by January 20th. It's going to be a birthday gift for someone I know.
Here is my code:
index.php (Code Snippet)
<div id="content-container" class="container-fluid" style="padding:0px;overflow:hidden;">
<div class="row-fluid full">
<div class="span12 full" style="overflow:scroll;position:relative;">
<div id="media-palette">
<?php
include('content.php');
?>
</div>
</div>
</div>
</div>
script.js (Code Snippet)
$("#media-palette").infinitescroll({
navSelector:"#next",
nextSelector:"#media-palette a#next:last",
itemSelector:".media-content",
bufferPx:50,
debug: true,
}, function(newElements) {
$("#media-palette").masonry('append', newElements,true);
});
content.php
(It is worth noting that the images found in this file are for testing purposes and the final PHP file will load images from a database.)
<?php
require('dbconnect.php');
$startIndex = $_GET['start'];
$endIndex = $_GET['end'];
$nextStartIndex = $endIndex-1;
$nextEndIndex = $endIndex-10;
?>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
$files = scandir("images");
if ($files) {
$length = count($files);
static $allowedExts = array("jpg", "jpeg", "gif", "png");
for ($i = 0; $i < $length; $i++) {
$extension = end(explode(".", $files[$i]));
$extension = strtolower($extension);
if (in_array($extension,$allowedExts)) {
$rand = rand(0,10);
if (!$rand) echo "<img class='media-content medium' src='images/".$files[$i]."'/>";
else echo "<img class='media-content small' src='images/".$files[$i]."'/>";
}
}
}
echo '<a id="next" href="content.php?start='.$nextStartIndex.'&end='.$nextEndIndex.'"></a>';
?>
</body>