karq Posted September 23, 2007 Share Posted September 23, 2007 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 More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 if nothing else, you're missing a paren: if (empty($tyhi) should be if (empty($tyhi)) Link to comment https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/#findComment-353493 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 try <?php if (empty($_POST[variable]||$_POST[variable2])) { echo "please enter something in the form fields"; } ?> Link to comment https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/#findComment-353494 Share on other sites More sharing options...
karq Posted September 23, 2007 Author Share Posted September 23, 2007 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> Link to comment https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/#findComment-353507 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 use my exact code dont change it up! it will check if the form variables are empty if they are it errors Link to comment https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/#findComment-353512 Share on other sites More sharing options...
karq Posted September 23, 2007 Author Share Posted September 23, 2007 you code dosent work I tried it, it gave this error Parse error: syntax error, unexpected T_BOOLEAN_OR, expecting ')' in...... on line 14 Link to comment https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/#findComment-353518 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 then try removing the extra parens i put in jeesh. if ($_POST[variable]||$_POST[variable2]) { include(db.php); } Link to comment https://forums.phpfreaks.com/topic/70366-how-to-control-if-a-field-is-blank/#findComment-353522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.