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! Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/ 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. } ?> Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685649 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 } Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685660 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; Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685667 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; Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685697 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 Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685706 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. Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685725 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. Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685731 Share on other sites More sharing options...
jeff5656 Posted November 9, 2008 Author Share Posted November 9, 2008 Thank you that worked! Link to comment https://forums.phpfreaks.com/topic/131957-solved-compare-2-text-boxes/#findComment-685769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.