php session on undefinded constant - php

Notice: Use of undefined constant login - assumed 'login' in C:\wamp\www\Online_exam\header.php on line 43
Notice: Use of undefined constant login - assumed 'login' in C:\wamp\www\Online_exam\header.php on line 47
Notice: Use of undefined constant login - assumed 'login' in C:\wamp\www\Online_exam\index.php on line 30
I am new to PHP and learning SESSION, and i am trying to explore on that and i am receiving the above errors. Everything looks correct for me. Please somebody help me.
Index.php
<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Wel come to Online Exam</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="quiz.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
include("header.php");
include("database.php");
extract($_POST);
if(isset($submit))
{
$rs=mysql_query("select * from mst_user where login='$loginid' and pass='$pass'");
if(mysql_num_rows($rs)<1)
{
$found="N";
}
else
{
$_SESSION[login]=$loginid;
}
}
if (isset($_SESSION[login]))
{
echo "<h1 class='style8' align=center>Wel come to Online Exam</h1>";
echo '<table width="28%" border="0" align="center">
<tr>
<td width="7%" height="65" valign="bottom"><img src="image/HLPBUTT2.JPG" width="50" height="50" align="middle"></td>
<td width="93%" valign="bottom" bordercolor="#0000FF"> Subject for Quiz </td>
</tr>
<tr>
<td height="58" valign="bottom"><img src="image/DEGREE.JPG" width="43" height="43" align="absmiddle"></td>
<td valign="bottom"> Result </td>
</tr>
</table>';
exit;
}
?>
<table width="100%" border="0">
<tr>
<td width="70%" height="25"> </td>
<td width="1%" rowspan="2" bgcolor="#CC3300"><span class="style6"></span></td>
<td width="29%" bgcolor="#CC3333"><div align="center" class="style1">User Login </div></td>
</tr>
<tr>
<td height="296" valign="top"><div align="center">
<h1 class="style8">Wel come to Online Quiz</h1>
<span class="style5"><img src="image/paathshala.jpg" width="129" height="100"><span class="style7"><img src="image/HLPBUTT2.JPG" width="50" height="50"><img src="image/BOOKPG.JPG" width="43" height="43"></span> </span>
<param name="movie" value="english theams two brothers.dat">
<param name="quality" value="high">
<param name="movie" value="Drag to a file to choose it.">
<param name="quality" value="high">
<param name="BGCOLOR" value="#FFFFFF">
<p align="left" class="style5"> </p>
<blockquote>
<p align="left" class="style5"><span class="style7">Wel Come to Online
exam. This Site will provide the quiz for various subject of interest.
You need to login for the take the online exam.</span></p>
</blockquote>
</div></td>
<td valign="top"><form name="form1" method="post" action="">
<table width="200" border="0">
<tr>
<td><span class="style2">Login ID </span></td>
<td><input name="loginid" type="text" id="loginid2"></td>
</tr>
<tr>
<td><span class="style2">Password</span></td>
<td><input name="pass" type="password" id="pass2"></td>
</tr>
<tr>
<td colspan="2"><span class="errors">
<?php
if(isset($found))
{
echo "Invalid Username or Password";
}
?>
</span></td>
</tr>
<tr>
<td colspan=2 align=center class="errors">
<input name="submit" type="submit" id="submit" value="Login"> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#CC3300"><div align="center"><span class="style4">New User ? Signup Free</span></div></td>
</tr>
</table>
<div align="center">
<p class="style5"><img src="images/topleft.jpg" width="134" height="128"> </p>
</div>
</form></td>
</tr>
</table>
</body>
</html>
Header.php
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style>
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="image/topbkg.jpg">
<tr>
<td width="90%" valign="top">
<!--You can modify the text, color, size, number of loops and more on the flash header by editing the text file (fence.txt) included in the zip file.-->
<div align="left"><object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,2,0
width=500
height=68>
<param name=movie value=image/fence.swf>
<param name=quality value=high>
<param name=BGCOLOR value=#000000>
<param name=SCALE value=showall>
<param name=wmode value=transparent>
<embed src=image/fence.swf
quality=high
pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash
width=500
height=68
bgcolor=#000000
scale= showall>
</embed>
</object></div></td>
<td width="10%">
<img border="0" src="image/topright.jpg" width="203" height="68" align="right"></td>
</tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#000000" background="img/blackbar.jpg">
<tr>
<td width="100%" align="right"><img border="0" src="image/blackbar.jpg" width="89" height="15"></td>
</tr>
</Table>
<Table width="100%">
<tr>
<td>
<?php "Hi ".$_SESSION[login]; ?>
</td>
<td>
<?php
if(isset($_SESSION[login]))
{
echo "<div align=\"right\"><strong> Home |Signout</strong></div>";
}
else
{
echo " ";
}
?>
</tr>
</table>

session variable should wrap with ' '...
change your session variable like this...
$_SESSION['session_var_name'];
and in your case it should..
$_SESSION['login']

You have to give the session name inside quotes only. Use
$_SESSION['login'] or $_SESSION["login"]

Non-numeric array key constants should be enclosed in quotes, either single or double. Otherwise, php thinks you are referring to a constant name. And since it's undefined, it falls back to guessing you just forgot the quotes...
That's why it works. And that's why the issue appears as a Notice. But in order to do away with it, change $_SESSION[login] to $_SESSION['login'].

Replace $_SESSION[login] into $_SESSION['login'] in all occurance of your code

<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Wel come to Online Exam</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="quiz.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
include("header.php");
include("database.php");
extract($_POST);
if(isset($submit))
{
$rs=mysql_query("select * from mst_user where login='$loginid' and pass='$pass'");
if(mysql_num_rows($rs)<1)
{
$found="N";
}
else
{
$_SESSION['login']=$loginid;
}
}
if (isset($_SESSION['login']))
{
echo "<h1 class='style8' align=center>Wel come to Online Exam</h1>";
echo '<table width="28%" border="0" align="center">
<tr>
<td width="7%" height="65" valign="bottom"><img src="image/HLPBUTT2.JPG" width="50" height="50" align="middle"></td>
<td width="93%" valign="bottom" bordercolor="#0000FF"> Subject for Quiz </td>
</tr>
<tr>
<td height="58" valign="bottom"><img src="image/DEGREE.JPG" width="43" height="43" align="absmiddle"></td>
<td valign="bottom"> Result </td>
</tr>
</table>';
// exit;
}
?>
<table width="100%" border="0">
<tr>
<td width="70%" height="25"> </td>
<td width="1%" rowspan="2" bgcolor="#CC3300"><span class="style6"></span></td>
<td width="29%" bgcolor="#CC3333"><div align="center" class="style1">User Login </div></td>
</tr>
<tr>
<td height="296" valign="top"><div align="center">
<h1 class="style8">Wel come to Online Quiz</h1>
<span class="style5"><img src="image/paathshala.jpg" width="129" height="100"><span class="style7"><img src="image/HLPBUTT2.JPG" width="50" height="50"><img src="image/BOOKPG.JPG" width="43" height="43"></span> </span>
<param name="movie" value="english theams two brothers.dat">
<param name="quality" value="high">
<param name="movie" value="Drag to a file to choose it.">
<param name="quality" value="high">
<param name="BGCOLOR" value="#FFFFFF">
<p align="left" class="style5"> </p>
<blockquote>
<p align="left" class="style5"><span class="style7">Wel Come to Online
exam. This Site will provide the quiz for various subject of interest.
You need to login for the take the online exam.</span></p>
</blockquote>
</div></td>
<td valign="top"><form name="form1" method="post" action="">
<table width="200" border="0">
<tr>
<td><span class="style2">Login ID </span></td>
<td><input name="loginid" type="text" id="loginid2"></td>
</tr>
<tr>
<td><span class="style2">Password</span></td>
<td><input name="pass" type="password" id="pass2"></td>
</tr>
<tr>
<td colspan="2"><span class="errors">
<?php
if(isset($found))
{
echo "Invalid Username or Password";
}
?>
</span></td>
</tr>
<tr>
<td colspan=2 align=center class="errors">
<input name="submit" type="submit" id="submit" value="Login"> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#CC3300"><div align="center"><span class="style4">New User ? Signup Free</span></div></td>
</tr>
</table>
<div align="center">
<p class="style5"><img src="images/topleft.jpg" width="134" height="128"> </p>
</div>
</form></td>
</tr>
</table>
</body>
</html>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style>
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="image/topbkg.jpg">
<tr>
<td width="90%" valign="top">
<!--You can modify the text, color, size, number of loops and more on the flash header by editing the text file (fence.txt) included in the zip file.-->
<div align="left"><object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000
codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,2,0
width=500
height=68>
<param name=movie value=image/fence.swf>
<param name=quality value=high>
<param name=BGCOLOR value=#000000>
<param name=SCALE value=showall>
<param name=wmode value=transparent>
<embed src=image/fence.swf
quality=high
pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash
width=500
height=68
bgcolor=#000000
scale= showall>
</embed>
</object></div></td>
<td width="10%">
<img border="0" src="image/topright.jpg" width="203" height="68" align="right"></td>
</tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#000000" background="img/blackbar.jpg">
<tr>
<td width="100%" align="right"><img border="0" src="image/blackbar.jpg" width="89" height="15"></td>
</tr>
</Table>
<Table width="100%">
<tr>
<td>
<?php
if(isset($_SESSION['login']))
{
print "Hi ".$_SESSION['login'];
}
?>
</td>
<td>
<?php
if(isset($_SESSION['login']))
{
echo "<div align=\"right\"><strong> Home |Signout</strong></div>";
}
else
{
echo " ";
}
?>
</tr>
</table>

Related

How to insert Google Ads in left and right sidebar?

I want on my site to insert Google Ads on left and right sidebar, but I don't know how to create sidebars.
This is code from my header.php code that i have currently:
<?php
include "config.php";
?>
<html>
<head><meta name="adtictac-site-verification"
content="1qvt6zbzk026xfomo6gxbxxhjk9t96obv58gpcv3n9ver69s0"><meta
name="clckd" content="273a893ce34e0acd4ba2655313b5f902" />
<title><?php echo $sitename; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#2C60A9" leftmargin="1" topmargin="0" marginwidth="0"
marginheight="0">
<table width="777" border="2" bgcolor="#ffffff" align="center"
cellpadding="0" cellspacing="0" class="border">
<tr>
<td><img src="images/header.jpg" width="777" height="210" alt=""></td>
</tr>
<tr>
<td background="images/bg.jpg"><table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="30%"><img src="images/links.jpg" width="231" height="17"
alt=""></td>
<td width="7%"><A href="index.php"><img src="images/home.jpg" width="54"
height="17" alt="" border="0"></a></td>
<td width="11%"><A href="join.php"><img src="images/register.jpg"
width="83" height="17" alt="" border="0"></a></td>
<td width="7%"><A href="faq.php"><img src="images/faq.jpg" width="54"
height="17" alt="" border="0"></a></td>
<td width="12%"><A href="contactus.php"><img src="images/contact-us.jpg"
width="98" height="17" alt="" border="0"></a></td>
<td width="12%"><A href="advertise.php"><img src="images/advertise.jpg"
width="92" height="17" alt="" border="0"></a></td>
<td width="21%"><A href="login.php"><img src="images/login.jpg"
width="49" height="17" alt="" border="0"></a></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td class="bodytext"> </td>
<td> </td>
</tr>
<tr>
<td width="7%"> </td>
<td width="91%" class="bodytext"><p align="justify">
<?php
include "config.php";
$rs=mysql_query("select ID,BannerURL from bannersads where remaining>0 and
approved=1 and adtype=1 order by rand() limit 0,1");
while($arr=mysql_fetch_array($rs)) {
echo "<br><center><a href=$siteurl/tr.php?id=$arr[0] target=_blank><img
src=$arr[1] width=468 height=60 border=0></a><br></center><br>";
$rsu=mysql_query("update bannersads set remaining=remaining-1 where
ID=$arr[0]");
}
?>
So can someone share some tips how to create sidebars where need to create placed like shown in image? I tryed inserting this:
<div class="google">
// Google Code here
</div>
and this CSS:
.google {
margin-left:-250px;
}
but looks like broke my content in my homepage.
.google {
left: 250px;
}
Also create a container and give it width in px, not %.
Let me hope that will solve your problem.

Syntax Error on my php script

I am getting this error message when run the code below. Below is the code that is giving me error messages. This is the error message
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\jq\fines\admin\portal.php on line 218
My code:
<body class="easyui-layout">
<div region="north" class="title" border="false" style="height:40px;">
Client Services Admin Portal
</div>
<div region="center" border="false">
<div id="pp" style="position:relative">
<div style="width:30%;">
<div title="Time" style="text-align:center;background:#f3eeaf;height:170px;padding:5px;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100" height="100">
<param name="movie" value="http://www.respectsoft.com/onlineclock/analog.swf">
<param name=quality value=high>
<param name="wmode" value="transparent">
<embed src="http://www.respectsoft.com/onlineclock/analog.swf" width="100" height="100" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed>
</object>
</div>
<div title="Current Users Logged On" collapsible="true" closable="false" style="height:250px;padding:3px;">
<center>
<?php require_once "fines/admin/usersloggedon.php"; ?>
</center>
</div>
</div>
<div style="width:70%;">
<div title="Search for receipt" closable="false" style="height:170px;padding:10px;">
<center>
<form action="" method="post" id="receiptnumSearch">
<input type="hidden" name="check" value="submitted">
<input class="easyui-searchbox" style="width:200px" name="receiptnum" data-options="prompt:'',searcher:doReceiptSearch">
</form>
<br/>
<div style="background-color:#3FF; height:1px"> </div><br/>
<?php
require_once"functions.php";
if($_POST['check']=='submitted')//open1
{
//checking for errors
$receiptnum=trim($_POST['receiptnum']);
if($receiptnum=='')//open
{
//System error
echo SysError('Search field empty', 'index.php?t='.urlencode(base64_encode("admin_fins")).'&o='.md5(date('Y-m-d : t')).'');
die();
}//closed
elseif(!empty($receiptnum))//open
{
?><table class='tablestyle2' width=95% cellpadding=2 cellspacing=0>
<tr valign=top>
<td ><table width="100%" border="0" cellspacing="0" cellpadding="0" class='tablestyle_inner'>
<tr>
<td width="40%" class='tableheader' height="25">Paid From Library</td>
<td width="30%" class='tableheader'>Patron Name</td><td width="30%" class='tableheader'>Receipt Number</td>
</tr>
<?php
$db1w = new PDO('mysql:host=10.40.254.229;dbname=koha_msulibrary;charset=utf8', 'root', 'philly');
$gt_r=$db1w->query("SELECT * FROM fine, borrowers,branch_libs where borrowers.cardnumber=fine.cardnumber AND branch_libs.brunchid=fine.brunchid AND fine.receiptNum='$receiptnum' LIMIT 0,1");
$gt_r_results=$gt_r->fetch(PDO::FETCH_ASSOC);
echo'
<tr>
<td class=\'label\' height="25" align="center">'.$gt_r_results['branch_name'].'</td>
<td class=\'label\' align="center">'.ucwords(strtolower($gt_r_results['firstname'].' '.$gt_r_results['surname'])).'</td>
<td class=\'label\' align="center"><a target="_blank" href="http://www.msu.ac.zw/libraries/jq/fines/receipt.php?invoice='.base64_encode('invoce_view').'&t='.base64_encode($gt_r_results['receiptNum']).'">'.$gt_r_results['receiptNum'].'</a></td>
</tr>';
?>
</table></td></tr></table>
<?
}//closed
}//closed
?>
</center>
</div>
<div title="Library Fines Statistics" closable="false" style="height:250px;text-align:center;">
<center>
<br/><form action="" id="date_range" method="post"><table width="70%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="39%"><input type="hidden" name="date_r" value="date_r"><input name="data1" class="easyui-datebox" value="Start Date" width="200px"></input></td>
<td width="37%"><input name="data2" class="easyui-datebox" value="End Date" width="200px"></input></td>
<td width="24%">View Fines</td>
</tr>
</table></form>
<br/>
<?php
$data1=$_POST['data1'];
$data2=$_POST['data2'];
$date_r=$_POST['date_r'];
$dat=date('Y-m-d');
$da_1=strtotime($data1);
$data_=date('Y-m-d',$da_1);
//$da_2=strtotime($data2_);
//$data2=date('Y-m-d',$da_2);
//checking if date is real date
if((!isRealDate($data1) or !isRealDate($data2) or $dat < $data_ ) and $date_r=='date_r')
{
echo SysError('Incorrect date range', 'index.php?t='.urlencode(base64_encode("admin_fins")).'&o='.md5(date('Y-m-d : t')).'');
die();
}
//end of check
else{
?>
<table width=95% height="125" cellpadding=2 cellspacing=0 class='tablestyle2'>
<tr valign=top><td ><table width="100%" height="122" border="0" cellpadding="0" cellspacing="0" class='tablestyle_inner'> <tr> <td width="50%" class='tableheader' height="19">Branch Library</td> <td width="50%" class='tableheader'>
<?php
if($date_r=='date_r')
{
echo 'Fine collected between '.$data1.' and '.$data2;
}
else
{
echo 'Fines Collected to Date';
}
?></td>
</tr>
<tr>
<td class='label' height="12" >Batanai Library</td>
<td class='label' style="padding-left:10px">
<?php //checking if the date is real
if($date_r!='date_r')
{
echo GETbranchlibs('2');
}
elseif($date_r=='date_r')
{
echo GetBrunchLibsRange($data1,$data2,'2');
}
?></td>
</tr>
<tr>
<td class='label' height="6">GSBL</td>
<td class='label' style="padding-left:10px">
<?php
if($date_r!='date_r')
{
echo GETbranchlibs('3');
}
elseif($date_r=='date_r')
{
echo GetBrunchLibsRange($data1,$data2,'3');
}
?></td>
</tr>
<tr>
<td class='label' height="3" >Law Library</td>
<td class='label' style="padding-left:10px"><?php
if($date_r!='date_r')
{
echo GETbranchlibs('4');
}
elseif($date_r=='date_r')
{
echo GetBrunchLibsRange($data1,$data2,'4');
}
?></td>
</tr>
<tr>
<td class='label' height="3" >Main Library</td>
<td class='label' style="padding-left:10px"><?php
if($date_r!='date_r')
{
echo GETbranchlibs('1');
}
elseif($date_r=='date_r')
{
echo GetBrunchLibsRange($data1,$data2,1);
}
?></td>
</tr>
<tr>
<td class='label' height="2" >Total</td>
<td class='label' style="padding-left:10px; font-weight:bold;"><u><?php
if($date_r!='date_r')
{
echo GETbranchlibs('0');
}
elseif($date_r=='date_r')
{
echo GetBrunchLibsRange($data1,$data2,'0');
}
}
?></u></td>
</tr>
</table></td></tr></table></center>
</div>
</div>
</div>
</div>
You wrote somewhere in there
<? instead of <?php
So just change that and it will work. Tested on http://www.compileonline.com/execute_php_online.php

Why is this script not working? (not getting error, simply posts script and looks like it works)

Below is a contact us script in php, when I click submit at www.mydomain.com.au/contact.html it looks as though it works because I end up at ww.mydomain.com.au/thanks.html.
However the specified email account is not receiving contact emails.
Here is the code for the contact us script found at includes/contact_mail.php
<?php
if(isset($_POST['enter']) && $_POST['enter']==1)
{
$_SESSION['email']=$_POST['email'];
$to="name#domains.com";
$subject='Contact Us Details';
$message="<style>
.textstyle{
font-family:Tahoma;
font-size:11px;
color:#156E00;
text-align:left;
margin-left:10px;
text-decoration:none;
}
</style>";
$message.="<table width=400 border=0>
<tr><td class=textstyle>First Name: </td> <td class=textstyle>".$_POST['fname']."</td></tr>
<tr><td class=textstyle>Last Name: </td> <td class=textstyle>".$_POST['lname']."</td></tr>
<tr><td class=textstyle>E-mail: </td> <td class=textstyle>".$_POST['email']."</td></tr>
<tr><td class=textstyle>Phone Number: </td> <td class=textstyle>".$_POST['tel']."</td></tr>
<tr><td class=textstyle>Comments: </td> <td class=textstyle>".$_POST['que']."</td></tr>
</table>";
$mail_from = "From:".$_POST['email'];
$mail_from .="\r\nContent-type: text/html";
#mail($to,$subject,$message,$mail_from);
header("location: ../thankyou.html");
exit();
}
?>
Here is the code at ww.mydomain.com.au/contact.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="GENERATOR" content="Macromedia Dreamweaver CS3" />
<meta name="author" content="Relyon security" />
<meta name="keywords" content="Camera Surveillance,Spy Cameras,Remote Viewing,Audio recording,Relyon security" />
<meta name="description" content="" />
<meta http-equiv="EXPIRES" content="-1" />
<title>Relyon Security: About Relyon Security</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<script language="JavaScript" type="text/javascript">
function fullcheck()
{
var str=document.contact.email.value;
//alert(str);
if (document.contact.fname.value=="")
{
alert ("Blank space not allowed. Please type your First Name.");
document.contact.fname.select();
return false;
}
if (document.contact.lname.value=="")
{
alert ("Blank space not allowed. Please type your Last Name.");
document.contact.lname.select();
return false;
}
if ((document.contact.email.value).indexOf(" ")>=0)
{
alert ("Blank space not allowed inside email!");
document.contact.email.select();
return false;
}
if (document.contact.email.value.indexOf("#",1) == -1)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.email.value.indexOf("#") == 0)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.email.value.indexOf(".",5) == -1)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.email.value.indexOf(".") == 0)
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if ((document.contact.email.value.lastIndexOf(".")) -(document.contact.email.value.indexOf("#"))<4 )
{
alert("Invalid E-Mail address");
document.contact.email.focus();
document.contact.email.select();
return(false);
}
if (document.contact.tel.value=="")
{
alert ("Blank space not allowed. Please type your Telephone Number.");
document.contact.tel.select();
return false;
}
if (document.contact.que.value=="")
{
alert ("Blank space not allowed. Please enter your question or comment.");
document.contact.que.select();
return false;
}
}
//-->
</script>
</head>
<body>
<table width="1000" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" align="left" width="110" height="186"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
<td width="780" rowspan="2" align="center" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td height="161" valign="top"><img src="images/spacer.gif" alt="" /></td>
</tr>
<tr>
<td valign="top" align="left" class="btn">
<table width="780" border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td width="10" valign="top"><img src="images/btn-left.jpg" alt="" width="10" height="49" /></td>
<td align="center" valign="middle">
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="154" align="center" valign="top">Home Page</td>
<td width="180" align="center" valign="top">Our Services</td>
<td width="244" align="center" valign="top">About relyon security</td>
<td width="182" align="center" valign="top"><span class="navg_contact_activated">Contact Us</span></td>
</tr>
</table>
</td>
<td width="10" valign="top" align="right"><img src="images/btn-right.jpg" alt="" width="10" height="49" /></td>
</tr>
<tr>
<td colspan="3" height="1" bgcolor="#FFFFFF"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
<tr>
<td width="10"><img src="images/left-bot.jpg" alt="" width="10" height="42" /></td>
<td class="shadow"><img src="images/spacer.gif" alt="" width="1" height="1" /></td>
<td><img src="images/rgh-bot.jpg" alt="" width="10" height="42" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td valign="top" align="left" width="110"><img src="images/spacer.gif" alt="" /></td>
</tr>
<tr>
<td valign="top" align="left" width="110" bgcolor="#FFFFFF" height="66"><img src="images/spacer.gif" alt="" /></td>
<td valign="top" align="left" width="110" bgcolor="#FFFFFF"><img src="images/spacer.gif" alt="" /></td>
</tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0" align="center" class="white">
<tr>
<td valign="top" align="left"><table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top" class="inner_text"><span class="head-blue">Contact Us</span><br /><br />
Email address: relyonsecurity#live.com.au
<br />
Phone: 0422 663 489<br />
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0" align="center" class="blue">
<tr>
<td valign="top" align="left"><table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td valign="top">
<form name="contact" method="post" action="includes/contact_mail.php" onsubmit="return fullcheck()">
<table width="90%" border="0" cellpadding="0" cellspacing="3" >
<tr>
<td width="7%"> </td>
<td height="30" colspan="2" align="left" valign="middle"><span class="mandatory">*</span>Required fields</td>
</tr>
<tr>
<td> </td>
<td width="22%" class="form_text"><span class="mandatory">*</span>First Name :</td>
<td width="71%"><input name="fname" type="text" id="fname" size="35" class="inputbox"></td>
</tr>
<tr>
<td> </td>
<td width="22%" class="form_text"><span class="mandatory">*</span>Last Name :</td>
<td width="71%"><input name="lname" type="text" id="lname" size="35" class="inputbox"></td>
</tr>
<tr>
<td> </td>
<td class="form_text"><span class="mandatory">*</span>Email Address :</td>
<td><input name="email" type="text" class="inputbox" id="email" size="35"></td>
</tr>
<tr>
<td width="7%"> </td>
<td class="form_text"><span class="mandatory">*</span>Telephone Number:</td>
<td><input name="tel" type="text" class="inputbox" id="tel" size="35"></td>
</tr>
<tr>
<td> </td>
<td class="form_text"><span class="mandatory">*</span>Please enter your question or comment :</td>
<td><textarea name="que" cols="33" rows="8" id="que" class="inputbox"></textarea></td>
</tr>
<tr>
<td colspan="3" height="5" valign="top"><input name="enter" type="hidden" value="1" /></td>
</tr>
<tr>
<td> </td>
<td class="form_text"> </td>
<td><input type="submit" name="Submit" value="Submit" class="inputbox">
<input type="reset" name="Submit2" value="Reset" class="inputbox"></td>
</tr>
<tr>
<td colspan="3" height="30" valign="top"></td>
</tr>
</table>
</form>
<table width="780" border="0" cellspacing="0" cellpadding="0" align="center" class="footer" height="41">
<tr>
<td valign="top" width="12" height="8"><img src="images/foo-l-top.gif" alt="" width="12" height="8" /></td>
<td><img src="images/spacer.gif" alt="" /></td>
<td align="right" valign="top" width="9" height="8"><img src="images/foo-r-top.gif" alt="" width="9" height="8" /></td>
</tr>
<tr>
<td><img src="images/spacer.gif" alt="" /></td>
<td align="center" valign="middle">©2009 Relyon Security.com All Rights Reserved</td>
<td><img src="images/spacer.gif" alt="" /></td>
</tr>
<tr>
<td valign="bottom" height="8"><img src="images/foo-l-bot.gif" alt="" width="12" height="8" /></td>
<td><img src="images/spacer.gif" alt="" /></td>
<td valign="bottom"><img src="images/foo-r-bot.gif" alt="" width="9" height="8" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Second attempt at script?
<?php
error_reporting(E_ALL)
if(isset($_POST['enter']) && $_POST['enter']==1)
{
$_SESSION['email']=$_POST['email'];
$to="name#domains.com";
$subject='Contact Us Details';
$message="<style>
.textstyle{
font-family:Tahoma;
font-size:11px;
color:#156E00;
text-align:left;
margin-left:10px;
text-decoration:none;
}
</style>";
$message.="<table width=400 border=0>
<tr><td class=textstyle>First Name: </td> <td class=textstyle>".$_POST['fname']."</td></tr>
<tr><td class=textstyle>Last Name: </td> <td class=textstyle>".$_POST['lname']."</td></tr>
<tr><td class=textstyle>E-mail: </td> <td class=textstyle>".$_POST['email']."</td></tr>
<tr><td class=textstyle>Phone Number: </td> <td class=textstyle>".$_POST['tel']."</td></tr>
<tr><td class=textstyle>Comments: </td> <td class=textstyle>".$_POST['que']."</td></tr>
</table>";
$mail_from = "From:".$_POST['email'];
$mail_from .="\r\nContent-type: text/html";
mail($to,$subject,$message,$mail_from);
// header("location: ../thankyou.html");
exit();
}
?>
put error_reporting(E_ALL) at the top of the script, remove # from mail() call and comment string with header() and THEN look for errors

PHP Trying to get string from a table cell with regular expressions

I have the following site and I want with regular expressions to get the text between the following tags
<td colspan="2" align="left" valign="top" bgcolor="#FBFAF4"> ..... </td>
I am trying with the following however it returns an empty array of $matches.
preg_match_all("/<td(.*) bgcolor=\"#FBFAF4\"\>(.*)\<\/td>/",$old_filecontents,$matches);
Which is the correct pattern for this?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Exotiq - Ðñïúüíôá</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7"> <link href="Styles.css" rel="stylesheet" type="text/css"> <link href="stylesheets/Styles.css" rel="stylesheet" type="text/css"> <script src="scripts/PopBox.js" type="text/javascript"></script> <script type="text/javascript"> popBoxWaitImage.src = "images/spinner40.gif"; popBoxRevertImage = "images/magminus.gif"; popBoxPopImage = "images/magplus.gif"; </script> <script type="text/javascript"> AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/ cabs/flash/swflash.cab#version=9,0,28,0', 'width','675','height','445','title','Morpork', 'src','assets/flash/morepork','loop', 'false','quality','high','pluginspage', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash', 'wmode','transparent','movie','assets/flash/morepork'); </script> </head> <body background="images/fonto2.jpg" topmargin="0"> <table width="948" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><table width="948" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="24"> </td> <td height="150" colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="900" height="150"> <param name="movie" value="flash/top02.swf"> <param name="quality" value="high"> <param name="wmode" value="transparent"> <embed src="flash/top02.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="900" height="150"></embed></object></td> <td width="24" height="150"> </td> </tr> <tr> <td height="31" colspan="5" valign="middle"> <div align="center"> <script src="menu/xaramenu.js"></script> <script Webstyle4 src="menu/menu_.js"></script> </div></td> </tr> <tr> <td width="24"> </td> <td width="200" valign="top" background="images/GreenFasa.jpg"> <br> <table width="180" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td height="25" class="styles"> Makuti<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Fun Palm<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Alang-Alang<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> Thatch<br> <hr> </td> </tr> <tr> <td height="25" class="styles"> <strong>Abaca</strong><br> <hr> </td> </tr> <tr> <td height="25" class="styles"> </td> </tr> </table></td> <td colspan="2" align="left" valign="top" bgcolor="#FBFAF4"> <div align="left"> <table width="680" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="600" height="40" class="titles">ÊáôáóêåõÝò - ÏìðñÝëåò - Abaca</td> <td width="50" align="right" valign="middle" class="titles"> <div align="right"><img src="images/uk-flag.jpg" width="30" height="17" border="0"></div></td> </tr> <tr> <td colspan="2" class="body"><p>Ç ïìðñÝëá <strong>Abaca</strong> Ýñ÷åôáé ùò Üîéïò áíôéêáôáóôÜôçò ôçò ïìðñÝëáò Rattan ðïõ åðß 15 ÷ñüíéá óôïëßæåé ôéò åëëçíéêÝò ðáñáëßåò. Ôï <strong>Abaca</strong> åßíáé Ýíá öõóéêü õëéêü ðéï <strong>áíèåêôéêü</strong> êáé ðéï üìïñöï áðü ôï Rattan. <br> Ðáñáäßäåôáé ìå <strong>îýëéíï êïñìü åìðïôéóìïý</strong> Ö8åê.<br> <br> </p> <table width="680" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="340" height="150" valign="middle"> <div align="left"><img src="images/Manufactures/Umbrelas/Abaca/AbacaUmbrela.jpg" width="328" height="500"></div></td> <td width="340" height="150" valign="bottom" class="body"> <table width="340" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/1_Abaca02_s.jpg" width="152" height="101" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/1_Abaca02.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/2_Abaca03_s.jpg" width="150" height="112" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/2_Abaca03.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"><img src="images/Manufactures/Umbrelas/Abaca/3_Abaca01_s.jpg" width="150" height="112" class="PopBoxImageSmall" onclick="Pop (this,50,'PopBoxImageLarge');" title="ÌåãÝèõíóç" pbsrc="images/Manufactures/Umbrelas/Abaca/3_Abaca01.jpg" pbCaption="Abaca - ÏìðñÝëá ðáñáëßáò" popBoxCaptionBelow="true" /></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> <tr> <td width="170" height="130"> <div align="center"></div></td> <td width="170" height="130"> <div align="center"></div></td> </tr> </table></td> </tr> <tr> <td width="340" height="50" valign="top"> <p align="center"> </p></td> <td width="340" height="50" valign="top"> <div align="center" class="perigrafes">ÊëéêÜñåôáé ðÜíù óôéò öùôïãñáößåò ãéá ìåãÝèõíóç</div></td> </tr> <tr> <td width="340" valign="bottom"> <div align="center"> </div></td> <td width="340" valign="bottom"> <p align="center"> </p></td> </tr> <tr> <td width="340" valign="top"> <div align="center"></div></td> <td width="340" valign="top"> <p align="center"> </p></td> </tr> <tr> <td height="20" colspan="2" valign="top"> </td> </tr> </table></td> </tr> </table> <font color="#FFFFFF"></font></div></td> <td width="24" height="420"> </td> </tr> <tr> <td width="24"> </td> <td width="200"> </td> <td width="600"> </td> <td width="100"> </td> <td width="24"> </td> </tr> </table></td> </tr> <tr> <td height="22"><table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#007F3E"> <tr> <td height="25"> <div align="center" class="styles">All rights reserved ® Designed by CONTINENTAL ADVERTISING </div></td> </tr> </table></td> </tr> </table> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-12742174-1"); pageTracker._trackPageview(); } catch(err) {}</script> </body> </html>
Given that the cell you're talking about contains HTML, another table in fact, you can't do traditional termination checking ... or you'll get the content between the cell opening and the first </td> you find. Plus '.' isn't multi-line friendly, so unless your cell opens and terminates on the same line, you'll get no matches.
I'd say don't use regular expressions for this. Try an XML parser.
If you were just getting plain text, that'd be fine, but because you're returning HTML which contains your terminator, you'll need to use a parser with some kind of DOM depth awareness ... ... or find a way to count terminators in regex.

Problem after adding <form>?

When i added <form> to my web page, all my javascript stopped working, and when i put the form at the begining of my table submit wont work, what i am doing wrong. below is my code after testing on other browser it works fine but on Firefox it doesn't
Update: After checking on firefox java error console it appears that Checking Function is defined
Update2: Solved my mistake was <script type="text/jscript"> is wrong thats why on firefox it wasn't working and on the rest it was, it must be <script type="text/javascript">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sabay Afrah.Inc | Contact Us</title>
<script src="js/clear.js" language="javascript" type="text/javascript"></script>
<script src="js/SpryValidationSelect.js" type="text/javascript"></script>
<script type="text/jscript">
function Checking(form){
if(empty(form.fname.value){
alert("do nothing");
}
}
</script>
<style type="text/css">
<!--
body {
background-color: #000;
}
body,td,th {
color: #FFF;
font-size: 14px;
}
.address {
font-family: "Comic Sans MS", cursive;
font-weight: bold;
}
-->
</style>
<link href="theme/style.css" rel="stylesheet" type="text/css" />
<link href="theme/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="enterdb.php" method="post">
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"> </td>
</tr>
<tr>
<td><table width="1006" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4"> </td>
<td width="93" align="right"> </td>
<td width="4"> </td>
<td width="374" ><img src="images/logo.png" width="230" height="114" /></td>
<td width="426" align="right" class="address">
10 GlenLake parkway<br />
Suite 130, mailbox # 76<br />
Atlanta, GA 30328<br />
Phone #: + 678-222-3442<br />
Fax #: +678-222-3401<br />
Office hours: M-F 8:30 a.m. to 5:00 p.m.<br />
</td>
<td width="99"> </td>
</tr>
<tr>
<td colspan="5"><table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td class="title"> </td>
</tr>
<tr>
<td width="84"><br /></td>
<td width="516" class="title">Contact Us</td>
</tr>
</table></td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td>
<table width="883" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="table">
<td width="27" rowspan="10" bgcolor="#330099" class="textable"> </td>
<td colspan="2" bgcolor="#330099" class="textable"> </td>
<td width="29" rowspan="8" bgcolor="#330099" class="textable"> </td>
<td colspan="3" class="textable"> </td>
</tr>
<tr >
<td width="139" height="31" bgcolor="#330099" class="textable">First Name:</td> <td>
<input id="fname" name="fname" type="text" size="40" /> </td>
<td width="150" class="textable">Last Name:</td>
<td width="265" class="textable"><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td ><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td ><input id="lname" name="lname" type="text" size="40" /></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="32" class="textable"> </td>
</tr>
<tr>
<td height="30" class="textable">Subject:</td> <td>
<span id="spryselect1">
<label>
<select name="sub" id="sub">
<option> Choose a Subject</option>
<option> General Question</option>
<option> MemberShip Area</option>
<option> Others</option>
</select>
</label>
<span class="selectRequiredMsg">Please select a Subject.</span></span>
</td>
<td colspan="3" class="textable"> </td>
</tr>
<tr>
<td height="33" class="textable">Company Name:</td> <td> <input id="cname" name="cname" type="text" size="40" /></td>
<td class="textable">Company Address:</td>
<td class="textable"><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input id="cadd" name="cadd" type="text" size="40" onclick="" /></td>
</tr>
</table></td>
<td class="textable"> </td>
</tr>
<tr>
<td height="31" class="textable">Phone Number:</td> <td><input id="phonen" name="phonen" type="text" size="40" /> </td>
<td colspan="3" rowspan="4" class="textable"> </td>
</tr>
<tr>
<td height="31" class="textable">Fax Number:</td><td> <input id="faxn" name="faxn" type="text" size="40" /></td>
</tr>
<tr>
<td height="32" class="textable">Email Address:</td><td><input id="email" name="email" type="text" size="40" /></td>
</tr>
<tr>
<td colspan="2" class="textable"> </td>
</tr>
<tr>
<td valign="top" class="textable">Additional Information:</td>
<td colspan="5" class="textable"><table width="600" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="center">
<textarea id="add" name="add" cols="70" rows="10" /></textarea>
</td>
</tr>
<tr>
<td align="center" class="textable">
<input name="Submit" type="submit" value="Submit" onclick="Checking()"/>
</td>
<td align="center" class="textable">
<input type="reset" value="Clear" />
</td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="6" class="textable"> </td>
</tr>
</table></td>
</tr>
</table>
</form>
<script type="text/javascript">
<!--
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
//-->
</script>
</body>
</html>
Your function wants to take in the form element and your submit button doesn't send anything to the function. I'd assume it's not submitting because your function is erroring out and thus stopping the button as if it were returning false. Fix your JavaScript, try using Firebug to help you find these problems.
Try adding an onsubmit to your form tag:
<form action="enterdb.php" method="post" enctype="application/x-www-form-urlencoded" onsubmit="return Checking(this);">
Then remove the onclick event from the submit button.
You need to pass a form object to the Checking function, hence the this. Also it's usually better to place the handler in the form tag as it'll be called when the user submits the form by either clicking the submit button or by pressing enter elsewhere in the form.
Edited per webdestroya.
generally, suggest that you comment out first clear.js and SpryValidationSelect.js, and then try run your code by adding one by one javascript file to clearly defined what is the file that been crashing with your inline code text.
also try to add name for your form and try like this:
function Checking(form){
if(empty(window.myform.fname.value){
alert("do nothing");
}
}
in a way to debug something, its best to try different method by which sometimes you will spot the not easier.
just my thought. gudluck

Categories