I am trying to connect with social web sites like facebook,twitter,linkedin etc using Hybridauth
This is what I do to connect with social web sites. I am new to PHP just started to learn and doing this.
index.php
<?php
# start a new PHP session
session_start();
// we need to know it
$CURRENT_URL = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
// print "CURRENT_URL $CURRENT_URL";
// change the following paths if necessary
$config = dirname(__FILE__) . '/hybridauth/config.php';
require_once( "hybridauth/Hybrid/Auth.php" );
try{
$hybridauth = new Hybrid_Auth( $config );
}
catch( Exception $e ){
echo "Ooophs, we got an error: " . $e->getMessage();
}
$provider = "";
// handle logout request
if( isset( $_GET["logout"] ) ){
$provider = $_GET["logout"];
$adapter = $hybridauth->getAdapter( $provider );
$adapter->logout();
header( "Location: index.php" );
die();
}
// if the user select a provider and authenticate with it
// then the widget will return this provider name in "connected_with" argument
elseif( isset( $_GET["connected_with"] ) && $hybridauth->isConnectedWith( $_GET["connected_with"] ) ){
$provider = $_GET["connected_with"];
$adapter = $hybridauth->getAdapter( $provider );
$user_data = $adapter->getUserProfile();
// include authenticated user view
include "authenticated_user.php";
die();
} // if user connected to the selected provider
// if not, include unauthenticated user view
include "unauthenticated_user.php";
authenticated_user.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<style type="text/css" media="screen">
<!--
BODY {
margin: 10px;
padding: 0;
}
H1 {
margin-bottom: 2px;
font-family: Garamond, "Times New Roman", Times, Serif;
}
FIELDSET {
border: 1px solid #ccc;
padding: 1em;
margin: 0;
}
LEGEND {
color: #666666;
}
-->
</style>
</head>
<body>
<br /><br />
<center>
<h1>Welcome <?php echo $user_data->displayName; ?></h1>
<br />
<br />
<table width="600" border="0" cellpadding="2" cellspacing="2">
<tr>
<td valign="top"><fieldset>
<legend>Connected user badge</legend>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="100" rowspan="5">
<?php
if( $user_data->photoURL ){
?>
<img src="<?php echo $user_data->photoURL; ?>" title="<?php echo $user_data->displayName; ?>" border="0" width="100" height="120">
<?php
}
else{
?>
<img src="avatar.png" title="<?php echo $user_data->displayName; ?>" border="0" >
<?php
}
?>
</td>
<td width="60" nowrap><div align="right"><strong>Provider</strong></div></td>
<td align="left" ><?php echo $adapter->id; ?></td>
</tr>
<tr>
<td nowrap><div align="right"><strong>Identifier</strong></div></td>
<td align="left"><?php echo $user_data->identifier; ?></td>
</tr>
<tr>
<td nowrap><div align="right"><strong>Dispaly name</strong></div></td>
<td align="left"><?php echo $user_data->displayName; ?></td>
</tr>
<tr>
<td nowrap><div align="right"><strong>Email</strong></div></td>
<td align="left"><?php
if( $user_data->email ){
echo $user_data->email ;
}
else{
echo "not provided by " . $adapter->id ;
}
?></td>
</tr>
<tr>
<td nowrap valign="top"><div align="right"><strong>Profile URL</strong></div></td>
<td align="left" valign="top"><?php echo $user_data->profileURL; ?></td>
</tr>
<tr>
<td align="right"><strong>Update Status</strong></td>
<td align="center"><input name="updatestatus" id="updatestatus" /></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td valign="top" align="right">
<img src="arrow.gif" align="texttop" style="margin-top:-5px;" >
Log me out
</td>
</tr>
</table>
</center>
</body>
</html>
unathenticated.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<style type="text/css" media="screen">
<!--
BODY {
margin: 10px;
padding: 0;
}
H1 {
margin-bottom: 2px;
font-family: Garamond, "Times New Roman", Times, Serif;
}
FIELDSET {
border: 1px solid #ccc;
padding: 1em;
margin: 0;
}
LEGEND {
color: #666666;
}
INPUT {
display: block;
font-family: Arial, verdana;
padding: 7px;
border: 1px solid #999;
margin: 10px;
}
/* Gradient 2 */
.textbox{
background-image: url(images/bg.png);
border: 1px solid #6297BC;
width: 230px;
}
-->
</style>
</head>
<body>
<br /><br />
<center>
<h1>Social web sites integration</h1>
<br />
<br />
<table width="380" border="0" cellpadding="2" cellspacing="2">
<tr>
<td valign="top"><fieldset>
<legend>Sign-in form</legend>
<table width="00%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td><div align="right"><strong>login</strong></div></td>
<td><input type="text" name="textfield" id="textfield" class="textbox"/></td>
</tr>
<tr>
<td><div align="right"><strong>password</strong></div></td>
<td><input type="text" name="textfield2" id="textfield2" class="textbox"/></td>
</tr>
<tr>
<td> </td>
<td><div align="center">
<input type="submit" value="Sign-in" />
</div></td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td valign="top" align="right">
<!--img src="arrow.gif" align="texttop" style="margin-top:-5px;" -->
<!-- CODE REQUIRED BY THE WIDGET -->
<link media="screen" rel="stylesheet" href="widget/css/colorbox.css" />
<script src="widget/js/jquery.min.js"></script>
<script src="widget/js/jquery.colorbox.js"></script>
<script>
$(document).ready(function(){
$(".widget_link").colorbox({iframe:true, innerWidth:430, innerHeight:222});
});
</script>
<!-- /WIDGET -->
<!--
LINK TO THE WIDGET
return_to: call back this page after authenticatin the user
ts: nocache
-->
Or sign-in with Social web sites
</td>
</tr>
</table>
<br /><br /><br />
<!--b>Note:</b> This is just a proof of concept! it works good enough to try out on Firefox or on Chrome.-->
</center>
</body>
</html>
So please help me how to go about this?, Here I do display user information like first name and last name and picture url. I want to add another text box which will enable to update user status or post wall.
From the User Guide: Update User Status
This method exists:
$adapter->setUserStatus("");
Note From User Guide:
Currently only Facebook, Twitter, Identica, LinkedIn, QQ, Sina, Murmur, Pixnet and Plurk support this feature
You could create a form on authenticated_user.php and add a text field with ID "status_update". When it's submitted, you could check for it and run the setUserStatus method.
// if the user select a provider and authenticate with it
// then the widget will return this provider name in "connected_with" argument
elseif( isset( $_GET["connected_with"] ) && $hybridauth->isConnectedWith( $_GET["connected_with"] ) ){
$provider = $_GET["connected_with"];
$adapter = $hybridauth->getAdapter( $provider );
// *****************************************************
// NEW CODE TO UPDATE USER STATUS
if( isset( $_GET["status_update"] ) && !empty( $_GET["status_update"] ) ) {
$adapter->setUserStatus( $_GET["status_update"] );
}
$user_data = $adapter->getUserProfile();
// include authenticated user view
include "authenticated_user.php";
die();
} // if user connected to the selected provider
Related
I'm going nuts to try to understand why the script below (let's call it script1 is passing session variable $_SESSION['emptystcode'] to bulkstOLD.php but not the other two: $_SESSION['dlstrest'] and $_SESSION['dllist']. I have session_start(); on the first command line of the called script.
All this script1 does is to $_GET the Restaurant and List names and display a form where the user can fill in a CODE field and submit it.
To makes things worse, I've created another script (a simplified version of this caller script) which just set the session variables and calls the same bulkstOLD.php and it works ok. I wonder if this has something to do with the $_GET. Any help would be much appreciated.. Thanks!!
Here is the code:
<?php
session_start();
include ('logged.php');
require_once ('functions.php');
$acisversion = $_SESSION['acisversion'];
reset_all();
$cyear = date(Y);
$cmonth = date(M);
$cday = date(d);
$configs = include('config.php');
$_SESSION["module"] = 'st';
$_SESSION['favstlists_ref'] = 0;
$strest = $dlstrest = $_GET['dlstrest'];
$favstlist = $dllist = $_GET['dllist'];
$restname = 'restname_'.$strest;
$stlistrest = $configs[$restname];
?>
<!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=iso-8859-1"/>
<title>ACIS - Edit Lists</title>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="stmenu.js"></script>
<style type="text/css">
#import url(acis.css);
</style>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<div id="content">
<?php
$_SESSION['stcodesub'] = $stcodesub = $stcode = ($_POST["stcodein"]);
dbfile_init() ;
$_SESSION['stcode'] = $stcode;
if(isset($_POST["editSave"]))
{
connect_db ();
if (!empty($stcode))
{
check_code_for_st_list();
$emptystcode = 0;
}
else
{
$emptystcode = 1;
}
$_SESSION['dlstrest'] = $dlstrest;
$_SESSION['dllist'] = $dllist;
$_SESSION['emptystcode'] = $emptystcode;
if ((!$emptystcode and $codestok) or $emptystcode)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=bulkstOLD.php">';
exit;
}
}
?>
<table width="100%" border="0" align="center">
<tr>
<td width="223" align="left"></td>
<td width="111" align="right"></td>
</tr>
</table>
</style>
<form method="post" id="editLists" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="739" border="0" align="center" cellspacing="0" bgcolor="#171717">
<tr>
<td colspan="3"
style="color:#00CC00;
text-align: left;
padding: 0;
background: #2e2e2e url(images/nav_bar.jpg) repeat-x;
font-size: 0.9em;
color: white;
height:16px;"><script type="text/javascript" src="mainmenu.js"></script></td>
</tr>
<tr>
<td width="502"><h2 style="color:red;"> Atualizar Listas Favoritas de Pratos</h2></style></td>
<td width="231" colspan="2" align="right"><?php echo $configs[footer];?></td>
</tr>
<tr>
<td colspan="3" align="right" ><table width="100%" border="0" align="center">
<tr>
<td align="center">Restaurante:</td>
<td width="84" align="center" valign="bottom">Adicionar Código</td>
<td width="350" align="center">Lista a ser atualizada:</td>
<td width="150" align="left" valign="bottom"><span class="error"><?php echo $favErr;?></span></td>
</tr>
<tr>
<td width="135" align="center"><b><?php echo $stlistrest; ?></b></td>
<td align="center">
<?php
echo $stcodeline;
?>
</td>
<td align="center"><b><?php echo $dllist; ?></b></td>
<td align="right"><input type="submit" name="editSave" style="background-color: #009900; color: #FFFFFF;" value="Submeter" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php
$_SESSION["module"] = 'st';
?>
</div>
</body>
</html>
The only possible explanation for your problem is that you might have not written <?php session_start();?> in the very beginning, before any HTML tags(even doctype). Write it on top of every relevant php document.
Look if all your files are saved as UTF-8 without BOM, not just UTF-8.
This BOM dissables sessions.
And look if all your files are called as they are in the same subdomain.
www.domain.com/file1.php,
ww2.domain.com/file2.php,
domain.com/file3.php
... with diferent subdomains should not work.
I'm trying to update two fields in an individual record. However, when I click the "Update" button and the changes are submitted nothing is posted to the assigned_to=$_POST['assigned'], the completed='_POST['completedTime'] or the id='$_POST['ticket']. I think when I click "Update" it is looking at every field named "assigned"/"completedTime"/ and "ticket". How can I ensure only one record is selected?
<?php require_once('../con.php'); ?>
<?php
//query DB
$query = "SELECT * FROM table";
$results = mysql_query($query, $con) or die (mysql_error() . mysql_error($con));
$row = mysql_fetch_assoc($results);
$totalRows = mysql_num_rows($results);
//Update db
if (isset($_POST['update']))
{
$update = "UPDATE table SET assigned_to=$_POST['assigned'], completed='$_POST['completedTime'] WHERE id='$_POST['ticket']'";
mysql_query($update, $con);
if (!mysql_query($update, $con))
{
die('Error: ' . mysql_error($con));
}
}
?>
<!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></title>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
h1,h2,h3,h4,h5,h6 {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
font-size: 18px;
}
h2 {
font-size: 14px;
}
</style>
</head>
<body>
<h1>Report</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" accept-charset="iso-8859-1">
<hr size="1" noshade="noshade" />
<table border="1" cellpadding="3" cellspacing="0" class="small">
<tr>
<td><strong>TicketNum</strong></td>
<td><strong>User</strong></td>
<td><strong>Category</strong></td>
<td><strong>Description</strong></td>
<th>Comments</th>
<td><strong>Date</strong></td>
<td><strong>AssignedTo</strong></td>
<td><strong>CompletedDate</strong></td>
</tr>
<?php do { ?>
<tr bgcolor="<?php
$colorarray=array('#FFFFFF','#D9ECFF');
$colorarraysize=count($colorarray);
if ($BRB_rowcounter++%1 == 0){
if ($colorarrayindex<($colorarraysize-1)){
$colorarrayindex++;
}else{
$colorarrayindex=0;
}
}
echo "$colorarray[$colorarrayindex]"; ?>">
<td valign="top" nowrap="nowrap"><?php echo $row['id']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['username']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['category']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['title']; ?></td>
<td valign="top"><?php echo $row['issue_details']; ?></td>
<td valign="top" nowrap="nowrap"><?php echo $row['timestamp']; ?></td>
<td valign="top" nowrap="nowrap"><input type="text" name="assigned" value ='<?php echo $row['assigned_to']; ?>'></td>
<td valign="top" nowrap="nowrap"><input type="text" name="completedTime" value ='<?php echo $row['completed']; ?>'></td>
<td><input type="hidden" name="ticket" value ='<?php echo $row['id']; ?>'></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
<?php } while ($row = mysql_fetch_assoc($results)); ?>
</table>
</form>
</body>
</html>
<?php
mysql_free_result($update);
mysql_free_result($results);
?>
Try it:
<?php
require_once('../con.php');
//Update db
if (isset($_POST['update']))
{
$update = "UPDATE table SET assigned_to='{$_POST['assigned']}', completed='{$_POST['completedTime']}' WHERE id='{$_POST['ticket']}'";
$result = mysql_query($update, $con) or die ('Error' . mysql_error($con));
}
//query DB
$query = "SELECT * FROM table";
$results = mysql_query($query, $con) or die (mysql_error() . mysql_error($con));
$totalRows = mysql_num_rows($results);
?>
<!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></title>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
h1,h2,h3,h4,h5,h6 {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
font-size: 18px;
}
h2 {
font-size: 14px;
}
</style>
</head>
<body>
<h1>Report</h1>
<hr size="1" noshade="noshade" />
<table border="1" cellpadding="3" cellspacing="0" class="small">
<tr>
<td><strong>TicketNum</strong></td>
<td><strong>User</strong></td>
<td><strong>Category</strong></td>
<td><strong>Description</strong></td>
<th>Comments</th>
<td><strong>Date</strong></td>
<td><strong>AssignedTo</strong></td>
<td><strong>CompletedDate</strong></td>
</tr>
<?php
while ($row = mysql_fetch_assoc($results)) {
$colorarray = array("#FFFFFF","#D9ECFF");
$colorarraysize = count($colorarray);
if ($BRB_rowcounter++%1 == 0){
if ($colorarrayindex<($colorarraysize-1)){
$colorarrayindex++;
}else{
$colorarrayindex=0;
}
}
$content .= <<< END
<form action="" method="POST" accept-charset="iso-8859-1">
<tr bgcolor="{$colorarray[$colorarrayindex]}">
<td valign="top" nowrap="nowrap">{$row['id']}</td>
<td valign="top" nowrap="nowrap">{$row['username']}</td>
<td valign="top" nowrap="nowrap">{$row['category']}</td>
<td valign="top" nowrap="nowrap">{$row['title']}</td>
<td valign="top">{$row['issue_details']}</td>
<td valign="top" nowrap="nowrap">{$row['timestamp']}</td>
<td valign="top" nowrap="nowrap"><input type="text" name="assigned" value="{$row['assigned_to']}"></td>
<td valign="top" nowrap="nowrap"><input type="text" name="completedTime" value="{$row['completed']}"></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
<input type="hidden" name="ticket" value="{$row['id']}">
</form>
END;
}
echo $content;
mysql_free_result($results);
?>
</table>
Your string interpolation syntax is incorrect. It should be:
$update = "UPDATE table SET assigned_to='{$_POST['assigned']}', completed='{$_POST['completedTime']}' WHERE id='{$_POST['ticket']}'";
You need to put { } around an array reference if the index contains quotes. You can also leave out the quotes:
$update = "UPDATE table SET assigned_to='$_POST[assigned]', completed='$_POST[completedTime] WHERE id='$_POST[ticket]'";
You also had some missing quotes and dollar signs, which I've fixed here.
See the PHP documentation for details of string syntax.
However, this is very poor style, since it's subject to SQL injection. You should preferable use an API that supports prepared queries (PDO, mysqli); if not, assign the $_POST parameters to variables and call mysql_real_escape_string() to sanitize them.
This is my code; I will tell you the issue then.
<?php
//checking for perfect loging
session_start();
$user_name = $_SESSION['username'];
$user_pass = $_SESSION['password'];
require ("connection.php");
if ( $user_name == '' ) {
header('location:home.php');
exit();
}
/////////////////////////////////////
?>
<?php
//collecting posted variables by pressing addanother button
if(isset($_POST['adnother'])) {
$date = $_POST['date'];
$billnmbr = $_POST['billnmbr'];
$itemcode = $_POST['itemcode'];
$itemname = $_POST['itemname'];
$exdate = $_POST['exdate'];
$eachprice = $_POST['eachprice'];
$itmtotal = $_POST['itmtotal'];
$wasFound=false;
$i=0;
// check for >>>>>>>>>>> if the session bill_array array is not set or cart array is empty <<<<<<<<<<<<<<<
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
// Run if the bill_array is empty or not set
$_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
} else {
// Run if the bill has at least one item in it
foreach($_SESSION["bill_array"] as $each_item) {
$i++;
while(list($key,$value)=each($each_item)){
if($key=="itemcode" && $value == $itemcode){
// That item is in cart already so push a error message in to screen
$wasFound = true;
?>
<script type="text/javascript">
var error = "<?= $wasFound ?>";
if(error == "true") {
alert("You trying to add same item twice")
}
</script>
<?php
}//close if condition
}//close while loop
}//close foreach loop
//if the next item is not in the bill and then add it to the bill_array
if($wasFound==false){
array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
}//clos if condition
}//close else statment
}//close ifisset
?>
<!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>Front-end Billing</title>
<link href="main.css" rel="stylesheet" type="text/css" media="all" />
<style type="text/css">
.mainheder {
font-size: 36px;
font-weight: bolder;
color: #00C;
text-align: center;
}
#headertopic {
position:absolute;
left:304px;
top:1px;
width:395px;
height:44px;
z-index:1;
background-color: #999900;
}
#mainmenue {
position:absolute;
left:208px;
top:78px;
width:614px;
height:48px;
z-index:10000;
}
#dateandtime {
position:absolute;
left:790px;
top:251px;
width:208px;
height:82px;
z-index:1;
}
#redcross {
position:absolute;
left:377px;
top:321px;
width:247px;
height:239px;
z-index:0;
}
#usrlogin {
position:absolute;
left:4px;
top:216px;
width:265px;
height:184px;
z-index:1;
}
#address {
position:absolute;
left:2px;
top:462px;
width:204px;
height:155px;
z-index:2;
}
#logdas {
position:absolute;
left:10px;
top:92px;
width:197px;
height:58px;
z-index:1;
}
.logdas {
font-weight: bold;
color: #00F;
}
#pagetheam {
position:absolute;
left:332px;
top:49px;
width:341px;
height:24px;
z-index:1;
text-align: center;
font-size: 18px;
font-weight: bolder;
color: #0CF;
text-decoration: underline;
}
#billingitems {
position:absolute;
left:11px;
top:186px;
width:489px;
height:293px;
z-index:1;
}
#printlayout {
position:absolute;
left:531px;
top:186px;
width:211px;
height:322px;
z-index:1;
text-align: center;
}
.printlayoutshopname {
font-size: 14px;
font-weight: bold;
color: #000;
}
.billaddrs {
font-size: 10px;
}
.bilnmbr {
font-size: 10px;
font-weight: bold;
text-align: left;
}
</style></head>
<body>
<div id="wrap">
<div id="headertopic" class="mainheder">Accoutnig for Phamacy</div>
<p> </p>
<p> </p>
<div id="mainmenue"> <?php // include 'index.html' ;?> </div>
<div id="logdas"><p class="logdas">Logged in as : <?php echo $user_name; ?></p>
<p class="logdas">Date : <?php echo date("Y-m-d") ?></p>
</div>
<div id="pagetheam">Front-end Billing </div>
<div id="billingitems">
<form id="form1" name="form1" method="post" action="biling.php">
<?php $data = mysql_query("SELECT * FROM billnumber ") ;
$info = mysql_fetch_array( $data );
$oldnumber = $info['bill_number'];
$oldnumber= $oldnumber + 1;
$Transaction_number = "PM". $oldnumber ;
?>
<table width="490" height="282" border="0">
<tr>
<td width="160"><input type="hidden" name="date" id="date" value=" <?php echo date("Y-m-d") ?> " /><?php echo date("Y-m-d") ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td width="206">Bill Number</td>
<td width="160"><input type="hidden" name="billnmbr" id="billnmbr" value="<?php echo $Transaction_number; ?>" /><?php echo $Transaction_number; ?></td>
<td width="47"> </td>
<td width="69"> </td>
</tr>
<tr>
<td>Item Code</td>
<td><input type="text" name="itemcode" id="itemcode" tabindex="1" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Name</td>
<td><input type="text" name="itemname" id="itemname" tabindex="2" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Expier Date</td>
<td><input type="text" name="exdate" id="exdate" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Item Price</td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Each :
<input type="text" name="eachprice" id="eachprice" /></td>
<td>Total :
<input type="text" name="itmtotal" id="itmtotal" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="adnother" id="adnother" value="add another item" tabindex="5" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
</div>
<div id="printlayout">
<p><span class="printlayoutshopname">Yasitha Pharacy<br />
</span><span class="billaddrs">22,Colombathanthiri Mawatha, Ethulkotte, Kotte.</span></p>
<table width="211" border="0">
<tr>
<td width="103"><span class="bilnmbr">Bill No: <?php echo $Transaction_number; ?></span></td>
<td colspan="2" class="bilnmbr">Date: <?php echo date("Y-m-d") ?></td>
</tr>
<?php
if(isset($_POST['adnother'])) {
//taking items in the bill to variables if the bill_array is not empty.
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
$cartOutput = "<h2 align='center'> Bill is still empty </hd>";
}
else {
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ): ?>
<tr>
<td class="bilnmbr">Item code: </td>
<td colspan="2" class="bilnmbr"><?php echo $each_item['itemcode']; ?></td>
</tr>
<tr>
<td colspan="3" class="bilnmbr">Item Name:</td>
</tr>
<tr>
<td colspan="3" class="bilnmbr"><?php echo $each_item['itemname']; ?></td>
</tr>
<tr class="bilnmbr">
<td>Each</td>
<td width="98">Qty</td>
<td width="98">Total</td>
</tr>
<tr class="bilnmbr">
<td><?php echo $each_item['eachprice']; ?></td>
<td>20</td>
<td><?php echo $each_item['itmtotal']; ?></td>
</tr>
</table>
<?php endforeach; ?>
<?php
}
}
////////////////////////////////////////
?>
<p>
</p>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<?php //closing div for wrapper?>
</div>
</body>
</html>
I used two dimensional array for insert item details to a session array, after inserting a item I want its details to be displayed in a separate table (right hand side) there is no problem with one item, when I add a item it is viewing in the perfect place, but when I add the second item it is going under that table without creating new row. What is the wrong with what I had done?
I found my error
i ended my foreach loop like this
</tr>
</table>
<?php endforeach;
}
}
////////////////////////////////////////
?>
but now i corrected to this way
</tr>
<?php endforeach;
}
}
////////////////////////////////////////
?>
</table>
now it's all ok.... thank you guys for wasting your time for my silly mistake... sorry.... :(
I keep getting a
"Parse error: syntax error, unexpected ':', expecting ')' in /home/jobkill/public_html/process.php on line 8"
when processing inputs from a page that redirects here. I dont know what to fix,
Here's the code:
<?
$aff = $_GET['aff'] ;
$click_id = $_GET['click_id'] ;
$zipcode = #$_GET['zip'];
$state = #$_GET['custom_state'];
$subid = $_GET['subid'] ;
$urls = array(
“http://consumerheadlinesdaily.com/debt/direct_2de89f.php?
cdb=23&zip=<?print $zipcode?>”,
“http://consumerheadlinesdaily.com/debt/direct_2de89f.php?
cdb=80&zip=<?print $zipcode?>”,
“http://consumerheadlinesdaily.com/debt/direct_2de89f.php?
cdb=46&zip=<?print $zipcode?>”,
“http://consumerheadlinesdaily.com/debt/direct_2de89f.php?
cdb=37&zip=<?print $zipcode?>”,
“http://consumerheadlinesdaily.com/debt/direct_2de89f.php?
cdb=55&zip=<?print $zipcode?>”,
“http://consumerheadlinesdaily.com/debt/direct_2de89f.php?
cdb=71&zip=<?print $zipcode?>”);
$url = $urls[array_rand($urls)];
echo “<meta http-equiv=\"refresh\" content=3; url='$url'>”;
?>
<html>
<HEAD>
<LINK href="./index_files/style2.css" rel="stylesheet" type="text/css">
<STYLE>
#middlename
{
display:none;
visibility:hidden;
}
</STYLE>
<SCRIPT type="text/javascript" src="./index_files/scripts.js"></SCRIPT>
<SCRIPT type="text/javascript"
src="./index_files/functions.js"></SCRIPT>
<script language="JavaScript"
src="http://j.maxmind.com/app/geoip.js"></script>
</HEAD><BODY>
<DIV id="form_complete">
<!-- OPEN MAIN TABLE -->
<TABLE width="100%" height="850" border="0" align="center"
cellpadding="0" cellspacing="0" class="tablebg2">
<TBODY>
<TR>
<TD valign="top" align="center">
<!-- OPEN PLACEMENT TABLE -->
<table width="1010" height="500" border="0" cellspacing="0"
cellpadding="0">
<tr><td height="220" colspan="3"> </td></tr>
<tr>
<td width="51%"><div align="center"><img
src="index_files/blank.gif" border="0" width="425" height="344"
/></div></td>
<td
width="10%">  
; </td
>
<td width="39%" align="left">
<br /><br /><br />
<div id="super-container0">
<div id="wrapper">
<span style="color:#000000;font-weight:bold;font-
size:24px;color:#898;">Now Searching...</span><br /><span
style="color:#000000;font-weight:bold;font-size:32px;"><script
language="Javascript">document.write(geoip_city());</script>, <script
language="Javascript">document.write(geoip_region());</script></span>
<!-- <h2>for <span style="color:#000000;font-weight:bold">30-
34</span> Year Old <span style="color:#000000;font-
weight:bold">Male</span> Drivers</h2> -->
<div id="block"></div>
<div id="progress-bar"><img src="index_files/progress.gif"></div>
</div>
</div>
</DIV>
</td>
</tr>
<tr>
<td height="350" colspan="3"> </td>
</tr>
<tr>
<td colspan="3">
<DIV class="Privacy" style="width: 1000px; margin: 0 auto;">
<P style="font-family:Arial, Helvetica, sans-serif; font-
size:11px; margin: 0px; padding: 0px;">All personal information and
email addresses are kept confidential. By
submitting your expression of interest you are consenting to receive
telephone calls from our participating partners even if you have been
previously listed on a state or federal Do-Not-Call List.
</P><P style="width: 1000px; text-align: center; margin-top: 0px;
padding-top: 0px;"><A href="#" onclick="MM_openBrWindow
('privacy.htm','','scrollbars=yes,width=500,height=
400')" target="_blank" style="font-family:Arial, Helvetica, sans-
serif; font-size:10px; color:#03C">Privacy Policy</A></P>
</DIV></td>
</tr>
</table> <!-- CLOSE PLACEMENT TABLE -->
</TD></TR></TABLE> <!-- CLOSE MAIN TABLE -->
<DIV id="processing" style="display:none">
<br /><br /><br /><br />
<CENTER><img src="./index_files/logo2.gif" /><br /><br />
<H2>Searching for a specialist now ...<BR>Thank you for giving us an
opportunity to assist you today.</H2><STRONG>(Please do not Refresh
page as that will result in an error in the system.)</STRONG><BR>
<IMG src="./index_files/ajax-loader.gif" width="220" height="19"
alt="Processing">
</CENTER>
</DIV>
</BODY></html>
The problem in your code are the quotes.
This character:
“
Is not recognised as a quotation in PHP, you need to use
'
Or
"
Here is the updated code
<?
$aff = $_GET['aff'] ;
$click_id = $_GET['click_id'] ;
$subid = $_GET['subid'];
$zipcode = '';
if (isset($_GET['zip']) {
$zipcode = $_GET['zip'];
}
$state = '';
if (isset($_GET['custom_state']) {
$state = $_GET['custom_state'];
}
$urls = array(
'http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=23&zip=' . $zipcode,
'http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=80&zip=' . $zipcode,
'http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=46&zip=' . $zipcode,
'http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=37&zip=' . $zipcode,
'http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=55&zip=' . $zipcode,
'http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=71&zip=' . $zipcode);
$url = $urls[array_rand($urls)];
?>
<html>
<head>
<meta http-equiv="refresh" content=3; url='<? echo $url ?>'>
<link href="./index_files/style2.css" rel="stylesheet" type="text/css">
<style>
#middlename
{
display:none;
visibility:hidden;
}
</style>
<script type="text/javascript" src="./index_files/scripts.js"></script>
<script type="text/javascript" src="./index_files/functions.js"></script>
<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>
</head>
<body>
<div id="form_complete">
<!-- OPEN MAIN TABLE -->
<table width="100%" height="850" border="0" align="center" cellpadding="0" cellspacing="0" class="tablebg2">
<tbody>
<tr>
<td valign="top" align="center">
<!-- OPEN PLACEMENT TABLE -->
<table width="1010" height="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="220" colspan="3"> </td>
</tr>
<tr>
<td width="51%">
<div align="center">
<img src="index_files/blank.gif" border="0" width="425" height="344" />
</div>
</td>
<td width="10%">
</td>
<td width="39%" align="left">
<br /><br /><br />
<div id="super-container0">
<div id="wrapper">
<span style="color:#000000;font-weight:bold;font-size:24px;color:#898;">Now Searching...</span><br />
<span style="color:#000000;font-weight:bold;font-size:32px;">
<script type="text/javascript">document.write(geoip_city());</script>,
<script type="text/javascript">document.write(geoip_region());</script>
</span>
<!-- <h2>for <span style="color:#000000;font-weight:bold">30-34</span> Year Old
<span style="color:#000000;font-weight:bold">Male</span> Drivers</h2> -->
<div id="block"></div>
<div id="progress-bar"><img src="index_files/progress.gif"></div>
</div>
</div>
</td>
</tr>
<tr>
<td height="350" colspan="3"> </td>
</tr>
<tr>
<td colspan="3">
<div class="Privacy" style="width: 1000px; margin: 0 auto;">
<p style="font-family:Arial, Helvetica, sans-serif; font-size:11px; margin: 0px; padding: 0px;">All personal information and
email addresses are kept confidential. By submitting your expression of interest you are consenting to receive
telephone calls from our participating partners even if you have been
previously listed on a state or federal Do-Not-Call List.</p>
<p style="width: 1000px; text-align: center; margin-top: 0px; padding-top: 0px;">Privacy Policy</p>
</div>
</td>
</tr>
</table> <!-- CLOSE PLACEMENT TABLE -->
</td>
</tr>
</tbody>
</table> <!-- CLOSE MAIN TABLE -->
</div>
<div id="processing" style="display:none">
<br /><br /><br /><br />
<center>
<img src="./index_files/logo2.gif" /><br /><br />
<H2>Searching for a specialist now ...<BR>Thank you for giving us an opportunity to assist you today.</h2>
<strong>(Please do not Refresh page as that will result in an error in the system.)</strong><br>
<img src="./index_files/ajax-loader.gif" width="220" height="19" alt="Processing">
</center>
</div>
</body>
</html>
I have also...
Fixed a couple of HTML errors, with missing closing tags or bad nesting
Rather than using error suppression in PHP (#$_GET['mightnotexist']) I have performed an isset($_GET['mightnotexist']) check
I have normalised the script tags
But I haven't...
Removed the tables being used for layout
Moved the inline styles into the stylesheet
UPDATE:
added whole code, tested and working
replace <?print $zipcode?> with $zipcode
i.e. “http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=23&zip=<?print $zipcode?>”,
into “http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=23&zip=$zipcode”,
and replace quotation marks (“”) to normal ones ("")
basically your code should look like this:
<?php
$aff = $_GET['aff'] ;
$click_id = $_GET['click_id'] ;
$zipcode = #$_GET['zip'];
$state = #$_GET['custom_state'];
$subid = $_GET['subid'] ;
$urls = array(
"http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=23&zip=$zipcode",
"http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=80&zip=$zipcode",
"http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=46&zip=$zipcode",
"http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=37&zip=$zipcode",
"http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=55&zip=$zipcode",
"http://consumerheadlinesdaily.com/debt/direct_2de89f.php?cdb=71&zip=$zipcode");
$url = $urls[array_rand($urls)];
?>
<html>
<HEAD>
<LINK href="./index_files/style2.css" rel="stylesheet" type="text/css">
<STYLE>
#middlename
{
display:none;
visibility:hidden;
}
</STYLE>
<SCRIPT type="text/javascript" src="./index_files/scripts.js"></SCRIPT>
<SCRIPT type="text/javascript"
src="./index_files/functions.js"></SCRIPT>
<script language="JavaScript"
src="http://j.maxmind.com/app/geoip.js"></script>
<meta http-equiv="refresh" content="3;url=<?php echo $url; ?>">
</HEAD><BODY>
<DIV id="form_complete">
<!-- OPEN MAIN TABLE -->
<TABLE width="100%" height="850" border="0" align="center"
cellpadding="0" cellspacing="0" class="tablebg2">
<TBODY>
<TR>
<TD valign="top" align="center">
<!-- OPEN PLACEMENT TABLE -->
<table width="1010" height="500" border="0" cellspacing="0"
cellpadding="0">
<tr><td height="220" colspan="3"> </td></tr>
<tr>
<td width="51%"><div align="center"><img
src="index_files/blank.gif" border="0" width="425" height="344"
/></div></td>
<td
width="10%">  
; </td
>
<td width="39%" align="left">
<br /><br /><br />
<div id="super-container0">
<div id="wrapper">
<span style="color:#000000;font-weight:bold;font-
size:24px;color:#898;">Now Searching...</span><br /><span
style="color:#000000;font-weight:bold;font-size:32px;"><script
language="Javascript">document.write(geoip_city());</script>, <script
language="Javascript">document.write(geoip_region());</script></span>
<!-- <h2>for <span style="color:#000000;font-weight:bold">30-
34</span> Year Old <span style="color:#000000;font-
weight:bold">Male</span> Drivers</h2> -->
<div id="block"></div>
<div id="progress-bar"><img src="index_files/progress.gif"></div>
</div>
</div>
</DIV>
</td>
</tr>
<tr>
<td height="350" colspan="3"> </td>
</tr>
<tr>
<td colspan="3">
<DIV class="Privacy" style="width: 1000px; margin: 0 auto;">
<P style="font-family:Arial, Helvetica, sans-serif; font-
size:11px; margin: 0px; padding: 0px;">All personal information and
email addresses are kept confidential. By
submitting your expression of interest you are consenting to receive
telephone calls from our participating partners even if you have been
previously listed on a state or federal Do-Not-Call List.
</P><P style="width: 1000px; text-align: center; margin-top: 0px;
padding-top: 0px;"><A href="#" onclick="MM_openBrWindow
('privacy.htm','','scrollbars=yes,width=500,height=
400')" target="_blank" style="font-family:Arial, Helvetica, sans-
serif; font-size:10px; color:#03C">Privacy Policy</A></P>
</DIV></td>
</tr>
</table> <!-- CLOSE PLACEMENT TABLE -->
</TD></TR></TABLE> <!-- CLOSE MAIN TABLE -->
<DIV id="processing" style="display:none">
<br /><br /><br /><br />
<CENTER><img src="./index_files/logo2.gif" /><br /><br />
<H2>Searching for a specialist now ...<BR>Thank you for giving us an
opportunity to assist you today.</H2><STRONG>(Please do not Refresh
page as that will result in an error in the system.)</STRONG><BR>
<IMG src="./index_files/ajax-loader.gif" width="220" height="19"
alt="Processing">
</CENTER>
</DIV>
</BODY></html>
replace "refresh" in your echo with \"refresh\"
and
<?print $zipcode?>
in array with
$zipcode
Update:
Checked your code and was able to reproduce your error. You're not using double quotes but some other obscure quotes that is not supported by PHP.
Proper double quotes are literally ". You can learn about the details in the PHP manual.
You probably made an error while copy and pasting code from somewhere else in the internet that was changing code's quote's on the fly for styling and display reason.
Take care. The other problems in your code still stand (see other answers as well).
Try
echo "<meta http-equiv=\"refresh\" content=\"3; url='$url'\">";
instead of the similar but different line in your screenshot (it's no text, so I can't quote it and highlight the places you made errors in there, so sorry 'bout that).
This does not create the syntax error you're asking about however.
I just can't get my variables to carry over to the next page. The variable assignment works fine on the initial page (tested), but the value goes null when going to the next. Plz Help!
Page 1:
<?PHP session_start(); ?>
<HTML>
<HEAD>
<META NAME='robots' CONTENT='noindex,nofollow'>
<TITLE>Master Chief's Gamestore</TITLE>
<STYLE type="text/css">
BODY {
color: #ffffff;
background: url('~/halo-reach.jpg');
background-repeat: no-repeat;
background-position: top;
background-color: black;
}
</STYLE>
</HEAD>
<body vLink='#3366CC' link='#3366CC' alink='#3366CC'>
<br/><br/><br/><br/><br/>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<table width="50%" cellspacing="0" cellpadding="25" border="0">
<form method="post">
<tr bgcolor="#666633">
<th id="header" align="left" colspan="3">
<DIV align="center">
<font face="Verdana, Arial, Helvetica" color="white" size="3">
Master Chief's Gamestore </font>
</DIV>
</th>
</tr>
<tr bgcolor="#A3A385">
<td width="100%" valign="middle" colspan="2">
<font face="Verdana, Arial, Helvetica" size="2">
<div align="center"><br/><br/>
Username: 
<input type="text" name="username"> 
Password: 
<input type="password" name="password"><br/>
<br/><input type="submit" name="act" value="Login"><br/>
<input type="submit" name="act" value="Register"><br/>
<input type="submit" name="act" value="Main"><br/> <br/><br/>
</div>
</font>
</td>
</tr>
<?PHP
if ($_POST['act'] == "Login") {
mysql_connect("~", "~", "~") or die("unable to connect to server");
mysql_select_db("~") or die("unable to select database");
$user = $_POST['username'];
$pass = $_POST['password'];
$query = "select * from users where user like '%" . $user . "%' and pass like '%" . $pass . "%';";
$result = mysql_query($query);
$rows = mysql_numrows($result);
if ($rows == 0 || strlen($user) == 0) {
echo "<br />Login Failure";
} else {
$_SESSION['user'] = mysql_result($result, 0, "user");
$_SESSION['id'] = mysql_result($result, 0, "P_Id");
header('Location: ~/success.php');
}
}
if ($_POST['act'] == "Register") {
header('Location: ~/register.php');
}
if ($_POST['act'] == "Main") {
header('Location: ~/index.php');
}
?>
<div align="center">
<tr bgcolor="#666633">
<td align="left">
Logged in as:
<?PHP
$user = $_SESSION['user'];
if (!$user) {
$user = 'Guest';
}
echo $user;
?>
</td>
<td align="right">
Password: 
<input type="password" name="srcpw">
<input type="submit" name="dspphp" value="Display PHP">
</td>
</tr>
</div>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
Page 2:
<?PHP session_start(); ?>
<HTML>
<HEAD>
<META NAME='robots' CONTENT='noindex,nofollow'>
<TITLE>Master Chief's Gamestore</TITLE>
<STYLE type="text/css">
BODY {
color: #ffffff;
background: url('~/halo-reach.jpg');
background-repeat: no-repeat;
background-position: top;
background-color: black;
}
</STYLE>
</HEAD>
<body vLink='#3366CC' link='#3366CC' alink='#3366CC'>
<br/><br/><br/><br/><br/>
<table width='100%' height='80%'>
<tr>
<td align='center' valign='middle'>
<table width="30%" cellspacing="0" cellpadding="25" border="0">
<form method="post">
<tr bgcolor="#666633">
<th id="header" align="left" colspan="3">
<DIV align="center">
<font face="Verdana, Arial, Helvetica" color="white" size="3">
Master Chief's Gamestore </font>
</DIV>
</th>
</tr>
<tr bgcolor="#A3A385">
<td width="100%" valign="middle" colspan="2">
<font face="Verdana, Arial, Helvetica" size="2">
<div align="center">
<br/><br/>Success<br/><br/>
<input type='submit' name='main' value='Main'>
<?PHP
if ($_POST['main'] == "Main") {
header('Location: http://~/index.php');
}
if ($_POST['act'] == "Display Code") {
if ($_POST['pw'] == "pass") {
highlight_file("success.php");
}
}
?>
</div>
</font>
</td>
</tr>
<div align="center">
<tr bgcolor="#666633">
<td align="left">
Logged in as:
<?PHP
$user = $_SESSION['user'];
if (!$user)
$user = 'Guest';
echo $user;
?>
</td>
<td align="right">
Password: 
<input type="password" name="pw">
<input type="submit" name="dspphp" value="Display PHP">
</td>
</tr>
</div>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
EDIT: I've tried this sample code and it does NOT work.
Page 1:
<?php
session_start();
if (isset($_GET['link'])) {
$_session['myvariable'] = 'Hello World';
header('Location: http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']) . '/page2.php');
exit;
}
?>
Click Here
Page 2:
<?php
session_start();
print 'Here is page two, and my session variable: ';
print $_session['myvariable'];
exit;
?>
But as I posted below, I have used sessions in other pages successfully on the same server. Soo frustrating....
Thanks for all the posts btw!
Make sure cookies are enabled so the second page actually re-creates the session of the first page instead of creating a new, empty one. Check out http://www.php.net/manual/en/session.idpassing.php for details.
EDIT
Another possible cause for sessions not working as expected, especially if it only affects certain pages, is that you have accidental whitespace or other output before your first 'session_start() error
It looks like you are just redirecting the user to the second page without posting anything. You would want to set hidden variables and actually submit your form to the second page. Re-directing will lose all the post variables.
If you want to send variables to the second page with a redirect, you can use session variables or a GET variable passed in with the URL to the second page.
Try using
$_SESSION['myvariable'] = 'Hello World';
in upper case