How to change VAR? - php

I've got a part of a PHP script, but it gives a T_CLASS error.
But i'm not sure how to convert the VAR element into a php5 compliant code...
Can somebody help me?
<?php // Defining the "calc" class
if (!class_exists('calc'))
class calc {
var $number1;
}
?>
p.s. this is just part of a bigger code, but it keeps saying: "PHP Syntax Check: Parse error: syntax error, unexpected T_CLASS in your code on line 3". So the error should be either in "class calc {" or in "var $number1;". Please help :P
I had to place the entire code. Just adding the brackets gave me a new error.
<?php // Defining the "calc" class
if (class_exists('calc')) {
class calc {
var $number1;
}
}
function boek($number1)
{
$result =$number1 * 2;
echo "Om een tekst van $number1 pagina's te redigeren, rekenen wij: <strong>€ $result,-*</strong></br>";
echo "<small>*Deze prijs is slechts een indicatie. Om een vrijblijvende offerte aan te vragen kunt u gebruikmaken van het contactformulier onderaan de pagina. <br/><span style=\"text-decoration: underline;\">Let op: studenten krijgen op vertoon van hun studentenpas 25% korting.</span></small>";
}
}
//Creating object of class
$calc = new calc();
?>
<style type="text/css">
.calcbutton {
Cursor: pointer;
display: block;
text-indent: -5000px;
width: 136px;
height: 44px;
border: none;
background-image: url('http://www.mijncreaties.com/wp-content/themes/GoedVerwoord/images/buttons.png');
background-repeat: no-repeat;
}
.calcbutton {background-position: top left;}
.calcbutton:hover {background-position: center left;}
.calcbutton:active {background-position: bottom left;}
</style>
<form name="calc" action="" method="POST">
<table>
<tr>
<td>Aantal pagina's: </td>
<td><input type="text" style="padding-left: 3px;" class="calc-form wpcf7-text" name="value1" value="0" onfocus="if (this.value == '0') {this.value = '';}" onblur="if (this.value == '') {this.value = '0';}"><br>
<input type="hidden" name="oper" value="boek">
</td>
</tr>
</table>
<input type="submit" value="Bereken prijs" name="submit" class="calcbutton">
</form>
<?
if($_POST['submit']){
$number1 = $_POST['value1'];
$oper = $_POST['oper'];
if(!$number1){
echo "<p><font color=\"red\">Vul a.u.b. een getal in.</font></p>";
}
if($oper == "boek"){
$calc->boek($number1);
}
}
?>

Try wrapping it in an extra set of braces:
<?php // Defining the "calc" class
if (!class_exists('calc')) {
class calc {
var $number1;
}
}
?>
Editted to add:
if (class_exists('calc')) {
class calc {
var $number1;
function boek($number1)
{
$result =$number1 * 2;
echo "Om een tekst van $number1 pagina's te redigeren, rekenen wij: <strong>€ $result,-*</strong></br>";
echo "<small>*Deze prijs is slechts een indicatie. Om een vrijblijvende offerte aan te vragen kunt u gebruikmaken van het contactformulier onderaan de pagina. <br/><span style=\"text-decoration: underline;\">Let op: studenten krijgen op vertoon van hun studentenpas 25% korting.</span></small>";
}
}
}
Your closing bracket was in the wrong place.

Wrap brackets around that if:
<?php
// Defining the "calc" class
if (!class_exists('calc')){
class calc {
var $number1;
}
}
?>
You will have the same issue when conditionally creating functions:
<?php
if (!function_exists('new_function')){
function new_function{
return 'awesome';
}
}
?>

Related

php get value out of array with quotes

Hello! I have a few SQL statements and I need to split them, I need the first image tag that occurs in the statement, I have the code for it to split it, but the problem being all of the different quotes. Is there a way to get it out out?
Code I have now:
$array = array('INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120333,139,'Champ Cars 2007','champ-cars-2007','<table style=width: 429px; height: 74px height=74 width=429 border=0><tbody><tr><td><img title=champcar_logo_2007.jpg style=width: 200px; height: 79px height=79 alt=champcar_logo_2007.jpg hspace=5 src=images/stories/Store/champcar_logo_2007.jpg width=200 align=left vspace=5 border=0 /></td><td><div align=justify>Exclusieve toegangskaarten alleen hier te koop! Wilt u tijdens het evenement op 2 september aanwezig zijn? kijk in mijn <a class=undefined href=index.php?option=com_content&task=view&id=94&Itemid=>shop</a> en bestel snel!</div></td></tr></tbody></table><hr />','',0,8,'2007-08-10 16:21:48',367,'','2008-04-17 15:09:13',367,0,'0000-00-00 00:00:00','2007-08-10 00:00:00','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,0,'{"robots":"","author":"","rights":"","xreference":""}');,/* INSERT QUERY */INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120444,140,'Nieuwe helmen voor Nik en Koen','nieuwe-helmen-voor-nik-en-koen','<table border=0> <tbody> <tr> <td valign=top><img style=margin: 0px; width: 200px; height: 124px; border: 0px solid #000000; float: left; src=images/stories/Nieuws/helmen.jpg alt=helmen.jpg title=helmen.jpg height=124 width=200 /></td> <td valign=top>Speciaal uit Amerika zijn afgelopen winter twee nieuwe IRL Bell T6 Interceptors overgevlogen. Samen met de hoofdsponsor Eurogrip en Marcel Brouwers van Tjello Creations</td> </tr> </tbody> </table>','<p>is dit design tot stand gekomen en uiteindelijk super mooi gespoten op de helmen!<br /><br /></p>',1,8,'2008-04-17 15:08:48',367,'','2012-06-20 11:37:19',367,0,'0000-00-00 00:00:00','2008-04-17 14:23:23','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,2088,'{"robots":"","author":"","rights":"","xreference":""}');');
foreach($array as $item) {
$split = preg_split('/src=/', $item);
$split = explode(' ', $split[1]);
echo $split[0] . "\n";
}
I have a few statements in a array:
INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120333,139,'Champ Cars 2007','champ-cars-2007','<table style=width: 429px; height: 74px height=74 width=429 border=0><tbody><tr><td><img title=champcar_logo_2007.jpg style=width: 200px; height: 79px height=79 alt=champcar_logo_2007.jpg hspace=5 src=images/stories/Store/champcar_logo_2007.jpg width=200 align=left vspace=5 border=0 /></td><td><div align=justify>Exclusieve toegangskaarten alleen hier te koop! Wilt u tijdens het evenement op 2 september aanwezig zijn? kijk in mijn <a class=undefined href=index.php?option=com_content&task=view&id=94&Itemid=>shop</a> en bestel snel!</div></td></tr></tbody></table><hr />','',0,8,'2007-08-10 16:21:48',367,'','2008-04-17 15:09:13',367,0,'0000-00-00 00:00:00','2007-08-10 00:00:00','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,0,'{"robots":"","author":"","rights":"","xreference":""}');,/* INSERT QUERY */
INSERT INTO ba793_content(`id`,`asset_id`,`title`,`alias`,`introtext`,`fulltext`,`state`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`checked_out`,`checked_out_time`,`publish_up`,`publish_down`,`images`,`urls`,`attribs`,`access`,`hits`,`metadata`) VALUES( 120444,140,'Nieuwe helme en en','nieuwe-helmn','<table border=0> <tbody> <tr> <td valign=top><img style=margin: 0px; width: 200px; height: 124px; border: 0px solid #000000; float: left; src=images/stories/Nieuws/helmen.jpg alt=helmen.jpg title=helmen.jpg height=124 width=200 /></td> <td valign=top>Speciaal uit Amerika zijn afgelopen winter twee niIRL Bell T6 Interceptors overgevlogen. Samen met de hoofip en Mers van Tjeions</td> </tr> </tbody> </table>','<p>is dit design tot stand gekomen en uiteindelijk super mooi gespoten op de helmen!<br /><br /></p>',1,8,'2008-04-17 15:08:48',367,'','2012-06-20 11:37:19',367,0,'0000-00-00 00:00:00','2008-04-17 14:23:23','0000-00-00 00:00:00','{"image_intro":"images\/headers\/zonderdeur.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/headers\/zonderdeur.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}','{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}','{"article_layout":"","show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_associations":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_page_title":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}',1,2088,'{"robots":"","author":"","rights":"","xreference":""}');
I just want
<img style=margin: 0px; width: 200px; height: 124px; border: 0px solid #000000; float: left; src=images/stories/Nieuws/helmen.jpg alt=helmen.jpg title=helmen.jpg height=124 width=200 />
I am getting now is errors because of the quotes that won't resemble a correct string, anyone know a way to do this?
Parsing SQL is not trivial. (It's not hard either.) If this is a one-off job, you might get away with a few regex to pull out what you want. Otherwise you need to use a parser.
Regex /<img[^>]+>/ will extract image tags. It will fail on a variety of edge cases so don't rely on this and verify the output. And you don't need PHP for this:
egrep -o '<img[^>]+>' < old_db.sql
This is really putting the cart before the horse. Why not use the tool intended for the job: Mysql? Run the inserts, then query the data. Done. If you don't have mysql handy, try sqlite. It looks like it should be able to read your SQL.

How to echo a table for addressbook in PHP

I'm trying to build a addressbook in PHP but I'm stuck at a point. How can I echo a table that automaticaly add a table row to display the next user in the addresbook, and how can I display all the users in my addressbook in the same table?
This is the code I have now.I hope someone can help me
<?php
if (!isset($_SESSION)) { session_start(); }
include "connect.php";
if (!isset($_SESSION['login']) || $_SESSION['login'] !== true || !isset($_SESSION['userid']) || $_SESSION['userid'] == "") {
header('location: login.php');
exit();
// Natuurlijk wel even controleren of de user daadwerkelijk is ingelogd!
// Als de login niet bestaat, terugsturen naar de homepage. Tevens script stoppen met uitvoeren voor de extra veiligheid.
} else {
session_regenerate_id();
// sessio_regenerate_id moet je altijd gebruiken wanneer de autorisatie van een gebruiker veranderd.
// Dit is tegen de hack session fixation, waarbij een hacker meelift op de sessie van een ander.
$userQuery = mysqli_query($conn, "SELECT roepnaam, telefoon, naam, bedrijf, stad, straat1, straat2, provincie, postcode, email FROM address");
// $userid is een integer (getal), en deze zet je in SQL niet tussen quotes.
// Tevens hoeft dit niet geHEX't te worden gezien deze informatie schoon uit de database komt
$user = mysqli_fetch_assoc($userQuery);
// Haal de gegevens uit de database als een associative array
}
?>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>
<table style="width:60%">
<tr>
<th>Roepnaam</th>
<th>Naam</th>
<th>Bedrijf</th>
<th>Telefoon</th>
<th>Email</th>
<th>Straatnaam 1</th>
<th>Straatnaam 2</th>
<th>Postcode</th>
<th>Stad</th>
<th>Provincie</th>
</tr>
<?php
while ($user = mysqli_fetch_assoc($userQuery)) {
?>
<tr>
<td><?php echo $user['roepnaam']; ?></td>
<td><?php echo $user['naam']; ?></td>
<td><?php echo $user['bedrijf']; ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
try:
<?php
while ($user = mysqli_fetch_assoc($userQuery)) {
?>
<tr>
<td><?php echo $user['roepnaam']; ?></td>
<td><?php echo $user['naam']; ?></td>
<td><?php echo $user['bedrijf']; ?></td>
</tr>
<?php
}
?>
for more detail have a look at http://php.net/manual/en/mysqli-result.fetch-assoc.php
Make sure your $conn is included in the script.
If the connection is correct.
Remove previous $user = mysqli_fetch_assoc($userQuery);
and do this:
<?php
while ($user = mysqli_fetch_assoc($userQuery)) {
?>
<tr>
<td><?=$user['roepnaam']?></td>
<td><?=$user['naam']?></td>
<td><?=$user['bedrijf']?></td>
</tr>
<?php
}
?>

Not receiving mails even after successful POST

I got a mailscript which works, I tested it before.
Now all of a sudden with the same code I am not receiving any mails, nor are other people.
I looked in spam and inbox on both outlook and gmail.
This is my mail script:
<?PHP
require_once ('config.php');
require_once("../phpMailer/class.phpmailer.php");
$isValid = true;
if(isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['email']) && isset($_POST['message']))
{
$name = $_POST['name'];
$subject = 'Er is een contact aanvraag op Kijk & Zie : '.$_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$mail = new PHPMailer;
$mail->From = $email;
$mail->FromName = $name;
$mail->addAddress("receiver#live.nl"); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$texts = 'Er is een aanvraag op de website van Kijk & Zie<br /> <br />
<b>Naam:</b> '.$name.'<br />
<b>E-mail adres:</b> '.$email.'<br />
<b>Onderwerp:</b> '.$subject.'<br />
<b>Telefoonnummer:</b>'.$phone.'<br />
<b>Vragen / Opmerkingen:</b> '.$message.'<br /><br /><br />
';
$handtekening = '
<table border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
<tr>
<td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
[contents]
</td>
</tr>
<tr>
<td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
<br><br>Met vriendelijke groet,<br><br>
Helpdesk<br>
<b>Kijk & Zie</b><br>
<p></p>
</td>
</tr>
</table>
<table height="120" border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
<tr>
<td width="250" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
E:
info#website.nl<br>
T:
(0181) 851 859<br>
W:
www.website.nl<br>
</td>
<td align="right" style="font-family:calibri;padding-right:10px;padding-top:5px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
<a href="http://website.nl/" target="_blank" title="Ga naar de website">
<img src="http://www.website-kindercoaching.nl" alt="Ga naar de website" style="font-family:calibri;text-align:right;margin:0px;padding:10px 0 10px 0;" border="0" width="232">
</a>
</td>
</tr>
<tr>
<td colspan="2" style="font-family:calibri;color:#a3a3a3;font-size:11px;margin-top:6px;line-height:14px;">
<br>Dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Als dit bericht niet voor u bestemd is, wordt u vriendelijk verzocht dit aan de afzender te melden. Kijk & Zie staat door de elektronische verzending van dit bericht niet in voor de juiste en volledige overbrenging van de inhoud, noch voor tijdige ontvangst daarvan. Voor informatie over Kijk & Zie raadpleegt u Kijk & Zie.<br><br>
</td>
</tr>
</table>';
$contents = preg_replace('/\[contents]/',$texts, $handtekening);
$mail->msgHTML($contents);
$mail->AltBody = $texts;
if(!$mail->send())
{
$isValid = false;
}
$mail = new PHPMailer;
$mail->From = 'info#website.nl';
$mail->FromName = 'Kijk & Zie';
$mail->addAddress($email); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Bedankt voor uw aanvraag bij Kijk & Zie';
$texts = 'Geachte heer/mevrouw '.$naam.',<br /><br />
Hartelijk dank voor uw aanvraag bij Kijk & Zie<br />
Wij reageren zo spoedig mogelijk op uw aanvraag.<br /><br />
Uw gegevens worden nooit aan derden ter hand gesteld.
';
$contents = preg_replace('/\[contents]/',$texts, $handtekening);
$mail->msgHTML($contents);
$mail->AltBody = $texts;
if(!$mail->send())
$isValid = false;
}
if($isValid == true) {
$result["submit_message"] = _msg_send_ok;
} else {
$result["submit_message"] = _msg_send_error;
}
$array = array(
'isValid' => $isValid
);
echo json_encode($result);
This is the ajax code in case someone needs it:
//contact form
if($(".contact-form").length)
{
$(".contact-form").each(function(){
$(this)[0].reset();
});
$(".submit-contact-form").on("click", function(event){
event.preventDefault();
$("#contact-form").submit();
});
}
$(".contact-form").submit(function(event){
event.preventDefault();
var data = $(this).serializeArray();
var self = $(this);
//if($(this).find(".total-cost").length)
// data.push({name: 'total-cost', value: $(this).find(".total-cost").val()});
self.find(".block").block({
message: false,
overlayCSS: {
opacity:'0.3',
"backgroundColor": "#FFF"
}
});
$.ajax({
url: self.attr("action"),
data: data,
type: "post",
dataType: "json",
success: function(json){
self.find(".submit-contact-form, [name='submit'], [name='name'], [name='email'], [name='message']").qtip('destroy');
if(typeof(json.isOk)!="undefined" && json.isOk)
{
if(typeof(json.submit_message)!="undefined" && json.submit_message!="")
{
self.find(".submit-contact-form").qtip(
{
style: {
classes: 'ui-tooltip-success'
},
content: {
text: json.submit_message
},
position: {
my: "right center",
at: "left center"
}
}).qtip('show');
self[0].reset();
self.find(".cost-slider-input").trigger("change");
self.find(".cost-dropdown").selectmenu("refresh");
self.find("input[type='text'], textarea").trigger("focus").trigger("blur");
}
}
else
{
if(typeof(json.submit_message)!="undefined" && json.submit_message!="")
{
self.find(".submit-contact-form").qtip(
{
style: {
classes: 'ui-tooltip-error'
},
content: {
text: json.submit_message
},
position: {
my: "right center",
at: "left center"
}
}).qtip('show');
}
if(typeof(json.error_name)!="undefined" && json.error_name!="")
{
self.find("[name='name']").qtip(
{
style: {
classes: 'ui-tooltip-error'
},
content: {
text: json.error_name
},
position: {
my: "bottom center",
at: "top center"
}
}).qtip('show');
}
if(typeof(json.error_email)!="undefined" && json.error_email!="")
{
self.find("[name='email']").qtip(
{
style: {
classes: 'ui-tooltip-error'
},
content: {
text: json.error_email
},
position: {
my: "bottom center",
at: "top center"
}
}).qtip('show');
}
if(typeof(json.error_message)!="undefined" && json.error_message!="")
{
self.find("[name='message']").qtip(
{
style: {
classes: 'ui-tooltip-error'
},
content: {
text: json.error_message
},
position: {
my: "bottom center",
at: "top center"
}
}).qtip('show');
}
}
self.find(".block").unblock();
}
});
});
What could it be that's preventing me from receiving/sending any emails?
When I submit the form it gives me a success message, and in the serverlog I can see it is posted succesfully.

goodnight need to keep a calendar event laravel

goodnight need to keep a calendar event laravel and make a calendar but I can not do any other please Amano in this and in advance thank you very much
this is the code of my calendar
<?php
$month=date("n");
$year=date("Y");
$diaActual=date("j");
$diaSemana=date("w",mktime(0,0,0,$month,1,$year))+7;
$ultimoDiaMes=date("d",(mktime(0,0,0,$month+1,1,$year)-1));
$meses=array(1=>"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio",
"Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
?>
<!DOCTYPE html>
<html lang="es">
<head>
<title>calendario </title>
<meta charset="utf-8">
<style>
#calendar {
font-family:Arial;
font-size:12px;
}
#calendar caption {
text-align:left;
padding:5px 10px;
background-color:#003366;
color:#fff;
font-weight:bold;
}
#calendar th {
background-color:#006699;
color:#fff;
width:40px;
}
#calendar td {
text-align:right;
padding:2px 5px;
background-color:silver;
}
#calendar .hoy {
background-color:red;
}
</style>
</head>
<body>
<h1>calendario </h1>
<table id="calendar">
<caption><?php echo $meses[$month]." ".$year?></caption>
<tr>
<th>Lun</th><th>Mar</th><th>Mie</th><th>Jue</th>
<th>Vie</th><th>Sab</th><th>Dom</th>
</tr>
<tr bgcolor="silver">
<?php
$last_cell=$diaSemana+$ultimoDiaMes;
// hacemos un bucle hasta 42, que es el máximo de valores que puede
// haber... 6 columnas de 7 dias
for($i=1;$i<=42;$i++)
{
if($i==$diaSemana)
{
// determinamos en que dia empieza
$day=1;
}
if($i<$diaSemana || $i>=$last_cell)
{
// celca vacia
echo "<td> </td>";
}else{
// mostramos el dia
if($day==$diaActual)
echo "<td class='hoy'>$day</td>";
else
echo "<td>$day</td>";
$day++;
}
// cuando llega al final de la semana, iniciamos una columna nueva
if($i%7==0)
{
echo "</tr><tr>\n";
}
}
?>
</tr>
</table>
</body>
</html>
this is the structure I only need to add the event and select dates mvc but everything goes to get here

Write text inside a < div > from an external function. PHP

Sorry if I have done wrong , is my first question on StackOverflow.
I want to write the value of var after doing several checks that are within the functions and as a result if everything is okey want to print the variables in a particular div. I have created three different div , one to display errors , one to show var and other one for the form.
What I Do That IS THIS:
https://mega.co.nz/#!3EQGQSAL!94ao1u6UhARYaYdjJzfFqY6ln1oPyO9JQ4_ElT7WEkA
Code:
<html>
<head>
<meta charset="UTF-8">
<title>Agenda Alex Ventura</title>
<style type="text/css">
#errores {
display: block;
background-color: grey;
border-color: red;
border-top-style: double;
border-right-style: double;
border-bottom-style: double;
border-left-style: double;
}
#contactos {
margin-top: 20px;
background-color: aquamarine;
}
#formulario{
margin-top: 50px;
}
</style>
</head>
<body>
<div id="errores">
<?php
if (!(isset($_POST['enviar']))) {
//Primera vez
$nombre = "";
$telefono = "";
} else {
if (errores()) {
//Segunda o siguientes veces con error
$nombre = "";
$telefono = "";
} else {
//Todo ok
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
imprimir_datos();
}
}
function errores() {
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
if ((empty($nombre)) || (empty($telefono))) {
echo "Los campos de usuariio y telefono no pueden estar vacíos";
return true;
}
if (strlen($telefono) < 9) {
echo "El telefono debe tener 9 digitos " . strlen($telefono);
return true;
}
if (strlen($telefono) > 9) {
echo "El telefono debe tener 9 digitos " . strlen($telefono);
return true;
}
$expresion = '[0-9]';
if (preg_match($expresion, $telefono) != true) {
echo "El telefono debe tener solo numeros " . ($telefono);
return true;
}
return false;
}
?>
</div>
<div id="contactos">
<?php
function imprimir_datos() {
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
echo "Nombre: $nombre, Telefono: $telefono</br>";
}
?>
</div>
<div id="formulario">
<form action=<?php echo $_SERVER['PHP_SELF'] ?> method="POST">
Nombre : <input type="text" name="nombre" value="<?php echo "$nombre"; ?>"/>
Telefono: <input type="text" name="telefono" value="<?php echo "$telefono"; ?>"/>`enter code here`
<input TYPE="submit" VALUE="Enviar" name="enviar"/>
</form>
</div>
</body>
https://mega.co.nz/#!CA5TmCQJ!utWGpH7PZwpPcHbDK3eTG6JMuTRz_Z6KKAFWtbqPm1o
oh, i see now. Patterns needs delimiters.
change this:
if (preg_match($expresion, $telefono) != true) {
to this:
if (preg_match("/" . $expresion . "/", $telefono) != true)
And for the printing the details, try this. Move the function outside from the div, and call it within the div.
<div id="contactos"><?php imprimir_datos(); ?></div>
<?php
function imprimir_datos() {
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
echo "Nombre: $nombre, Telefono: $telefono</br>";
}
?>

Categories