E
E
Egor2016-02-13 20:24:39
PHP
Egor, 2016-02-13 20:24:39

Problem with PHP code. Can you help?

Hello! I just started learning PHP and I have a problem with the code: it doesn't run even though it's written exactly like the example. What to do?

<?
if (!isset($cardnumber))
   $m = "Введите номер карточки";
elseif ($cardnumber == "")
   $m = "Ваш номер пуст!";
else
   $m = "Ваш номер: $cardnumber";
?>
<html>
<head>
<title>Пример обработки ввода</title>
</head>
<body>
<h1><? echo $m?></h1>
<form action="<?echo $PHP_SELF?>" method="post">
      <p>Номер карточки:
      <input name="cardnumber" type="text" size="20">
</form>
</body>
</html>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zooks, 2016-02-13
Repiev @ega22a

$cardnumber = $_POST['cardnumber'];
And move the first block to <body>.

I
Ivanq, 2016-02-13
@Ivanq

There can be many problems.
1) Replace <? with <?php on the first line, and <?php echo $PHP_SELF ?>
2) Replace all $cardnumber with $_POST["cardnumber"] (post, like get, may not turn into a normal variable). "Ваш номер: $cardnumber"change to"Ваш номер: {$_POST['cardnumber']}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question