PHP insert won't work - phpt

I have been battling with phpMyAdmin insert for sometime now,
It doesn't give me an error, yet it won't insert into the database.
My code goes like this
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<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>New Page 1</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="43%" id="AutoNumber1">
<tr>
<td width="100%">
<p align="left"> </td>
</tr>
<tr>
<td width="100%">
<form method="GET" name="testform" id="testform" action="logout.php">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="69%" id="AutoNumber2" height="63">
<tr>
<td width="36%" height="22">Username</td>
<td width="64%" height="22"><input type="text" name="user" size="20"></td>
</tr>
<tr>
<td width="36%" height="22">password</td>
<td width="64%" height="22">
<input type="password" name="passwd" size="20"></td>
</tr>
<tr>
<td width="36%" height="19"> </td>
<td width="64%" height="19">
<input type="submit" value="login" name="login"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Now the php also goes like this
<?php
require_once('inc/config.php');
$user = $_GET['user'];
$pass = $_GET['passwd'];
//database connection
$conn = mysqli_connect(DBHOST,DBUSER,DBPASS,DB);
//mysql anti injection
$username = mysql_real_escape_string($_GET['user']);
$password = mysql_real_escape_string($_GET['passwd']);
$sql = "INSERT INTO people (`username`, `password`) VALUES ('$username', '$password');";
mysqli_close($conn);
echo "Inserted";
?>
Trouble is, I don't see what I insert into the mysql database, when viewed on local host; what is the problem?

Seems like the issue might be the use of ';' twice at the end of the following line:
$sql = "INSERT INTO people (username, password) VALUES ('$username', '$password');";
Try the following.
$sql = "INSERT INTO people (username, password) VALUES ('$username', '$password');"

Related

I have been trying to make an error handling on Coldfusion, everything is working good but I am not able to get the current session username

Application.cfm
<cfapplication name="AppError" clientmanagement="Yes" sessionmanagement="Yes"
clientstorage="cookie">
<cferror type="exception" template="ExpressError.cfm" exception="expression">
<cferror type="exception" template="DatabaseError.cfm" exception="database">
ExpressError.cfm
<cfoutput>
Sorry! Internal Error Occurred!
<cfsavecontent variable="errortext">
<div class="container">
<table class="err">
<tr>
<th>URL</th><td>#cgi.server_name##cgi.script_name#</td>
</tr>
<tr>
<th>Message</th><td>#Error.message#</td>
</tr>
<tr>
<th>Diagnostics</th><td>#Error.Diagnostics#</td>
</tr>
<tr>
<th>Template</th><td>#Error.TEMPLATE#</td>
</tr>
</table>
</div>
</cfsavecontent>
<cfmail to="xxx#xxx.com" from="yyy#yyyy.com" subject="Error : #Error.message#" type="html">
<HTML>
<head>
<style type="text/css">
<cfinclude template="Style/errorstyle.css">
</style>
</head>
<body>
#errortext#
</body>
</HTML>
</cfmail>
</cfoutput>
DatabaseError.cfm
<cfoutput>
Sorry! Internal Error Occurred!
<cfsavecontent variable="errortext">
<div class="container">
<table class="err">
<tr>
<th>Application</th><td>#elmsapp#</td>
</tr>
<tr>
<th>URL</th><td>#cgi.server_name##cgi.script_name#</td>
</tr>
<tr>
<th>Message</th><td>#Error.message#</td>
</tr>
<tr>
<th>Diagnostics</th><td>#Error.Diagnostics#</td>
</tr>
<tr>
<th>Template</th><td>#Error.TEMPLATE#</td>
</tr>
<tr>
<th>Sql</th><td>#Error.RootCause.Sql#</td>
</tr>
<tr>
<th>DataSource</th><td>#Error.RootCause.DataSource#</td>
</tr>
<tr>
<th>RemoteAddress</th><td>#Error.RemoteAddress#</td>
</tr>
</table>
</div>
</cfsavecontent>
<cfmail to="xxx#xxx.com" from="yyy#yyyyy.com" subject="Error: #Error.message#" type="html">
<HTML>
<head>
<style type="text/css">
<cfinclude template="Style/errorstyle.css">
</style>
</head>
<body>
#errortext#
</body>
</HTML>
</cfmail>
</cfoutput>
test.cfm
<cfoutput>#sdfssfsdf#</cfoutput>
user.cfm
<cfoutput> #trim(session.auth_user)# </cfoutput>
So when i run test.cfm, i am getting a correct email saying "Variable SDFSSFSDF is undefined." but when i run user.cfm, i am getting an email saying "Element AUTH_USER is undefined in SESSION.".
Point is when i delete application.cfm, user.cfm page gives the correct username of the session but with application.cfm in place...it gives an error. I think i need to define the sessiom.auth_user but how and where is the question.
Would appreciate if someone could please help me out. Thanks

How to send an email using email_user containing HTML and CSS in Python Django?

I am sending an activation link to the user on their registered email for my blog. I am using the following lines of code for sending the email in my signup view. I am not using EmailMultiAlternatives or send_email because, I am creating a unique token for the user signing up and I want to use email_user, which will automatically take care of for and to email address:-
current_site = get_current_site(request)
subject = 'Activate Your Account'
message = render_to_string('accounts/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
'token': account_activation_token.make_token(user),
})
message.content_subtype = "html"
user.email_user(subject, message)
I have added html and css in my template account_activation_email.html as under:-
{% autoescape off %}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Activate your SaralGyaan account</title>
<style type="text/css" rel="stylesheet" media="all">
[styles go there not shown due to beverity]
</style>
</head>
<body>
<span class="preheader">Use this link to activate your SaralGyaan account. The link is only valid for 24 hours.</span>
<table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="email-content" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="email-masthead">
<a href="https://saralgyaan.com" class="email-masthead_name">
SaralGyaan
</a>
</td>
</tr>
<!-- Email Body -->
<tr>
<td class="email-body" width="100%" cellpadding="0" cellspacing="0">
<table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
<h1>Hi {{user.get_full_name}},</h1>
<p>Thank you for registering your SaralGyaan's account. Please click the link below to activate your account. <strong>This link is only valid for the next 24 hours.</strong></p>
<!-- Action -->
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<!-- Border based button
https://litmus.com/blog/a-guide-to-bulletproof-buttons-in-email-design -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
Activate your account
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p> If you have not created an account, please ignore this email or contact support if you have questions.</p>
<p>Thanks,
<br>The SaralGyaan Team</p>
<!-- Sub copy -->
<table class="body-sub">
<tr>
<td>
<p class="sub">If you’re having trouble with the button above, copy and paste the URL below into your web browser.</p>
<p class="sub">{{ protocol }}://{{ domain }}{% url 'activate' uidb64=uid token=token %}</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0">
<tr>
<td class="content-cell" align="center">
<p class="sub align-center">© 2018 SaralGyaan. All rights reserved.</p>
<p class="sub align-center">
[SaralGyaan]
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
But the email which I am receiving is not the html version of it but plain text. There is no error in this html code as I am using the same with my password reset email and it is working fine there.
You can't send HTML alone in an email. HTML is sent as an alternative to plain text.
Use the html_message to send the html part and use message to send in plain text.
message = render_to_string('template.txt', ...)
html_message = render_to_string('textmplate.html', ...)

Coldfusion, send cfhtmltopdf by email

Is possible to send a pdf created using cfhtmltopdf in the email? I'm trying to set the cfhtmltopdf in a variable and send by email, but I think it is not possible.
Here is my test cfhtmltopdf:
<cfhtmltopdf
orientation="portrait" pagetype="A4" margintop="1" marginbottom="1" marginleft="1">
<html>
<head>
<body>
<table>
<tr>
<th>Test1</th>
<th>Test2</th>
<th>Test3</th>
</tr>
<tr>
<td>ABC</td>
<td>ABC</td>
<td>ABC</td>
</tr>
<tr>
<td>ABC</td>
<td>ABC</td>
<td>ABC</td>
</tr>
<tr>
<td>ABC</td>
<td>ABC</td>
<td>ABC</td>
</tr>
</table>
</body>
</head>
</html>
</cfhtmltopdf>
Simply add destination attribute with the path for creating the file, then use that path for the mail.
<cfset filePath = GetTempDirectory() & "emailfile.pdf">
<cfhtmltopdf destination="#filePath#" orientation="portrait" pagetype="A4" margintop="1" marginbottom="1" marginleft="1" >
<html>
<head>
</head>
<body>
<table>
<tr>
<th>Test1</th>
<th>Test2</th>
<th>Test3</th>
</tr>
<tr>
<td>ABC</td>
<td>ABC</td>
<td>ABC</td>
</tr>
</table>
</body>
</html>
</cfhtmltopdf>
<cfmail to="..." .... >
<cfmailparam file="#filePath#" disposition="attachment" type="#fileGetMimeType(filePath)#" remove="true">
<cfmailpart type="html">Content</cfmailpart>
</cfmail>

Regex - How to properly grab nested value

I understand parsing html with a regex isn't ideal, but I have a use case for it.
I have this coverage report/html page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LCOV - .info.cleaned</title>
<link rel="stylesheet" type="text/css" href="gcov.css">
</head>
<body>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td class="title">LCOV - code coverage report</td></tr>
<tr><td class="ruler"><img src="glass.png" width=3 height=3 alt=""></td></tr>
<tr>
<td width="100%">
<table cellpadding=1 border=0 width="100%">
<tr>
<td width="10%" class="headerItem">Current view:</td>
<td width="35%" class="headerValue">top level</td>
<td width="5%"></td>
<td width="15%"></td>
<td width="10%" class="headerCovTableHead">Hit</td>
<td width="10%" class="headerCovTableHead">Total</td>
<td width="15%" class="headerCovTableHead">Coverage</td>
</tr>
<tr>
<td class="headerItem">Test:</td>
<td class="headerValue">.info.cleaned</td>
<td></td>
<td class="headerItem">Lines:</td>
<td class="headerCovTableEntry">399</td>
<td class="headerCovTableEntry">1019</td>
<td class="headerCovTableEntryLo">39.2 %</td>
</tr>
<tr>
<td class="headerItem">Date:</td>
<td class="headerValue">2016-11-07</td>
<td></td>
<td class="headerItem">Functions:</td>
<td class="headerCovTableEntry">22</td>
<td class="headerCovTableEntry">67</td>
<td class="headerCovTableEntryLo">32.8 %</td>
</tr>
<tr><td><img src="glass.png" width=3 height=3 alt=""></td></tr>
</table>
</td>
</tr>
<tr><td class="ruler"><img src="glass.png" width=3 height=3 alt=""></td></tr>
</table>
<center>
<table width="80%" cellpadding=1 cellspacing=1 border=0>
<tr>
<td width="50%"><br></td>
<td width="10%"></td>
<td width="10%"></td>
<td width="10%"></td>
<td width="10%"></td>
<td width="10%"></td>
</tr>
<tr>
<td class="tableHead">Directory <span class="tableHeadSort"><img src="glass.png" width=10 height=14 alt="Sort by name" title="Sort by name" border=0></span></td>
<td class="tableHead" colspan=3>Line Coverage <span class="tableHeadSort"><img src="updown.png" width=10 height=14 alt="Sort by line coverage" title="Sort by line coverage" border=0></span></td>
<td class="tableHead" colspan=2>Functions <span class="tableHeadSort"><img src="updown.png" width=10 height=14 alt="Sort by function coverage" title="Sort by function coverage" border=0></span></td>
</tr>
<tr>
<td class="coverFile">src</td>
<td class="coverBar" align="center">
<table border=0 cellspacing=0 cellpadding=1><tr><td class="coverBarOutline"><img src="ruby.png" width=39 height=10 alt="39.2%"><img src="snow.png" width=61 height=10 alt="39.2%"></td></tr></table>
</td>
<td class="coverPerLo">39.2 %</td>
<td class="coverNumLo">399 / 1019</td>
<td class="coverPerLo">32.8 %</td>
<td class="coverNumLo">22 / 67</td>
</tr>
</table>
</center>
<br>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td class="ruler"><img src="glass.png" width=3 height=3 alt=""></td></tr>
<tr><td class="versionInfo">Generated by: LCOV version 1.10</td></tr>
</table>
<br>
</body>
</html>
I am attempting to parse out the data from this line:
<td class="headerCovTableEntryLo">39.2 %</td>
as 39.2 (a float value).
I am currently using this regex to find two matching TD's:
<td class="headerCovTableEntryLo">[0-9.].*?.%<\/td>
I'm misunderstanding how groups work. I tried:
(<td class="headerCovTableEntryLo">[0-9.].*?.%<\/td>)[0-9.].*?\1
To take what was found in the first group and grab just the numberical values but I have zero matches. Can anyone lend some insight into what I am doing wrong?
Is this what you want to perform? (capture only the floating value):
<(td) class="headerCovTableEntryLo">([0-9.]+)\s?%<\/\1>
see it working here: https://regex101.com/r/qprROm/2
If so, if you try to reuse the first match you're making correct use of it with \1 or to etc to match which captured group. but in your trial you also captured the class which wont match in closing tag.
Not sure this is really what you try to do though. haha
Plus, in this case doing <(td)>(.*?)<\/\1> does not really make sense. It is more usefill if your usecase is something like this <(td|th|tr)>(.*?)<\/\1>
In the end if I was doing it I would rather do it this way for more flexibility: (?<=class="headerCovTableEntryLo">)([0-9.]+)(?=\s?%)
See it working here: https://regex101.com/r/qprROm/3

CFWINDOW - Form submit in CF to stay inside CFWindow

I have a page with this basic process:
Click checkboxes next to forms you want to download
Click submit
CFWindow pops up to collect some basic info
Click submit to download forms while staying in the window that was opened by CFWindow
When you click the submit button inside the CFWindow , it brings you back to the parent page. I want the form submission to stay inside the CFWindow. I saw this post: Refresh cfwindow content. However, the refreshOnShow = "true" does not work. Every time I hit submit, it goes back to the parent window.
Here is the Parent page:
<cfform name="myform">
<cfinput type="hidden" name="OrgID" value="#getit.orgID#">
<table width="95%" border="0" cellspacing="5" cellpadding="0" align="center">
<tr>
<td width="50%" valign="top" class="coretextforBR">
<cfinput type="checkbox" name="GetThese" value="#form_ID#">
<a class="corelinkforBR">#Forms_Name#</a>
<br /><br />
#Forms_Description#
<br /><br />
</td>
</tr>
<tr>
<td width="50%" valign="top" class="coretextforBR">
<cfinput type="checkbox" name="GetThese" value="#form_ID#">
<a class="corelinkforBR">#Forms_Name#</a>
<br /><br />
#Forms_Description#
<br /><br />
</td>
</tr>
<tr>
<td width="50%" valign="top" class="coretextforBR">
<cfinput type="checkbox" name="GetThese" value="#form_ID#">
<a class="corelinkforBR">#Forms_Name#</a>
<br /><br />
#Forms_Description#
<br /><br />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit"value="Get It" onclick="javascript:ColdFusion.Window.show('mywindow1')">
</td>
</tr>
</table>
</cfform>
<cfwindow x="250" y="250" width="400" height="400"
name="mywindow1" title="Almost ready to download" initshow="false" draggable="false" resizable="false"
refreshOnShow="true" source="submitform.cfm?GetThese={myform:GetThese.value}&OrgID={myform:OrgID}&action=information"
bodystyle="background-color: white;" headerStyle="background-color: ###getcss.color#; font-family: #getcss.font#; color: ###getcss.fontcolor#;" />
Here is the source (submit.cfm) for the CFWwindow:
<cfparam name="attributes.action" default="information">
<cfoutput>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
This window will collect information to begin download
<br>
<!--- action for downloading --->
<cfif attributes.action eq "download">
<cfloop info and stuff left out>
#Forms_Name#<br />
</cfloop>
<!--- what you see when page initially loads --->
<cfelse>
<form action="submitform.cfm?action=download" method="post">
<input type="hidden" name="GetThese" value="#attributes.GetThese#">
<input type="hidden" name="OrgID" value="#attributes.OrgID#">
<table width="95%" border="0" align="center">
<tr>
<td class="coretextforBR">First:</td>
<td><input type="text" name="CollectedInfo_First"></td>
</tr>
<tr>
<td class="coretextforBR">Last:</td>
<td><input type="text" name="CollectedInfo_Last"></td>
</tr>
<tr>
<td class="coretextforBR">Phone:</td>
<td><input type="text" name="CollectedInfo_Phone"></td>
</tr>
<tr>
<td class="coretextforBR">Email:</td>
<td><input type="text" name="CollectedInfo_Email"></td>
</tr>
<tr>
<td class="coretextforBR">Best way <br> to contact:</td>
<td><input type="text" name="CollectedInfo_BestWay"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Download" class="button one"></td>
</tr>
</table>
</form>
</cfif>
</cfoutput>
</body>
</html>
I have no idea what I am doing wrong. I couldn't find a definite answer to my problem either other than the refreshOnShow. Should I rethink and do a ajax submit?
Using <cfform> instead of normal <form> worked as Liegh suggested.