Jump to content

How to control if a field is blank


karq

Recommended Posts

So i'm new to php just started learning some weeks ago and now I'm making a guestbook with registratsion.

And I'm stuck I dont know how to too so that if the registratsion fields are blank then he cant register and it says "please fill the fields"?

I did something like this, but it dosent work:

$tyhi=$_POST["kasutaja"];$_POST["parool"];

if (empty($tyhi)

{

echo "Please fill the fields";

}

 

Link to comment
https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/
Share on other sites

didint work :S

my I have a problem somewhere else?

So all the code:

<html>

<body>

<center>

<?php

echo "<form action='rega.php' method='POST'>

<b>Kasutaja: </b><input type='text' name='kasutaja'/><br />

<b>Parool: </b> <input type='password'name='parool'/><br />

<input type='submit' value='Registreeru'/>";

if ($_POST["kasutaja"]!="" && $_POST["parool"]!="") {

include("dp.php");

$kasutaja=$_POST["kasutaja"];

$parool=$_POST["parool"];

//Kui väli on tyhi

$tyhi=$_POST["kasutaja"]||$_POST["parool"];

if (empty($tyhi)) {

echo "Täida väljad!";

 

}

else{

//Äkki on olemas

$olemas=mysql_query("SELECT * FROM kasutajad WHERE kasutaja='$kasutaja'");

while($q=mysql_fetch_array($olemas)){

$mysql_user=$q["kasutaja"];

}

if ($kasutaja==$mysql_user) {

echo "<br />Selline kasutaja on juba olemas!";

}

else{

//Kui ei ole siis

mysql_query("INSERT INTO kasutajad(ksutaja,parool) VALUES('$kasutaja','$parool');");

echo "<br />Oled Registreerunud";

echo "<br />Mine logi sisse <a href=logi.php>vajuta siia.";

}

}

}

?>

</center>

</body>

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.