-
Posts
3,372 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Muddy_Funster
-
I used !== because it fit for the value that was requested for the check, the OP said 0 not 0.0 or 0.00000 or 000000.000000000000000 the issue being that PHP is a loose langauge, so 0 vlaues are parsed as false and false is parsed as empty. another way you could work it would be (assuming the normal kwywords are actualy words): <?php $keyword = (string)0.0; if(empty($keyword) && $keyword != '0'){ echo $keyword.' is empty!'; } echo $keyword; ?> or how about <?php $keyword = (string)0.0; if(empty($keyword) && $keyword != chr(48)){ echo $keyword.' is empty!'; } echo $keyword; ?>
-
I didn't write that line right, I missed off a closing ] so the code shouldn't even run at all, you should be getting a parse error (unless you fixed it)...it should be if (isset($post['searchID']) && $post['searchbyequipmenttype'] != '')
-
it is : this line here if (isset($post['searchID']) && $post['searchbyequipmenttype' != '') is checking the information returned passed in from the form and only running the query if the information is there to run it. Make sure and use the form to load the page, don't just refresh it.
-
ok, replace your searchByDocID.php code (all of it) with this: <?php include 'connect_db.php'; include 'newheader.php'; function sanitize_data($data) { $data = array_map('trim',$data); $data = array_map('strip_tags',$data); $data = array_map('htmlspecialchars',$data); $data = array_map('mysql_real_escape_string',$data); return $data; } $post = sanitize_data($_POST); if (isset($post['searchID']) && $post['searchbyequipmenttype' != '') { $id = $post['searchbyequipmenttype']; $sql = <<<SQL SELECT * FROM tc_tool.forms WHERE ( doc_id =$id ) SQL; $data = mysql_query($sql) or die(mysql_error()."<br>-----------<br>$sql"); while ($result = mysql_fetch_array( $data )) { echo $row ['doc_id'] . " <br /> " . $row ['doc_title'] . " <br /> " . $row ['doc_number'] . " <br /> " . $row ['doc_type'] . " <br /> " . $row ['revision'] . " <br /> " . $row ['cdm_link'] . " <br /> " . $row ['mars_link'] . " <br /> " . $row ['checklist_link'] . " <br /> " . $row ['link_internal_1_3']. " <br /> " . $row ['impacted_products']. " <br /> " . $row ['scope']. " <br /> " . $row ['impacted_products_2'] ." <br /> " . $row ['review_class']. " <br /> " . $row ['full_simplified'] . " <br /> " . $row ['pref_earliest'] . " <br /> " . $row ['pref_latest'] . " <br /> " . $row ['prev_reviews'] . " <br /> " . $row ['proj_name'] . " <br /> " . $row ['auth_name'] . " <br /> " . $row ['req_list'] . " <br /> " . $row ['optional_list'] . " <br /> " . $row ['information_only'] . " <br /> " . $row ['chairperson'] . " <br /> " . $row ['req_reviewers'] . " <br /> " . $row ['review_duration'] . " <br /> " . $row ['document_abstract'] . " <br /> "; } } else{ echo "there was a problem with the form, please try again and make sure you have filled in a document number"; } include "footer.php" ?>
-
OK, made some changes based on what you said, code is now : <?php //------------------------------------------------ class dbc { public $server; public $host; public $db; public $user; public $pass; public $hasError; public function set($var, $val=0){ try{ if(is_array($var)){ foreach ($var as $k => $v) { if(!$this->$k = $v){ throw new Exception('Error Setting Database Information :'); } } } else{ if(!$this->$var = $val){ throw new Exception('Error Setting Database Information :'); } } } catch(Exception $e){ $setError = array('1', 'set', $e->getMessage()); $error = new errorCatch; $error->ErrorHandle($setError); $this->hasError = "caught the error"; } } } //------------------------------------------------ class errorCatch{ public $severity; public $methodCall; public $message; public function ErrorHandle($error){ $this->severity = $error['0']; $this->methodCalled = $error['1']; $this->message = $error['2']; if ($this->severity == 1){ die ("Critical error in call to dbo->$methodCall: $message"); } die("Warning Call to $methodCall resulted in a non fatal error: $message"); } } //------------------------------------------------ //$error = new errorCatch; $con = new dbc; $set = array('hst'=>'localhost', 'svr'=>'mysql'); $con -> set($set); var_dump($con); ?> which interestingly gave this as an output : object(dbc)#1 ( { ["server"]=> NULL ["host"]=> NULL ["db"]=> NULL ["user"]=> NULL ["pass"]=> NULL ["hasError"]=> NULL ["hst"]=> string(9) "localhost" ["svr"]=> string(5) "mysql" } It's appending new variables into the class without them being pre defined so it's effectivly not generating an error. I guess need a better check (ie. one that works), any suggestions?
-
ok on searchByDocID.php you need to change this line back : $id = $_POST['searchID']; to read $id = $_POST['searchbyequipmenttype']; and as long as the field in the form is filled in you should get a result.
-
Ok, I'm trying to play with custom error handeling, and not getting anywhere. I have some code I made up just to mess about and get a feel for this, but no matter what I try I get nothing thrown out and no error caught. I did have it all in the one class, but got strongly advised that was a bad bad bad thing to do, so in an effort to keep the focus on the actual problem I've moved it off into it's own class. Here's the code, it's self contained (as I said its only a play around) but I would really appreciate it if someone could explain why the errors arn't being caught: <?php //------------------------------------------------ class dbc { public $server; public $host; public $db; public $user; public $pass; public function set($var, $val=0){ try{ if(is_array($var)){ foreach ($var as $k => $v) { if(!$this->$k = $v){ throw new Exception('Error Setting Database Information :'); } } } else{ if(!$this->$var = $val){ throw new Exception('Error Setting Database Information :'); } } } catch(Exception $e){ $setError = array('1', 'set', $e->getMessage()); $error->ErrorHandle($setError); } } } //------------------------------------------------ class errorCatch{ public $severity; public $methodCall; public $message; public function ErrorHandle($error){ $this->severity = $error['0']; $this->methodCalled = $error['1']; $this->message = $error['2']; if ($this->severity == 1){ die ("Critical error in call to dbo->$methodCall: $message"); } die("Warning Call to $methodCall resulted in a non fatal error: $message"); } } //------------------------------------------------ $error = new errorCatch; $con = new dbc; $set = array('hst'=>'localhost', 'svr'=>'mysql'); $con -> set($set); var_dump($error); ?>
-
and so does the code I posted....
-
OK, post up the full code for both pages as it is now so we're both working from the same page
-
take out the line we added at the top : die(print_r($_POST));
-
if (empty($keyword) && $keyword !== 0 ) {
-
I'm sorry....what?
-
nothing like jumping in at the deep end. How much PHP knowledge do you have? do you know about sessions and headers?
-
need to change these lines: $result = mysql_query($sql) or die(mysql_error())."<br>----------------<br>$sql"; while ($result = mysql_fetch_array( $data )) to $data = mysql_query($sql) or die(mysql_error())."<br>----------------<br>$sql"; while ($result = mysql_fetch_array( $data ))
-
I've never used a preloader, but I don't see any reason it wouldn't work, all you really need to do is for your if(xmlhttp.readyState == 4){...} attach an elseif directly after the closing } of the if to show your loading gif on the div while it's in a loading state, or whatever other state you want coverd.
-
Problem in Insert with On Duplicate Key Update
Muddy_Funster replied to newphpcoder's topic in MySQL Help
describe your table please? -
It's highly irregular to actualy delete information from a database that relates to any commercial process. Especialy after only 1 month. Common practice is to archive it after either a year or a quarter, depending on the environment. Your sure you want to delete?
-
you would need to do an array count, set up a counter, split off the array in groups of 12, updating the counter, and then display by itterating through each group simultaneously (using the same counter value from a second counter to reffernce the number of columns set by the first counter) to generate the row. Also you will need a check to make sure you stop trying to access each group of 12 when it is empty or you will get undefined offeset errors. I'm in a bit of a rush, so that may not make as much sense as I would like it, but hope it gets you on the right track
-
I know this sounds crazy, but you are filling in a value before you click the button to submit the form? right?
-
ok, assuming this to be your searchByDocID.php : <?php include 'connect_db.php'; include 'newheader.php'; function sanitize_data($data) { $data = array_map('trim',$data); $data = array_map('strip_tags',$data); $data = array_map('htmlspecialchars',$data); $data = array_map('mysql_real_escape_string',$data); return $data; } $post = sanitize_data($_POST); if (isset($_POST['searchID'])) //... if it is I would like you to add a line at the top of the page: <?php die(print_r($_POST)); Let me know what you get on the page from that.
-
problem is getting the information from the form to the script. Your form element name that we want to look at is "searchbyequipmenttype" so we use the line $id = $_POST['searchbyequipmenttype']; to get it from the POST array, only problem is, it's not got anything in it. So we need to now look at the form. where is your form? on the same page or on a different one and do you have any other code that the form uses that you didn't post??
-
you need to address the form element by it's name in the $_POST array - so try this as a test: $id = $_POST['searchbyequipmenttype']; $sql = <<<SQL SELECT * FROM tc_tool.forms WHERE ( doc_id =$id ) SQL; $result = mysql_query($sql) or die(mysql_error()."<br>-----------<br>$sql); $row = mysql_fetch_assoc($result); var_dump($row);
-
my bad on the code I gave you, I closed the or die() brackets too soon - change to this and let's see what comes back $result = mysql_query($sql) or die(mysql_error()."<br>----------------<br>$sql");
-
I think your would be best using a ROLLUP for this kind of thing