Get logged in username with php from database - php

in the first php code !$fgmembersite->CheckLogin() works perfectly. also next in the html code <?= $fgmembersite->UserFullName(); ?>! works perfectly. But in the second php it won't work correctly. Am I doing something wrong in that code? if($row['name']=="$fgmembersite->UserFullName()")
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Home page</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div id='fg_membersite_content'>
<h2>Home Page</h2>
Welcome back <?= $fgmembersite->UserFullName(); ?>!
</div>
</body>
<?php
include("db.php");
$select=mysql_query("select * from commenttable");
while($row=mysql_fetch_array($select))
{
if($row['name']=="$fgmembersite->UserFullName()")
{
echo "<div id='sty'>";
echo "<img src='files/fav icon.png'"."' width='50px' height='50px' align='left' />";
echo "<div id='nameid'>".$row['name']."</div>";
echo "<div id='msgid'>".$row['message']."</div>";
echo "</div><br />";
}else{
ob_start();
echo "<div id='sty'>";
echo "<img src='files/fav icon.png'"."' width='50px' height='50px' align='left' />";
echo "<div id='nameid'>".$row['name']."</div>";
echo "<div id='msgid'>".$row['message']."</div>";
echo "</div><br />";
ob_end_clean();
}
}
?>

You have an error with your PHP, you have enclosed what should be PHP code within a string causing it to output as you have typed.
Change the following line:
if($row['name']=="$fgmembersite->UserFullName()")
To the following:
if($row['name']==$fgmembersite->UserFullName())

Related

How to show calculated history in php

I'm creating a calculator using PHP and would like to show what has been calculated (list the calculated history) but I have no idea how to store and display the information.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Basic PHP Calculator</title>
</head>
<body>
<?php
//var_export($_POST);
//echo "<br>";
$buttons=[1,3,5,'+',7,9,0,'/','C','='];
$pressed='';
if(isset($_POST['pressed']) && in_array($_POST['pressed'],$buttons)){
$pressed=$_POST['pressed'];
}
$stored='';
if(isset($_POST['stored']) && preg_match('~^(?:[\d.]+[*/+-]?)+$~',$_POST['stored'],$out)){
$stored=$out[0];
}
$display=$stored.$pressed;
//echo "$pressed & $stored & $display<br>";
if($pressed=='C'){
$display='';
}elseif($pressed=='=' && preg_match('~^\d*\.?\d+(?:[*/+-]\d*\.?\d+)*$~',$stored)){
$display.=eval("return $stored;");
}
echo "<form action=\"\" method=\"POST\">";
echo "<table style=\"width:300px;border:solid thick black;\">";
echo "<tr>";
echo "<td colspan=\"4\">$display</td>";
echo "</tr>";
foreach(array_chunk($buttons,4) as $chunk){
echo "<tr>";
foreach($chunk as $button){
echo "<td",(sizeof($chunk)!=4?" colspan=\"4\"":""),"><button name=\"pressed\" value=\"$button\">$button</button></td>";
}
echo "</tr>";
}
echo "</table>";
echo "<input type=\"hidden\" name=\"stored\" value=\"$display\">";
echo "</form>";
?>
</body>
</html>
Expected to get a list of what has been calculated like:
Calculate history:
2+2=4
3+4=7
Append results in SESSION only when isequalto(=) button pressed:
session_start();
elseif($pressed=='=' && preg_match('~^\d*\.?\d+(?:[*/+-]\d*\.?\d+)*$~',$stored)){
$display.=eval("return $stored;");
$_SESSION["list"].=$display."<br>";
}
And finally display the history:
<?php echo $_SESSION["list"];?>

echo HINDI language word stored in an array in PHP script

I am trying to echo hindi script words stored in an array. The output is getting displayed when i use print_r() but not when i use echo. The code is below. what changes do I need to make?
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<?php
$base_arr=array("सूर्योदय","कँगन","ख गोल","गँगरी","घंटाघर","चंचल","छूईमुई","जिज्ञासा","झंकार","टिकट","ठंढाई","डांटना","तौलिया","थकान","दंगल","धुँधला","निंदनीय","पँखुडी","फाइल","बाँटना","भँवर","मंजीरा","यंत्रक","रुकावट","लेकिन","वंचित","शांतनु","षडयंत्र","सँजोग","हिंदुस्तान","अजय","आँकड़े","इंकार","ईखराज","उँगली","ऊगना","एजेंसी","ऐंठना","ओवन","औलाद");
shuffle($base_arr);
print_r($base_arr);
?>
<table border=”1px” bordercolor="#F660AB" bgcolor="#FCDFFF" width=30% height=50% align=center>
<?php
for($i=0;$i<6;$i++)
{
echo"<tr>";
for($j=0;$j<6;$j++)
{
?>
<td> <center><h5><?php echo $base_arr[$i][$j]; ?> </h5></center><
<?php
}
echo"</tr>";
}
?>
You are using 1D array as 2D array
Try this:-
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<?php
$base_arr=array("सूर्योदय","कँगन","ख गोल","गँगरी","घंटाघर","चंचल","छूईमुई","जिज्ञासा","झंकार","टिकट","ठंढाई","डांटना","तौलिया","थकान","दंगल","धुँधला","निंदनीय","पँखुडी","फाइल","बाँटना","भँवर","मंजीरा","यंत्रक","रुकावट","लेकिन","वंचित","शांतनु","षडयंत्र","सँजोग","हिंदुस्तान","अजय","आँकड़े","इंकार","ईखराज","उँगली","ऊगना","एजेंसी","ऐंठना","ओवन","औलाद");
shuffle($base_arr);
print_r($base_arr);
?>
<table border=”1px” bordercolor="#F660AB" bgcolor="#FCDFFF" width=30% height=50% align=center>
<?php
$x =0;
for($i=0;$i<6;$i++)
{
echo"<tr>";
for($j=0;$j<6;$j++)
{
?>
<td> <center><h5><?php echo $base_arr[$x]; ?> </h5></center>
<?php
$x++;
}
echo"</tr>";
}
?>

Live Search in PHP and MySQL (not working in array?)

Good Day,
I have a page where the list of data taken from the db are being fetched in an array. Here's the code:
<table width="100%">
<thead>
<tr>
<th>Name:</th>
<th>Address:</th>
<th>Birthday:</th>
</tr>
</thead>
$samp=mysql_query("select * from client order by id asc");
$counter=0;
while($row=mysql_fetch_array($samp))
{
$id = $row['id'];
$name = $row['name'];
$address = $row['address'];
$birthday = $row['birthday'];
if($counter%2)
{
?>
<tbody>
<tr id="<?php echo $id; ?>">
<?php } else { ?>
<tr id="<?php echo $id; ?>">
<?php } ?>
<td>
<span class="text"><?php echo $id.". ".$name; ?></span>
</td>
<td>
<span class="text"><?php echo $address; ?></span>
</td>
<td>
<span class="text"><?php echo $birthday; ?></span>
</td>
<tr>
<!--and so on -->
</tbody>
I saw this reference Live Search Jquery and have tried if this will gonna work with my program. But much to my surprise it only appears to work for the pre-defined values. But when I tried to use it to my table which has the this Live Search didn't work.
Too bad, since this reference is what am really trying to achieve. Since it already searches for the words without waiting for the user to complete his/her search.
Anyone who has an opinion?
Test it:
index.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" />
<script>
function showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").innerHTML="";
return;
}
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
<title>main page</title></head>
<body>
<form>
<input type="text" size="30" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>
</body>
</html>
livesearch.php
<!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>Untitled Document</title>
</head>
<body>
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("links.xml");
$x=$xmlDoc->getElementsByTagName('link');
//get the q parameter from URL
$q=$_GET["q"];
//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('title');
$z=$x->item($i)->getElementsByTagName('url');
if ($y->item(0)->nodeType==1)
{
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"' target='_blank'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
//output the response
echo $response;
?>
</body>
</html>
links.xml
<?xml version="1.0" encoding="utf-8"?>
<links>
<link>
<title>about</title>
<url>main.html</url>
</link>
<link>
<title>Gmail</title>
<url>www.google.com</url>
</link>
<link>
<title>yahoo</title>
<url>www.google.com</url>
</link>
<link>
<title>bing</title>
<url>www.google.com</url>
</link>
<link>
<title>torrent search</title>
<url>www.google.com</url>
</link>
<link>
<title>Zend</title>
<url>www.google.com</url>
</link>
</links>

how to read the path of swf file from MYSQL , then view it on the web

My code below does not work.
nisreen is the name of DB , and the table name is ana.
What I want is to read the path of the SWF file from the database, then view it on the web-page.
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<?php
$con =mysql_connect("localhost","root","");
mysql_select_db("nisreen", $con);
$result = mysql_query("SELECT * FROM ana LIMIT 1");
while($row = mysql_fetch_array($result))
{
$row['title'];
}
echo '</head>';
echo '<body>';
echo $row;
echo '<object data="'.$row . "'";
echo "type='application/x-shockwave-flash' width='600' height='600'>";
echo '</object>';
echo '
</body>
</html>';
?>
You're not assigning your fetched data to a variable, $row exists only in the scope of that while loop. try something like
<?php
$con =mysql_connect("localhost","root","");
mysql_select_db("nisreen", $con);
$result = mysql_query("SELECT * FROM ana LIMIT 1");
while($row = mysql_fetch_array($result))
{
$title = $row['title'];
$path = $row['path'];
}
echo '</head>';
echo '<body>';
echo $title;
echo '<object data="'.$path. "'";
echo "type='application/x-shockwave-flash' width='600' height='600'>";
echo '</object>';
echo '
</body>
</html>';
?>

Html Validation PHP

I have an HTML file that won't validate and I keep getting the error Line 65, Column 7: document type does not allow element "table" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag
<table><tr>
But my document doesnt have a Line 65, the code is below
<!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>
<link rel="stylesheet" type="text/css" href="style_2.css"></link>
<title> Gadgets </title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
</head>
<body>
<div class="container">
<div class="background">
<div class="innerContainer">
<?php include("header.php"); ?>
<div class="content">
<div class="scroll">
<?php
error_reporting(0);
$con = mysql_connect("xxxxxxxx");
mysql_select_db("xxxx", $con);
$result = mysql_query("SELECT * FROM gadgets");
?>
<p>
<?php
echo "<table>";
echo "<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Manufacturer</th>
<th>Image</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" .$row['Name']."</td>";
echo "<td>" .$row['Description'] ."</td>";
echo "<td>" .$row['Price'] ."</td>";
echo "<td><img src='" .$row['ImageURL'] ."' style='width: 200px; height: 150px;' alt='Image' /></td>";
echo "</tr>";
}
echo "</table>";
?>
</p>
<?php
mysql_close($con);
?>
</div>
</div>
<?php include("footer.php"); ?>
</div>
</div>
</div>
</body>
</html>
Validators operate on HTML, not PHP (so compare line numbers to the generated HTML … also note the Show Source option of the W3C validation service).
Paragraphs cannot contain tables. Move the <table> outside the <p>

Categories