jeff5656 Posted November 8, 2008 Share Posted November 8, 2008 Can someone tell me how to compare content from a text box submitted from a form with the content from the database? the form will have $_POST['problist'] and the the database variable is problist. I want to query the databse and get "problist" and then compare it to $_POST['problist']. If they are different I want to update another field ("problist_date") with with today's date (to show the date of when that textbox was altered). Thank you! Quote Link to comment Share on other sites More sharing options...
peranha Posted November 8, 2008 Share Posted November 8, 2008 Just do <?php if ($_POST['problist'] == $problist) { // Put what you want done here is they are equal } else { // if they are not equal, put what you want done here. } ?> Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted November 8, 2008 Author Share Posted November 8, 2008 I have this. is this correct? I can't test it yet but I thinbk the query line is slightly wrong... $current_date = date ("m/d/y"); $query = "SELECT * FROM `icu` WHERE `patient` = '$_POST['patient']' "; $results = mysql_query ($query) or die (mysql_error()); if($problist != $_POST[problist]) { $problist_date = $current_date } Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 8, 2008 Share Posted November 8, 2008 here you go <?php $current_date = date ("m/d/y"); $query = "SELECT * FROM `icu` WHERE `patient` = '".$_POST['patient']."' "; $results = mysql_query ($query) or die (mysql_error()); if($problist != $_POST[problist]) { $problist_date = $current_date; }?> from '$_POST['patient']' to '".$_POST['patient']."' and $current_date to $current_date; Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted November 8, 2008 Author Share Posted November 8, 2008 Thanks. Now the problem is when I echo problist it is null, even though I know it contains text. Since I used * to select all the fields, why is it not returning the content? $current_date = date ("m/d/y"); $query = "SELECT * FROM `icu` WHERE `patient` = '".$_POST['patient']."' "; $results = mysql_query ($query) or die (mysql_error()); if($problist != $_POST[problist]) { $problist_date = $current_date; } echo $_POST['patient']; echo $_POST['problist']; echo "<p>"; echo "problist:"; echo $problist; echo "<br/>"; echo $problist_date; echo $current_date; Quote Link to comment Share on other sites More sharing options...
runnerjp Posted November 8, 2008 Share Posted November 8, 2008 not sure lol this dunt look right if($problist != $_POST[problist]) { $problist_date = $current_date; } and where you getting $_post from Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted November 8, 2008 Author Share Posted November 8, 2008 and where you getting $_post from from a form where the user can edit the fields from that record. If they edit a field, I want to put in tpday's date to show that the field was updated. also, echo $_POST['problist']; gives me the correct contents from that submitted form. Quote Link to comment Share on other sites More sharing options...
peranha Posted November 8, 2008 Share Posted November 8, 2008 You are not setting $problist anywhere that is why. // execute query $result = mysql_fetch_array(mysql_query($query)) or die(mysql_error()); //Set problist to a variable. $problist = $result['problist']; Try that and see what happens. Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted November 9, 2008 Author Share Posted November 9, 2008 Thank you that worked! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.