CSS form border formatting inside PHP file - php

I'm trying to embed some CSS into my PHP file. How can I properly add my CSS so that each called form will be rendered inside a black border? This is what I tried so far.
while ($ratings = mysql_fetch_array($q))
{
//This outputs the doctors's name
echo "Doctor's name:" . $ratings['doctor_name'] ."<br />";
// Retrieve the id of the doctor which was posted on
$id = $_POST['id'];
echo "<style> form { border-style: solid; border-color: #ffffff}";
//This outputs a textarea for the user to submit comments
echo "<b>Your Experience: </b>";
echo "<form method='post' action='review_doctors.php'>
<textarea name='body'></textarea>
<input type='submit' name='submit' value='Send'/>
<input type='hidden' name='id' value='$ratings[id]' />
</style>
</form>
";
echo "<br />";
}

As mentioned in the comments: "The style tag should only include styles".
?>
<style>
form {
border: 3px solid black;
}
</style>
<?php
while ($ratings = mysql_fetch_array($q)) {
echo "<form>...</form>"
}
If you would like to reuse styles you can put them in their own file and then include them on each page:
?>
<link rel="stylesheet" type="text/css" href="/path/to/mystyle.css">
<?php
// ...

Related

Second submit button not showing [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have created a form whose method is "POST" and action is "#", indicating to send the data to the same page.
Now after submitting the form,
A second form appears below which fetches data(according to the selection on first form) from database and gives the user a control to edit the record.
EVERYTHING IS WORKING GOOD AND WELL
The only problem is "*Second form submit button doesn't show up"
My Code of that particular page:(editcategory.php)
<?php
require_once("admin_panel.php");
?>
<!DOCTYPE html>
<head>
<title>Users</title>
<link rel="stylesheet" href="css/footer.css">
<style>
.bodystart{
margin-top:2%;
margin-left:25%;
}
h1{
font-size:xx-large;
}
table {
border-collapse: separate;
border-spacing:5px 5px;
width: auto;
color: #588c7e;
font-family:"Lucida Console", "Courier New", monospace;
font-size: 20px;
text-align: left;
}
th {
background-color: #588c7e;
color: white;
}
option:nth-child(even) {
background-color: #f2f2f2
}
.submitnewcat{
margin-top:3%;
color:#ffffff;
padding:5px;
border-radius:10 px;
background-color:#4CAF50;
cursor:pointer;
}
form{
margin-top:5%;
}
input,select{
border-style:inset;
border-left:6px solid green;
background-color:#ced6e0;
padding: 12px 15px;
border-radius:5px;
}
.catidcont{
background-color:#c7ecee;
cursor:default;
}
label{
padding:12px 15px;
font-size:larger;
background-color:#130f40;
color:#ffffff;
border-radius:5px;
border:2px solid red;
}
</style>
</head>
<body>
<div class="bodystart">
<h1><i>Edit Category</i></h1>
<form method="POST" action="#">
<label>Select Category</label>
<?php
$sql = "SELECT * FROM category";
$result = mysqli_query($db_conn,$sql);
echo "<select name='catset' required>";
echo "<option value=''>Select</option>";
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";
}
echo "</select>";
?>
<button class="submitnewcat" name="submit3" type="submit" value="Submit">Fetch Details</button>
</form>
<?php
if(isset($_POST["submit3"])==true){
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$x=(int)$_POST['catset'];
$sql = "SELECT * FROM category a WHERE a.id=$x";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo "<form method='POST' action='updatecategory.php'";
echo "<input type='hidden' readonly>";
echo "<label>Category ID</label>";
echo "<input type='number' name='catid' value=$x readonly style='cursor:no-drop;'><br><br><br>";
echo "<label>New Category Name</label>";
echo "<input type='text' name='newcatname' required placeholder='".$row['name']."'>";
echo "<label>Status</label>";
echo "<select name='newstat' required>";
if($row["status"]==1){
$catstat="Active";
echo "<option value='".$row['status']."' selected>$catstat</option>";
echo "<option value='2'>Disabled</option>";
}
else{
$catstat="Disabled";
echo "<option value='1'>Active</option>";
echo "<option value='".$row['status']."' selected>$catstat</option>";
}
echo "<button class='submigtnewcat' name='submit4' type='submit' value='Submit'>Fetch Details</button>";
echo "</form>";
}
} ?>
</div>
</body>
<?php
require_once("include/footer.php");?>
</html>
Snippet of my page
there is bug you have not close the tag of select so button is not displaying .
i hope you have got your answer .
echo "<select name='newstat' required>";
if($row["status"]==1){
$catstat="Active";
echo "<option value='".$row['status']."' selected>$catstat</option>";
echo "<option value='2'>Disabled</option>";
}
else{
$catstat="Disabled";
echo "<option value='1'>Active</option>";
echo "<option value='".$row['status']."' selected>$catstat</option>";
}
echo "</select>";

Passing a variable in $_POST parameters not working in PHP?

I am displaying images from a database, each image has a comment box that contains a form and a submit button; the submit button has the name of the image that is displayed. Ex. if the image name is flowers.jpg, the name for the submit button is set to flowers.jpg. (I did string replace though, so in my code it would be set to flowersjpg) The names are added to the submit button with no problem at all. Because I have several images, I wanted to pass $row['image'] (image name) into $_POST[ ] parameters for an isset() function but it is not working. - All the code is in one document
$result = mysqli_query($conn, "SELECT * FROM uploads ORDER BY timestamp DESC");
while($row = mysqli_fetch_array($result))
{
// Prints all the photos with a caption
echo "<div class='wrapper' name=".$row['image'].">";
echo "<div class='caption'>";
echo "<h3>".$row['title']."</h3>";
echo "<p class='description'>".$row['description']."</p>";
echo "</div>";
echo "<img src='images/uploads/".$row['image']."'/>";
// name for submit button, the $row['image'] contains the entire image name so certain characters have to be removed
**$name = str_replace(array(".", "-", ":", "'", "/", " "), "", $row['image']);**
// comment box - just a form with a submit
echo "<div class='commentBox'>
<form action='test.php' method='POST'>
<textarea placeholder='Say something nice!' name='comment'></textarea>
// CREATES NAME FOR BUTTON. FOR EACH IMAGE, THE BUTTON HAS THE IMG NAME
**<button type='submit' name='".$name."' value='submit'> post </button>**
</form>
</div>";
echo "</div>";
}
if(isset($_POST["'".$name."'"]))
{
echo '<script type="text/javascript"> alert("isset"); </script>';
}
When I put the name as a plain string in the $_POST parameters, it works fine but when I put the variable in, it does not work. The $name variable is a string.
This works but I'm sure any string used will work as long as the button name and string in $_POST are the same.
echo "<button type='submit' name='flowerspng' value='submit'> post </button>";
if(isset($_POST[flowerspng]))
{
echo '<script type="text/javascript"> alert("isset"); </script>';
}
This code on the other hand, does not. I know variables can be passed inside $_POST parameters, so I don't understand what's wrong with my code. Is my syntax incorrect? Clearly the variable is not being set otherwise the alert box would pop up.
echo "<button type='submit' name='".$name."' value='submit'> post </button>";
if(isset($_POST["'".$name."'"]))
{
echo '<script type="text/javascript"> alert("isset"); </script>';
}
I have tried this too but I don't think it worked because there are no quotes around $name.
echo "<button type='submit' name=$name value='submit'> post </button>"
if(isset($_POST[$name]))
{
echo '<script type="text/javascript"> alert("isset"); </script>';
}
This code works:
echo "<button type='submit' name='$name' value='submit'> post </button>"
if(isset($_POST[$name]))
{
echo '<script type="text/javascript"> alert("isset"); </script>';
}
I moved the if statement for the isset() function into the end of the while loop, it works for all images now.
while($row = mysqli_fetch_array($result))
{
echo "<div class='wrapper' name=".$row['image'].">";
echo "<div class='caption'>";
echo "<h3>".$row['title']."</h3>";
echo "<p class='description'>".$row['description']."</p>";
echo "</div>";
echo "<img src='images/uploads/".$row['image']."'/>";
$name = str_replace(array(".", "-", ":", "'", "/", " "), "", $row['image']);
echo "<div class='commentBox'>
<form action='test.php' style='text-align: right; background-color: rgb(34,34,34); width: 100%; height: 120%; margin: 0;' method='POST'>
<textarea style='height: 90%; width: 79%; resize: none; border-radius: 3px; margin: 0; margin-top: 5px;' placeholder='Say something nice!' name='comment'></textarea>
<button type='submit' name='$name' value='submit' style='height: 100%; width: 20%; float: right;'> post </button>
</form>
<div class='seeMore'> see more </div>
</div>";
echo "</br><div class='comments' style='display: none;'> comment display </div>";
echo "</div>";
**
// testing the if statement for each image - works perfectly now
if(isset($_POST[$name]))
{
echo '<script type="text/javascript"> alert("'.$name.'"); </script>';
mysqli_query($conn, "UPDATE uploads SET title='test' WHERE image='".$row['image']."'");
header("Refresh:0");
}
**
}

PHP/HTML: Creating an element using php, with the click of a button

I've been trying to do something very complicated (in my opinion, because it doesn't quite work the way I want it to). What I want, is that I have a text field where I type in something, then next to that is a button, and when you type in something in the text field, then press the button a new html element will appear (a box with in there the text you typed in the text field). Now, I've been trying this many different ways. Here's the code I'm using now:
<html>
<head>
<style>
div.cat {
width: 200px;
height: 25px;
border: 1px solid black;
}
</style>
</head>
<?php
$form = "<form method=\"post\" action=\"<?php echo $_SERVER['PHP_SELF']; ?>\"><input type=\"text\" name=\"name\"><br><input type=\"submit\" value=\"Submit\"></form>";
function newCategory() {
$categoryname = $_POST['name'];
$category = "<div class=\"cat\"> <?php $categoryname ?> </div>"
echo $category;
}
?>
<body>
<?php
echo $form;
newCategory();
?>
</body>
</html>
Now, the issue seems to be that if you press the button, the newCategory() function won't execute again. Please help!
EDIT: The issue was in the syntax errors. It's still not working the way I want it to work, though I now know what went wrong. I guess I have to use JavaScript.
try this code...
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<input type="text" id="text1"/>
<input type="button" id="btn" value="Button"/>
<div id="div1">
</div>
<script>
$('#btn').click(function(){
var gettext=document.getElementById("text1").value;
var temp=document.createElement("input");
temp.id="text2";
temp.value=gettext;
$("#div1").html(temp);
});
</script>
You have syntax error,
Replace this to your whole code with this, it is working well
<html>
<head>
<style>
div.cat {
width: 200px;
height: 25px;
border: 1px solid black;
}
</style>
</head>
<?php
$form = "<form method='post' action='".$_SERVER['PHP_SELF']."'><input type='text' name='name'><br><input type='submit' value='Submit'></form>";
function newCategory() {
$categoryname = $_POST['name'];
$category = "<div class='cat'>".$categoryname."</div>";
return $category;
}
?>
<body>
<?php
echo $form;
echo newCategory();
?>
</body>
</html>
The problem is in this line of code: $category = "<div class=\"cat\"> <?php $categoryname ?> </div>".
You cannot have php tags <?php ?> inside another set of php tags.
Just change it to this: $category = "<div class=\"cat\">".$categoryname."</div>";.
And make sure you fix all the other syntax errors as well.

Display single line data in columns mysql/PHP

Currently I have a script that displays the data which is editable and can update the database. I have tried to enter row counts and nothing seem to work. I really like the script to make 3 columns (10 rows per column), please help.
$sql = "SELECT id, pounds FROM price_list ORDER BY id";
$i = 0;
$result = mysql_query($sql);
echo "<form name='prices' method='post' action='updateA.php'>";
while($rows = mysql_fetch_array($result))
{
echo "<body bgColor='#5F5F6B'>";
echo "<table><table border=2 cellspacing=0 cellpadding=1>";
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<td><font color='#FFFFFF'><font size='2'>DAYS {$rows['id']}: </font><font size='2'><font color='#000000'>PRICE:<input type='text' size='1' name='pounds[$i]' value='{$rows['pounds']}' ></tr>";
++$i;
}
echo "</table>";
echo "<input type='submit' value='Update Prices Band A' />";
echo "</form>";
?>
The above is the original code.
I don't really know what you're trying to do, but this code will generate a list of all the entries in the database with the ability to change them. Note that you'll have to remake your update_a.php file:
<style>
body {
background:#5F5F6B;
color:#fff;
}
</style>
<?php
$result = mysql_query("SELECT id, pounds FROM price_list ORDER BY id");
if (!$sql || mysql_num_rows($result)==0)
echo "Price list is empty";
else {
echo '<form name="prices" method="GET" action="update_a.php">'; // Change your filename!
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo 'Day '.$rows['id'].' costs ';
echo '<input type="text" name="'.$rows['id'].'" value="'.$rows['pounds'].'"/> pounds'
echo '<br/>'
$i++;
}
echo '<input type="submit" value="Update Prices Band A"/>';
echo "</form>";
}
?>
First of all many thanks to Leonard Pauli, the code worked perfectly in displaying the data but, it wouldn't update the database using my update.php. Below is the revised code and screenshot of what I was trying to archive.
Screenshot of single lined data displayed in 3 columns
<style>
body {
background:#5F5F6B;
color:#fff;
width:800px;
height:550px;
border:2px solid #bbb;
padding:20px;
float:center;
}
input[type="text"] {
width: 30px;
}
.table {
width:180px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
.header {
width:595px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
</style>
<div class="header"><b>Price List for dates from <font color ="yellow"><?php echo "$SPA"; ?> to <?php echo "$EPA"; ?></font></div>
<?php
$dataprice = $_POST['database'];
$datesrange = $_POST['id'];
$result = mysql_query("SELECT id, pounds FROM $dataprice ORDER BY id");
echo '<form name="prices" method="POST" action="update.php">';
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo '<div class="table">Day <font color="yellow">'.$rows['id'].' </font> costs ';
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<input type='text' name='pounds[$i]' value='{$rows['pounds']}' > Pounds";
echo '<br/></div>';
$i++;
}
echo "<input type='hidden' name='databases' value='$dataprice'>";
echo '<center><input type="submit" value="Update Prices"/>';
echo '<center><font color="yellow"><br><br><br>IF UPDATING PRICE BAND D, ONLY ENTER THE VALUE OF WHICH
PRICES YOU WANT TO INCREASE BY, <br>EXAMPLE: 7 DAYS, IF CURRENT PRICE IS 30, IF YOU WANT TO
CHARGE 34, ONLY ENTER 4 AND LEAVE EVERYTHING ELSE SET TO 0</b></center>';
echo "</form>";
?>
A bit of an idiot really, completely forgot about CSS styling.

Load Google Maps on webpage using Javascript and PHP through drop down form

I am having two drop down lists on a html page. The data is coming from a mysql database and contains information like latitude, longitude and address. The user selects one item from the drop down and clicks on submit.
At this stage, I want to display a google map and put a marker at the latitude and longitude. Then, when the user selects the option from second drop down, I want to just add a marker on that map.
Currently, I am able to load the map once he clicks the submit from first drop down but all the options I tried to drop the pins are not working.
Here is the code I have achieved till now:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once('auth.php');
include ('LoginConfig.php');
include ('FetchAgentDetails.php');
include ('FetchDeliveryDetails.php');
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delivery Management System</title>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA0Rm5aK0BYu1f_TzhjkG97cchHHlQfrQY&sensor=false">
</script>
<style type="text/css">
html {height:100%}
body {height:100%;margin:0;padding:0}
#googleMap {height:100%}
</style>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<style type="text/css">
<!--
.style1 {
font-size: 20px;
font-weight: bold;
}
-->
</style>
<style type="text/css">
table.collection {width:250px;border:2px solid black;border-style: outset;border-collapse:collapse;}
table.collection tr {background-color:#fff; border-bottom: 1px #99b solid;padding:10px;}
table.collection tr:hover {background-color:#ffe;}
table.collection td {display:table-cell;border-bottom: 1px #99b solid; padding:10px;}
table.collection td a {text-decoration:none; display:table-row; padding:0px; height:100%;}
</style>
</head>
<body bgcolor="#8E8E38"
<div style="clear: right;">
<p align="left" class="style1">Welcome Delivery Manager! </p>
<img style="position: absolute; top: 0; right: 0;" src="./Images/logo.jpg" alt="Company Logo" width="90" height="60" align="middle"></img>
</div>
<p align="left">Home</p>
<hr></hr>
<!-- START Main Wrap -->
<form method="post">
<fieldset>
<div style="clear: left;float:left;">
<label for="deliveryList">Delivery Items:</label>
<select name="deliveryList" id="deliveryList">
<option value="Select delivery item" selected="selected">Select delivery item</option>
<?php
$deliveryHandler = new FetchDeliveryDetails();
$itemNameArray = $deliveryHandler->getItemNames();
foreach ($itemNameArray as $innerArray) {
if (is_array($innerArray)) {
$value = $innerArray['itemName'];
echo "<option value=\"$value\"";
if (isset($_POST['deliveryList']) && $_POST['deliveryList'] == $value)
echo 'selected';
echo ">" . $value . "</option>\n";
}
}
?>
</select>
<input type="submit" name="submit" id="submit" value="Submit"/>
</div>
<div style="clear: right;float:right;">
<label for="agentList">Avaliable Agent:</label>
<select name="agentList" id="agentList">
<option value="" selected="selected">Select agent to assign</option>
<?php
$agentHandler = new FetchAgentDetails();
$agentNameArray = $agentHandler->getAgentNames();
foreach ($agentNameArray as $innerArray) {
if (is_array($innerArray)) {
$agentId = $innerArray['agentId'];
$firstNameValue = $innerArray['firstname'];
$lastNameValue = $innerArray['lastname'];
$fullName = $firstNameValue . ' ' . $lastNameValue;
echo "<option value=\"$agentId\">$fullName</option>\n";
}
}
?>
</select>
<input type="submit" name="agentSubmit" id="agentSubmit" value="Check Location"/>
</div>
</fieldset>
</form>
<?php
if (isset($_POST['deliveryList'])) {
$selectedItemName = $_POST['deliveryList'];
$deliveryHander = new FetchDeliveryDetails();
$itemDetailsArray = $deliveryHander->getAllDeliveryDetails($selectedItemName);
foreach ($itemDetailsArray as $valuesArray) {
$itemNameValue = $valuesArray['itemName'];
$itemDescriptionValue = $valuesArray['itemDescription'];
$ownerFirstname = $valuesArray['firstName'];
$ownerLastname = $valuesArray['lastName'];
$dateAdded = $valuesArray['dateAdded'];
$deliveryDate = $valuesArray['deliveryDate'];
$deliveryAddress = $valuesArray['deliveryAddress'];
$deliveryLatitude = $valuesArray['deliveryLatitude'];
$deliveryLongitude = $valuesArray['deliveryLongitude'];
$assignedAgent = $valuesArray['assignedAgentId'];
if ($assignedAgent == 0) {
$assignedAgent = "-";
}
echo "<table border=\"1\" align=\"left\" class =\"collection\">\n";
echo "<tr>\n";
echo "<td >Item Name:<b>$itemNameValue</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Item Description: <b>$itemDescriptionValue</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Owner Name: <b>$ownerFirstname $ownerLastname</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Date Added: <b>$dateAdded</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>Delivery Date: <b>$deliveryDate</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Delivery Address: <b>$deliveryAddress</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Assigned Agent: <b>$assignedAgent</td>";
echo "</tr>";
echo "</table>";
echo "<div id=\"googleMap\" style=\"width:500px;height:380px;\"></div>";
}
}
if (isset($_POST['agentList'])) {
}
?>
</body>
</html>
I almost forgot, this is my first PHP application, in fact my first web application. So please go easy on me. Point out other errors also, but please stick to the question.
Ok got it working by using iframe :) and a bit of php
Reference:
http://www.youtube.com/watch?v=HTm-3Cduafw
echo "<iframe style =\"display: block;
width: 800px;
padding-top: 2px;
height: 400px;
margin: 0 auto;
border: 0;\" width=\"425\" height=\"350\" align=\"center\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\"
src=\"https://maps.google.com/maps?f=d&source=s_d&saddr=$agent_map_url&
daddr=$map_url&hl=en&z=10&t=m&mra=ls&ie=UTF8&output=embed\"></iframe><br/>";

Categories