Unable to Style Div - php

Creating a blog from scratch is a difficult process but I've been plodding along with some minor issues which have been resolved. My minor issue today is the fact that I'm unable to style the site background with an image. I'm able to add colors but not an image.
The second minor issue is to do with my Div tags. I've created a basic form that submits comments to my MySQL database but when I attempt to style the div that I've enclosed the form and comments that are displayed the styles have not appeared. I have included my Comments CSS below and my post.php page.
CSS:
#comments-title {
background-color: #282828;
width: 567px;
height: 30px;
font-size: 25px;
font-family: arial;
color: #ffffff;
padding: 5px;
padding-top: 6px;
padding-bottom: 4px;
}
#comment-list{
border:1px solid #dadada;
width: 567px;
padding: 5px;
}
PHP:
<h2 id="comments-title">Comments</h2>
<div id="comment-list'">
<?php
}
$commenttimestamp = strtotime("now");
$sql = "SELECT * FROM php_blog_comments WHERE entry='$id' ORDER BY timestamp";
$result = mysql_query ($sql) or print ("Can't select comments from table php_blog_comments.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {
$timestamp = date("l F d Y", $row['timestamp']);
print("<p id='comment'>" . stripslashes($row['comment']) . "</p>");
printf("<p id='comment'>Comment by %s # %s</p>", stripslashes($row['url']), stripslashes($row['name']), $timestamp);
}
?>
<form method="post" action="process.php">
<p><input type="hidden" name="entry" id="entry" value="<?php echo $id; ?>" />
<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">
<strong><label for="name">Name:</label></strong> <input type="text" name="name" id="name" size="25" /><br />
<strong><label for="email">E-mail:</label></strong> <input type="text" name="email" id="email" size="25" /><br />
<strong><label for="url">URL:</label></strong> <input type="text" name="url" id="url" size="25" value="http://" /><br />
<strong><label for="comment">Comment:</label></strong><br />
<textarea cols="25" rows="5" name="comment" id="comment"></textarea></p>
<p><input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" /></p>
</form>
</div>

Take a second look at this line:
<div id="comment-list'">
See that little ' in there? Take it out.
For everything else, you're going to have to be more specific. You've basically posted a large slab of code here without pointing to the offending code.

Remember that the ID have to be unique. use class instead if id. (In your while loop: <p id='comment'>, you have multiple id's with the same id.
You have a lot of this to fix.
And, try to validate your code to check for some errors that might prevent it from working. http://validator.w3.org
+ You have a single quote in your comment-list ID

Related

WordPress : Form data is not displaying via echo

I have created a form to which I am passing the data. When I try to echo the data it shows couple of errors saying that index is undefined.
<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
<div class="main-content-inner">
<form method='post' enctype='multipart/form-data'>
<input id="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
<input id="designation" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
<input id="description" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
<input id="pic" type="file" style="height:30px; width: 350px; "><br><br>
<input name="insert" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px; " name='Submit' value='Add Member' /><br><br>
</form>
</div>
</div>
<?php
if(isset($_POST['insert']))
{
echo $namevar = isset($_POST['name']);
echo $descriptionvar = isset($_POST['description']);
echo $designationvar = isset($_POST['designation']);
}
?>
Following are the errors:
Notice: Undefined index: name in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
Notice: Undefined index: description in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
Notice: Undefined index: designation in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen-child\practicepage.php
<form method='post' enctype='multipart/form-data'>
<input name="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
<input name="designation" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
<input name="description" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
<input id="pic" type="file" style="height:30px; width: 350px; "><br><br>
<input name="insert" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px;" value='Add Member' /><br><br>
</form>
<?php
if(isset($_POST['insert']))
{
echo $namevar = $_POST['name'];
echo $descriptionvar = $_POST['description'];
echo $designationvar = $_POST['designation'];
}
?>
The issue is with the names of input fields.
In PHP or any other programming language, You should use the input name="something" to get the input values.
You should give the name for each input fields.
For example,
<input name = "name" id="name" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
You cannot pass POST data to another page vie using ID.
You should give name to <input>
<input name="name">
<input name="description">
<input name="designation">
Edit
You are defining variables and echoing them same time
Change your code to:
<?php
if(isset($_POST["insert"])){
echo $_POST["name"];
echo $_POST["description"];
echo $_POST["designation"];
}?>

HMVC CodeIgniter view igniter type="date" not working on html

am making this form input in my HMVC project. i want to have
input type="date"
but it happens to be the output was just like a normal textbox. what other ways can i do this or what is the error?
add_view.php
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/bootstrap/css/inputfield.css">
<html>
<div>
<fieldset>
<?php
echo form_open('Clients/create');
?>
<p>
<label class="field" for=""><span>*</span>Name:</label>
<input type = "text" name="" class ="textbox-300">
</p>
<p>
<label class="field" for=""><span>*</span>Details:</label>
<textarea name=""></textarea>
</p>
</br></br></br>
<p>
<label class="field" for=""><span>*</span>Address:</label>
<textarea name=""></textarea>
</p>
<p>
<label class="field" for=""><span>*</span>Contact Number:</label>
<input type = "text" name="" class ="textbox-300">
</p>
<p>
<label class="field" for=""><span>*</span>Contact Email:</label>
<input type = "text" name="" class ="textbox-300">
</p>
<p>
<label class="field" for=""><span>*</span>Date Added:</label>
<input type="date" name="" min="1950-01-01">
</p>
<?php
echo form_submit('submit','Save');
echo validation_errors();
echo form_close();
?>
</fieldset>
</div>
</html>
inputfield.css
textarea {
width: 51%;
height: 150px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px black;
border-radius: 4px;
resize: none;
float:right;
}
fieldset {
width: 500px;
}
label .field{
text-align:left;
width:100px;
float:left;
font-weight: bold;
}
input.textbox-300{
width:350;
float:right;
}
fieldset p {
clear:both;
padding:5px;
}
label span, .required{
color:red;
font-weight: bold;
}
.center {
margin: auto;
padding: 10px;
}
im sorry im not good in this date thing so please help me
You are getting empty textbox result because you are not using name attribute in your input fields just add name attribute in all input fields as:
Example:
<input type = "text" name="yourName" class ="textbox-300">
<textarea name="Details"></textarea>
<textarea name="Address"></textarea>
<input type = "text" name="ContactNo" class ="textbox-300">
<input type = "text" name="Email" class ="textbox-300">
<input type="date" name="YourDate" min="1950-01-01">
date picker appears to be blank because it is not supported by mozilla fire fox. if theres any that mozilla supports please let me know. thanks

Posting to Database with PHP

I'm trying to all users to add data to a database. However, it's not working and I'm not getting an error. This is purely for practice, but it's still frustrating. Thoughts?
<form name="Add" id="Add" method="post" action="programadd.php">
<p>Content Name:
<input name="program" type="text" id="program" style="width: 500px; height: 20px;" />
</p>
<p>Content Air Date
<input name="airdate" type="date" id="airdate" />
</p>
<p>Description
<input name="description" type="text" id="description" style="width: 500px; height: 20px;" />
</p>
<p>Production
<input name="production" type="text" id="production" value="nothing" style="width: 500px; height: 20px;" />
</p>
<p>Promotions
<input name="promotion" type="text" id="promotion" value="nothing" style="width: 500px; height: 20px;" />
</p>
<p>Community
<input name="community" type="text" id="community" value="nothing" style="width: 500px; height: 20px;" />
</p>
<p>Web
<input name="web" type="text" id="web" value="nothing" style="width: 500px; height: 20px;" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
Here's the programadd page. Thanks!
<?php
include('connect-db.php');
$program = $_POST['program'];
$airdate = $_POST['airdate'];
$description = $_POST['description'];
$production = $_POST['production'];
$promotion = $_POST['promotion'];
$community = $_POST['community'];
$web = $_POST['web'];
if (mysql_query ("INSERT INTO calendar(program, airdate, description, production, promotion, community, web) VALUES
('$program', '$airdate', '$description','$production', '$promotion', '$community', '$web')"))
{ echo "Content successfully added to the database. <br />
}
else {
die(mysql_error());
}
require_once("db_connx_close.php");
?>
{ echo "Content successfully added to the database. <br />
^---missing " here
If you're NOT getting a syntax error from this, then you're probably running with display_errors and error_reporting turned off. NEVER have them disabled when you're developing. It's the coding equivalent of stuffing your fingers in your ears and going "lalalala can't hear you don't care what you have to tell me lalala".
This may be an error in your question's markdown, but just incase it isn't I will mention what I am seeing.
You are not closing the string on the echo after your query:
echo "Content successfully added to the database. <br />
Should be:
echo "Content successfully added to the database. <br />";
Also, just for the sake of clarity, you are using $_POST data directly in a SQL Query without sanitizing or validating the data. I realize this is for practice but it should be mentioned that this methodology is highly vulnerable to SQL Injection and will make your database easily accessible. You could, instead, use PHP's PDO Library for your connections or at the very least sanitize your inputs.
However your code is vulnereble to sql-injection although for your help put this change in your query syntax like this--
if (mysql_query ("INSERT INTO calendar(program, airdate, description, production, promotion, community, web) VALUES ('".$program."', '".$airdate."', '".$description."','".$production."','".$promotion."', '".$community."', '".$web."')"))
{
echo "Content successfully added to the database. <br />";
}

Display form validation errors next to each field

I am working on a simple contact form written in php and have almost everything setup as I would like for it to be except right now, all validation errors are displaying in a div on the top of my form, and I would like to change the code below so they are displayed next to the form field that caused the error, but I am not sure how to accomplish this so I have come to the experts for some advise.
PHP Validation Routine
$frm_valid = new Validate();
if(isset($_POST['submit'])){
$rules=array(
array('Type'=>'Required','Var'=>$_POST['name'],'Msg'=>'Name field is required.'),
array('Type'=>'Required','Var'=>$_POST['email'],'Msg'=>'Email address field is required.'),
array('Type'=>'Email','Var'=>$_POST['email'],'Msg'=>'Your email address format is invalid.'),
array('Type'=>'Required','Var'=>$_POST['subject'],'Msg'=>'Subject field is required.'),
array('Type'=>'Required','Var'=>$_POST['message'],'Msg'=>'Message field is required.'),
);
$result = $frm_valid->Valid($rules);
if(is_array($result)){
// Print validation errors (if any)
echo('<div"><b>The form cannot be submitted until the following errors are corrected.</b><ul>');
foreach($result as $key=>$val){
echo '<li>'.$val.'</li>';
}
echo('</ul></div><br />');
}
else {
// Do something else.
}
}
Forms HTML
<form action="<? echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<input type="text" name="name" value="" /> <br />
<input type="text" name="email" value="" /> <br />
<input type="text" name="subject" value="" /> <br />
<textarea name="message" cols="80" rows="7"></textarea> <br />
<input type="submit" name="submit" value="Send" />
</form>
You need to change the whole code for this!!! The structure, perhaps this way:
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<ul>
<li>
<label>
<span>Name</span>
<input type="text" name="name" />
<small class="errorText"><?php echo ($_POST["name"] == "") ? "This field is required" : ""; ?></small>
</label>
</li>
<li>
<label>
<span>Email</span>
<input type="text" name="email" />
<small class="errorText"><?php echo ($_POST["email"] == "") ? "This field is required" : ""; ?></small>
</label>
</li>
<li>
<label>
<span>Subject</span>
<input type="text" name="subject" />
<small class="errorText"><?php echo ($_POST["subject"] == "") ? "This field is required" : ""; ?></small>
</label>
</li>
<li>
<label>
<span>Message</span>
<textarea name="message" cols="80" rows="7"></textarea>
<small class="errorText"><?php echo ($_POST["message"] == "") ? "This field is required" : ""; ?></small>
</label>
</li>
<li>
<input type="submit" name="submit" value="Send" />
</li>
</ul>
</form>
And the CSS for the same:
* {font-family: Segoe UI, Tahoma;}
h1 {font-weight: bold; font-size: 14pt; padding: 5px 0; margin: 5px 0; border: 1px solid #999; border-width: 1px 0;}
input[type='submit'] {padding: 5px 20px; cursor: pointer;}
ul, li {display: block; list-style: none; margin: 0; padding: 0;}
ul li {padding: 5px 0;}
ul li label span {display: block; cursor: pointer;}
ul li label .errorText {color: #f00; font-weight: bold; vertical-align: top;}
ul li label textarea {width: 300px;}
You can see a live demo here: Demo
Error Handling in PHP
Keep an error variable for each field. Say,
<?php
$error = array(
"name" => "",
"email" => "",
"subject" => "",
"message" => ""
);
?>
Update them with the errors and display them below.
<?php
if (empty()$_POST["email"])
$error["email"] = "Email is required!";
elseif (!isEmail($_POST["email"]))
$error["email"] = "Not a Valid Email!";
?>
If there are no errors, it would be empty and the user doesn't see the error message. In your Forms Code, you need to just update this way:
<small class="errorText"><?php echo $error["name"]; ?></small>
<small class="errorText"><?php echo $error["email"]; ?></small>
where in the backend, the $error["email"] would have either "This field is required" or "Not a valid email address!".
You can use the following way if your every field has a single error :
<input name='myfield'>
#if ($errors->has('myfield'))
<span style="color:red;">
{{ $errors->first('myfield') }}
</span>
#endif

php form passing extra variable

My script displays a list of offers that I can either deny or approve. The problem I am having is sometimes I click deny and the offer is correctly denied but sometimes I click deny and it is incorrectly approved.
Using Live HTTP Headers I've checked the post data being sent when the offer is incorrectly approved and I see
denymes=Not+In+Downline&status=4&status=1
So the problem is that status is being sent twice.
I don't understand what is wrong. Sometimes it works correctly.
The code in question:
$list.="
<div class=\"borderBox\" id=\"approve_ad_main".$temp[id]."\">
<form name=\"deny".$temp[id]."\" action=\"index.php?view=account&ac=myads&adtype=ptsu&id=$temp[id]&action=approve&".$url_variables."\" method=\"post\">
<div style=\"border:0px solid #000;padding:5px;\" valign=\"top\" colspan=\"2\">Add Denied Message : <input type=\"text\" name=\"denymes\" value=\"\" size=\"50\"><br/>
<small>This is for displaying a message as to why the ad was denied<br/>
Leave blank if approving the ads.</small><br/>
<input type=\"hidden\" name=\"status\" value=\"4\">
<input type=\"submit\" value=\"Deny\" style=\"width:150px;float:left;\">
</form>
<form name=\"approve".$temp[id]."\" action=\"index.php?view=account&ac=myads&adtype=ptsu&id=$temp[id]&action=approve&".$url_variables."\" method=\"post\">
<input type=\"hidden\" name=\"status\" value=\"1\">
<input type=\"submit\" value=\"Approve\" style=\"width:150px;float:left;margin-left:5px;\">
</form>
<br/><br/>
$temp[title]
<div id=\"approve_ad".$temp[id]."\">
Username: $temp[username]<br />
<div style=\"height: 150px; overflow: auto; border: 1px solid #c8c8c8; background-color: white; text-align: left; padding: 5 5 5 5px; color: black\">
<b>Userid Used: </b> $temp[userid]<br />
".nl2br($temp[welcome_email])."
</div>
</div>
</div>
Here's code from view source. Still can't figure out what's wrong.
<div class="borderBox" id="approve_ad_main1000">
<form name="deny1000" action="index.php?view=account&ac=myads&adtype=ptsu&id=1000&action=approve&sid=27TWk0MU39VX4YhlU0Tn&sid2=28TYk&siduid=28&" method="post">
<div style="border:0px solid #000;padding:5px;" valign="top" colspan="2">Add Denied Message : <input type="text" name="denymes" value="" size="50" /><br/>
<small>This is for displaying a message as to why the ad was denied<br/>
Leave blank if approving the ads.</small><br/>
<input type="hidden" name="status" value="4" />
<input type="submit" value="Deny" style="width:150px;float:left;" />
</form>
<form name="approve1000" action="index.php?view=account&ac=myads&adtype=ptsu&id=1000&action=approve&sid=27TWk0MU39VX4YhlU0Tn&sid2=28TYk&siduid=28&" method="post">
<input type="hidden" name="status" value="1" />
<input type="submit" value="Approve" style="width:150px;float:left;margin-left:5px;" />
</form>
<br/><br/>
Beauty Discount Club - (submit Page & Confirm Email)
<div id="approve_ad1000">
Username: dan1190<br />
<div style="height: 150px; overflow: auto; border: 1px solid #c8c8c8; background-color: white; text-align: left; padding: 5 5 5 5px; color: black">
<b>Userid Used: </b> dan<br />
dan
</div>
</div>
</div>
your input tags aren't being closed, which may cause the form close tag to be ignored.
Your current code:
<input type=\"hidden\" name=\"status\" value=\"1\">
Correct code:
<input type=\"hidden\" name=\"status\" value=\"1\" />
Because the form isn't being closed, it is counted as a single form, hence the double status.

Categories