The following id my php code

<html>
 <head>
  Checking !
 </head>
<body>
 <?php
  $errors_array=array();
  if(isset($_REQUEST["welcome_already_seen"])){
    check_data();
    if(count($error_array)!=0){
      show_error();
      show_welcum();
     }
    else{
     handle();
     }
}
else {
    show_welcum();
}
   function show_welcum(){
   echo "<form method='post'>";
   echo "What's your ice cream flavour?";
   echo "<br>";
   echo "<input name='flavor' type='text'>";
   echo "<br>";
   echo "<input type='submit' value='send'>";
   echo "<br>";
   echo "<input type='hidden' name='welcum'>";
   echo "</form>";
  }
 function check_data(){
  global $error_array;
  if($_REQUEST["flavour"]==""){
   echo "<font color='red'> Please enter a value </font>";
 }
}
function show_error(){
 global $error_array;
 foreach($error_array as $err){
 echo $err,"<br>";
}
}
function handle(){
echo "your favourite ice cream flavour is ";
echo $_REQUEST["flavour"];
?>
</body>
</html>

but when I run it on the browser , it shows a blank screen, why?

Dani AI

Generated

A blank page almost always means PHP hit a fatal/parse error that the server is hiding. Some fixes are already identified in the thread: caught the incorrect variable name and the $this usage, and spotted the missing brace. Add these checks next because they’re the usual culprits in the posted snippets: inconsistent variable names ($errors_array vs $error_array), mismatched form field spelling ('flavor' in the form but code checks 'flavour'), and the hidden field named 'welcum' while the code tests for 'welcome_already_seen'. Any one of those will stop execution.

Turn on full error reporting while developing so you see the real problem:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
?>

Also dump incoming data to confirm what the form is sending:

<?php
var_dump($_REQUEST); // or var_dump($_POST);
?>

Practical checklist to get this thread’s examples working

  • Make names consistent: if the form uses name="flavor" check $_POST['flavor'] (or change the form to match the code). Use $_POST instead of $_REQUEST for clarity.
  • Hidden flag: give it the same name and a value so isset() works, e.g. <input type='hidden' name='welcome_already_seen' value='1'>.
  • Errors array: declare and use the same variable ($error_array) and push messages with $error_array[] = 'Please enter a value';.
  • Braces and PHP tags: a missing } or stray ?> in the wrong place produces a parse error; count your braces or use an editor that highlights matching braces.
  • Classes/magic methods: use $this->prop (not this->), function __call($method, $arguments) (note the dollar signs), compare $method == 'set_msg' (string), and index $arguments[0]/[1].

If problems persist, check the webserver/php error log and use a syntax-aware editor (VS Code, PhpStorm, or similar). Leaving display_errors enabled on a public site is unsafe — use it only in development.

Recommended Answers

All 9 Replies

remove 's' from line 7
it should look like below

$error_array=array();

Also put a closing brace '}' on line no 47

commented: useful +5

Thanks that did work.can you please help me with this code, what is the possible error ,i f=get a blank screen in my browser .
<html>
<head>
Creating objects
</head>
<body>
<?php
class Objects{
var $name;
function set_name($na){
this->$name= $na;
}
function get_name(){
return this->$name;
}
}
$ob=new Objects;
$ob->set_name("ila");
echo "the name of greatest person alive is ",$ob->get_name();
?>
</body>
</html>

Make sure you write $this->name and NOT $this->$name.

<html>
<head>
Creating objects
</head>
<body>
<?php
class Objects
{
	var $name;

	function set_name($na)
	{
		$this->name= $na;
	}
	
	function get_name()
	{
		return $this->name;
	}
}

$ob=new Objects;
$ob->set_name("ila");
echo "the name of greatest person alive is ",$ob->get_name();

?>
</body>
</html>

Thanks a lot.

<html>
<head>
</h1>Overloading tym!</h1>
</head>
<body>
<?php
class demo{
var $name;
var $msg;
function set_msg($data, $m){
$this->name=$data;
$this->msg=$m;
}
function set_name($data){
$this->name=$data;
}
function speak(){
echo $this->name,"hi!",$this->msg,"...","<br>";
}
function __call($method,$argument){
if ($method==set_msg){
if(count(argument)==1){
$this->name=argument[0];
}
if(count(argument)==2){
$this->name=argument[0];
$this->msg=argument[1];
}
}
}
}
$d=new demo;
$d->set_msg("ila","hello");
echo $d->speak();
?>
</body>
</html>
Kindly tell error in this code.

if(count($argument)==1)
			{
				$this->name=$argument[0];
			}
			if(count($argument)==2)
			{
				$this->name=$argument[0];
				$this->msg=$argument[1];
			}

Here you have not written $ sign before argument. In my previous post I suggest about position of dollar sign. So Here this->name is different then argument, so both will start with dollar sign.

<html>
<head>
<h3> yups working with static property</h3>
</head>
<body>
<?php
class demo{
static $data;
static function demoagain($name){
self::$data=$name;
echo "so the value is", self::$data,"<br>";
self::$data++;
echo "the new value is", self::$data,"<br">;
}
}
demo::demoagain(13);
?>
</body>
</html>
please tell the error in this code.

Download php designer 2007 for free, its php editor that will help you to find syntax errors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.