first_blood Posted August 29, 2008 Share Posted August 29, 2008 I am new to PHP so I need a lot of help with this. I have a form with 2 text boxes (loginid/password) On submitting the form (action = same PHP page) I check (if(isset($_POST("submit"))) and validate the fields from the records in a database. If its wrong, i need to display a error message, if not I direct the user to another page. This is my scenario. I have a problem displaying the error message. I have 2 <div> tags right next to the 2 text boxes showing the error message but its invisible on form load (style.display = 'none') Upon validation i need to make this div tags visible using (style.display = 'block'). How do i do that in PHP? Here is part of my code.. <? if(isset($_POST["submit"])) { require_once("config.php"); $userid = $_POST['userid']; $password = $_POST['password']; $query = "select * from login where userid = '$userid'"; $result = pg_query($connection, $query) or die("Error in query: $query." . pg_last_error($connection)); $rows = pg_num_rows($result); if($rows != 1) { echo "<div name=\"div1\" id=\"div1\" style=\"display:block\">Invalid Username!!!</div>"; } else { $row = pg_fetch_row($result); if($password == $row[1]) { $type = $row[2]; $company = $row[4]; echo "correct username and password"; } else { echo "Invalid"; } pg_free_result($result); } } ?> Instead of echoing the error message to the browser, i need to make the div tag style.display = 'block'/'none' according to conditions.... Is there a way to access the div tag's properties in PHP???? In javascript I would write something like this document.getElementById('div1').style.display = 'none'; Is there a corresponding code in PHP for this? Link to comment https://forums.phpfreaks.com/topic/121885-access-form-elements-properties-in-php/ Share on other sites More sharing options...
DarkWater Posted August 29, 2008 Share Posted August 29, 2008 Just do it in Javascript. PHP is server-side, not client-side. You'd need to make decisions in the code for which one to echo based on certain variables, rather than just changing a property in Javascript. It would be easier to code client-side. Link to comment https://forums.phpfreaks.com/topic/121885-access-form-elements-properties-in-php/#findComment-628889 Share on other sites More sharing options...
first_blood Posted August 29, 2008 Author Share Posted August 29, 2008 but i need to access the database so i need server-side scripting... I need JS only for that div style changing... if($rows != 1) { ?> <script> document.getElementById('div1').style.display = 'block'; </script> <? ....rest of th PH code Thats not working Link to comment https://forums.phpfreaks.com/topic/121885-access-form-elements-properties-in-php/#findComment-628892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.