PHP - Trying To Get Property Of Non-object In Error
Hi Guys
Trying to get xml elements to display in a html table using the following code Code: [Select] <?php session_start(); include_once('includes/connect_inc.php'); $file="https://www.cdlvis.com/lookup/getxml?username=username&mode=test&key=password&vrm=".$_POST['veh_reg'].""; $dom=new DOMdocument(); $dom->load($file); $xml=simplexml_import_dom($dom); ?> and Code: [Select] <form name="vehicle_details" method="post" action="add_vehicle.php"> <table> <tr> <td>Registration Number:</td><td><input name="reg_num" type="text" value="<?php echo $xml->result[0]->vrm;?>" readonly="true" /></td></tr> <tr> <td>Make:</td><td><input name="make" type="text" value="<?php echo $xml->result[0]->make;?>" readonly="true" /></td></tr> <tr> <td>Model:</td><td><input name="model" type="text" value="<?php echo $xml->result[0]->model;?>" readonly="true" /></td></tr> <tr> <td>Date of Manufactu </td><td><input name="date_man" type="text" value="<?php echo $xml->result[0]->date_manufactured;?>" readonly="true" /></td></tr> <tr> <td>Date of First Registration:</td><td><input name="date_reg" type="text" value="<?php echo $xml->result[0]->first_registered;?>" readonly="true" /></td></tr> <tr> <td>Colour:</td><td><input name="colour" type="text" value="<?php echo $xml->result[0]->colour;?>" readonly="true" /></td></tr> <tr> <td>Body Style:</td><td><input name="body" type="text" value="<?php echo $xml->result[0]->body;?>" readonly="true" /></td></tr> <tr> <td>Number of Doors:</td><td><input name="doors" type="text" value="<?php echo $xml->result[0]->doors;?>" readonly="true" /></td></tr> <tr> <td>Engine Size:</td><td><input name="engine_size" type="text" value="<?php echo $xml->result[0]->engine_size;?>" readonly="true" /></td></tr> <tr> <td>Fuel Type:</td><td><input name="fuel_type" type="text" value="<?php echo $xml->result[0]->fuel;?>" readonly="true" /></td></tr> <tr> <td>Gearbox Type:</td><td><input name="gearbox" type="text" value="<?php echo $xml->result[0]->gearbox_type;?>" readonly="true" /></td></tr> <tr> <td>Previous Keepers:</td><td><input name="keepers" type="text" value="<?php echo $xml->result[0]->previous_keepers;?>" readonly="true" /></td></tr> <tr> <td>BHP:</td><td><input name="bhp" type="text" value="<?php echo $xml->result[0]->smmt_power_bhp;?>" readonly="true" /></td></tr> <tr> <td>Emissions:</td><td><input name="co2" type="text" value="<?php echo $xml->result[0]->smmt_co2;?>" readonly="true" /></td></tr> <tr> <td><input name="try_again" type="button" value="Try Again" /></td><td><input name="submit" type="submit" value="Next Stage" /></td></tr> </table> </form> What have I done wrong? Similar TutorialsKeep getting this error from line 19 (Notice: Trying to get property of non-object in /clientdata/zeus-dynamic-1/s/o/blahblah/www/tyson/onion.php on line 18)... have no idea how to get rid of it. Do I have to use isset? If so.. where??? (obviously I've replaced site address with website) Code: [Select] include('simple_html_dom.php'); $story = array(); getArticles('website'); function getArticles($page) { global $story, $desc, $read; $html = new simple_html_dom(); $html->load_file($page); $items = $html->find('div[id=story_content]'); foreach($items as $post) { $story[] = array($post->children(0)->plaintext, $post->children(2)->next_sibling()->innertext, $post->children(4)->innertext); } } $i = 0; foreach($story as $item) { $syurl = str_replace('href="', 'href="http://website', $item[2]); echo '<p class="storytitle">' . $item[0] . '</p>'; echo '<p class="storyexcerpt">' . $item[1] . '</p>'; echo '<p class="storyread">' . $syurl . '</p>'; if (++$i == 3) break; } Any ideas? This line is causing the issue: $story[] = array($post->children(0)->plaintext, $post->children(2)->next_sibling()->innertext, $post->children(4)->innertext); Likewise, it does post the 3 storys below the 2 error lines...? Hey all, I want to have an object that has a property which is an object containing instances of other objects. I try this: Code: [Select] class Blog extends Posts { public $has_posts; public function __construct($a,$b,$c){ $has_posts = (object) array_merge((array) $a, (array) $b, (array) $c); } } class Posts { public $b; public function __construct($b){ $this->b = $b; } } $post1 = new Posts(1); $post2 = new Posts(2); $post3 = new Posts(3); $blog = new Blog($post1,$post2,$post3); var_dump($blog->has_posts); //null foreach($blog->has_posts as $post){ //Invalid argument supplied for foreach() echo $post->b; } But as you see, has_posts is null, not an object containing other objects. Thanks for response. Hi all, I have a script which I coded not long ago which works fine but there is one error which says: Notice: Trying to get property of non-object in /home/www/***-*****.com/hts.php on line 374 I carnt see why its showing the error. $fetch2=mysql_query("SELECT crew FROM users WHERE username='$username'") or die (mysql_error()); $fetch1 = mysql_fetch_object($fetch2); $crewrep1=mysql_query("SELECT * FROM crews WHERE name='$fetch1->crew'") or die (mysql_error()); $crewrep = mysql_fetch_object($crewrep1); $result = $rep + $reps; $result55 = $crewrep->rep + $reps; // Line 374 Can anyone else see why its showing the error? Thanks for your help. I've been getting this error message: Trying to get property of non-object in /application/controllers/index.php on line 37 Here is line 37 $this->view->title = $pageInfo[0]->title; any help would be much appreciated. We have a complex, json object which is multiple levels deep. We need to search for a given property/key in the entire object (not just first occurrence, but all), and if we find the property, return where in the object each property exists, so we can modify the properties value. Figure it needs to be recursive. I am trying to run a count query and faced with the error: Notice: Trying to get property of non-object in Not sure how to resolve this error in these lines:
if($result->num_rows > 0){ while($row = $result->fetch_rows()){ Code: <?php $sql = "SELECT Form_Group COUNT(Presence LIKE '/') AS Present, COUNT(Presence LIKE 'N') AS Absent, FROM 'attendance'"; $result = $conn->query($sql); ?> <?php //Fetch Data form database if($result->num_rows > 0){ while($row = $result->fetch_rows()){ ?> <tr> <td><?php echo $row['Form_Group']; ?></td> <td><?php echo $row['Present']; ?></td> <td><?php echo $row['Absent']; ?></td> </tr> <?php } } else { ?> <tr> <th colspan="6">There's No data found!!!</th> </tr> <?php } ?>
Hello, I'm currently in the process of trying to learn php. I've been working on an issue with something I am trying to code from a book I purchased "PHP and MySQL Web Development 5th Ed." by Luke Welling and Laura Thomson. So far the book has been great, but I'm trying to figure out using MySQL and php. When I try to run this particular script for a query for a book store, I get the error: Notice: Trying to get property of non-object in C:\php-book\ch11\results.php on line 37. This is the code: Code: [Select] $query = "select * from books where ".$searchtype."like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of books found: ".$num_results."</p>"; for($i=0; $i<$num_results; $i++) { $row = $result->fetch_assoc(); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br />Author: "; echo stripslashes($row['author']); echo "<br /> ISBN: "; echo stripslashes($row['isbn']); echo "<br />Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); Line 37 is specifically: $num_results = $result->num_rows; I've been bashing my head for a couple of hours here, thank you in advance to whoever can offer any help. I want to save class property values and want to write these in the database after being called from another function. Code: [Select] class model{ public $dbh; public $user_arr=array('username','password','email','location','interest','homepage'); public function insert_data() { $sql = "INSERT INTO account VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"; //if(isset($data)) echo $sql; } public function data_approoved($user){ //$user_info = new array(); $user_arr['username'] = $user['username']; $user_arr['password'] = $user['password']; $user_arr['email'] = $user['email']; $user_arr['location'] = $user['location']; $user_info['interests'] = $user['interests']; $user_info['homepage'] = $user['homepage']; Model::insert_data(); } } }//class ended The approoved_data function is supposed to set the values of $user_info array which should be later on stored in database. Please somebody help me. So I'm getting a "Notice: Trying to get property of non-object in" error when I'm trying to pull data from a xml. I have a complete xml that has all of the potential node that it could ever have and it loads up fine -no errors, but when I load a different xml that doesn't have all of the possible nodes it returns this error several times here is a sample of my code: $source = 'TestFile.xml'; $xml = new SimpleXMLElement($source,null,true); $result = mysql_query("SELECT * FROM tblvalues") or die(mysql_error()); //Return the table row by row while($row = mysql_fetch_array($result)) { $curblk = substr($row['fldelement'],0,3); switch ($row['fldelement']){ case "E06_04": case "E06_05": case "E06_07": case "E06_08": $cursub = $curblk."_04_0"; $xmlVal = $xml->Header->Record->$curblk->$cursub->$row['fldelement']; //grab value from xml break; ... ... ... // the cases go on for a while... ... case "E07_05": case "E07_06": case "E07_07": case "E07_08": $cursub = $curblk."_03_0"; $cursub2 = $curblk."_05_0"; $xmlVal = $xml->Header->Record->$curblk->$cursub->$cursub2->$row['fldelement']; //this is the line that the error points to break; ... ... ... And here is the sample of the xml that returns the error: Code: [Select] <E07> <E07_01>-20</E07_01> <E07_02>0</E07_02> <E07_15>-25</E07_15> <E07_16>-25</E07_16> <E07_17>-25</E07_17> <E07_18_0> <E07_18_01> <E07_18>-20</E07_18> <E07_19>-20</E07_19> <E07_20>-20</E07_20> </E07_18_01> .... .... .... The obvious problem (to me) is that my code is trying to return a value from a nonexistent xml node, for example: $xmlVal = $xml->Header->Record->$curblk->$cursub->$cursub2->$row['fldelement']; is looking for: $xmlVal = $xml->Header->Record->E07->E07_03_0->E07_05_0->E07_05 Ok, I get that, so how do I rewrite this so it's not blowing up on something so simple? Quick notes: -This same code works for a more complete xml -Rewriting the xmls is not an option as I have no control over those Edit: Almost forgot, thanks! *Mods* PLEASE don't move this to the OOP section again. I've had no luck there, and it's not specifically an OOP question. Hi everyone, I just want to know if there's a shorthand way to create objects, as there is for arrays: Code: [Select] // shorthand array creation $foo = array( 'bar' => 0, 'baz' => array ( 'name' => 'Dave', 'gender' => 'male' ) ) Code: [Select] // is there a way to do this with objects? // not that I know so far... $foo = object( bar->0, 'baz' -> object ( name -> 'Dave', gender -> 'male' ) ) I find object-access syntax is often quicker and easier to write than array-access syntax. Have I missed something obvious that I can't just write it out this way? Cheers, Dave I have a Soup object in a Bowl object in a Microwave object. The Microwave object has the methods: receiveItem(Bowl $b) cookItem(???) I want the Microwave to be able to set the Soup->temperature but I'm not how to do that? Make sense? TomTees This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=323395.0 I get the following error when I try to pass a value to a methiod in a loop: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 This one has me very baffled. It will work the first time, and seems to work every other time, so I have no clue what is wrong. Here is the code: This code is part of my "display" class: function display_partner ($type,$loc,$rand=0,$narrow=0) { $this->partners = new partner($this->cxn); $display = ' <div id="cont_info" class="partner-list"> <div> <h3 class="settings">'.ucfirst($loc).' '.ucfirst($type).last_letter($type).'s</h3> </div> <div class="settings-value" style="height:12px;padding:0;margin:0;text-align:right;padding-right:10px;"> <a href="" class="trunc">Add your organization to this list</a></p> </div> <div style="height:2px;padding:0;margin:0;"> <hr class="account" /> </div> '; $ids = $this->partners->get_partners_list($type,$loc,$rand); for ($b=0;$b<sizeof($ids->id);$b++) { $this->partnerID = $ids->id[$b]; $display .= ($narrow)? $this->card_partner_narr():$this->card_partner(); if ($b!=(sizeof($ids->id)-1)) { $display .= '<hr class="account" />'; } } if (sizeof($ids->id)==0) { $display .= '<div style="color:#999999;display:line;text-align:center;height:20px;">No Partners found for '.ucfirst($loc).' '.ucfirst($type).'</div>'; } $display .= ' </div>'; return $display; } function card_partner () { $this->partners->set_partner_id($this->partnerID); $part_info = $this->partners->get_partner_info(); if ($part_info) { $display .= ' <table class="settings"> <tr> '.$this->show_if($part_info['partLogo']['val'],'<td class="settings-value" rowspan="2"><img src="'.LOGO_FOLDER.$part_info['partLogo']['val'].'" '.resize_img(LOGO_FOLDER.$part_info['partLogo']['val'],175).'alt="'.$part_info['partName']['val'].'" /></td>').' <td class="settings-value" colspan="2"><h5>'.$part_info['partName']['val'].'</h5></td> </tr> <tr> <td class="settings-value"> <span style="color:999999;">'.$part_info['partAddress']['val'].'<br /> '.$part_info['partCity']['val'].', '.$part_info['partST']['val'].' '.$part_info['partZIP']['val'].'<br /> '.$part_info['partPhone']['val'].'</span><br /> <a href="'.$this->form->show_href($part_info['partWeb']['val']).'" target="_blank">'.$part_info['partWeb']['val'].'</a> </td> <td class="settings-value">'.$part_info['partInfo']['val'].'</td> </tr> </table> '; } return $display; } This code is part of my "partners" class: function set_partner_id($partID) { echo '<p>partID: '.$partID.' '.gettype($partID).'<br> $this->partner->id: '.$this->partner->id.'</p>'; $this->partner->id = $partID; ///*** ERROR HAPPENS HERE ***/ echo '<p>id set: '.$this->partner->id.'<br> $this->partner->id: '.$this->partner->id.'</p><hr>'; } function get_partner_id() { return $this->partner->id; } // gets user info at login function get_partner_info() { $this->partner = $this->cxn->proc_info('partner','partID',$this->partner->id);//$this->partner->id return $this->partner; } The following is the output generated: partID: 24 string $this->partner->id: id set: 24 $this->partner->id: 24 partID: 26 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: partID: 17 string $this->partner->id: id set: 17 $this->partner->id: 17 partID: 25 string $this->partner->id: Warning: Attempt to assign property of non-object in /Users/staceyschaller/Sites/dev_zone/ckwv2/classes/class.php on line 670 id set: $this->partner->id: As you can see, the value passes to $this->set_partner_id($partID) each time. It is formatted as a string. When it assigns the value to $this->partner->id, however, sometimes it works, and sometimes it doesn't. It's probably something obvious, but I've racked my brain to see what it is. Any ideas? Hello , I have a made a PHP website where users signup and send their Date of Birth and gets an OTP on their email after signup. The OTP is recieved but when we enter the OTP this problem occurs QuoteError! Something went wrong and I am facing this error in the error log QuotePHP Fatal error: Uncaught Error: Object of class DateTime could not be converted to string This is my config.php code <?php session_start(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Confirmation Page - Kanha Stories</title> <style> body { background-color: #330000; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 800 400'%3E%3Cdefs%3E%3CradialGradient id='a' cx='396' cy='281' r='514' gradientUnits='userSpaceOnUse'%3E%3Cstop offset='0' stop-color='%23D18'/%3E%3Cstop offset='1' stop-color='%23330000'/%3E%3C/radialGradient%3E%3ClinearGradient id='b' gradientUnits='userSpaceOnUse' x1='400' y1='148' x2='400' y2='333'%3E%3Cstop offset='0' stop-color='%23FA3' stop-opacity='0'/%3E%3Cstop offset='1' stop-color='%23FA3' stop-opacity='0.5'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect fill='url(%23a)' width='800' height='400'/%3E%3Cg fill-opacity='0.4'%3E%3Ccircle fill='url(%23b)' cx='267.5' cy='61' r='300'/%3E%3Ccircle fill='url(%23b)' cx='532.5' cy='61' r='300'/%3E%3Ccircle fill='url(%23b)' cx='400' cy='30' r='300'/%3E%3C/g%3E%3C/svg%3E"); background-attachment: fixed; background-size: cover; padding: 20px; width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; color:#ffffff; overflow-x: hidden; } .cont { padding: 20px 40px; position: relative; border-right: 4px solid rgb(184, 182, 182); border-bottom: 4px solid rgb(184, 182, 182); border-radius: 15px; display: flex; flex-direction: column; align-items: center; } #left{ float: left; } #right{ float: right; } input{ margin: 10px 0px; } s{ padding: 5px; } .error{ padding: 5px; color: #ffffff; } .resend{ color: rgb(14, 14, 196); padding: 5px; } .s:hover{ cursor: pointer; background-color:gray; color: rgb(243, 237, 237); border-radius: 5px; } </style> </head> <body> <?php $code=""; $err=""; $error=""; if(($_SERVER["REQUEST_METHOD"]=="GET" && $_SESSION['xyz'] === 'xyz') || isset($_POST['verify']) || isset($_POST['resend'])) { unset($_SESSION["xyz"]); if($_SERVER["REQUEST_METHOD"] ==="POST") { if(isset($_POST['verify'])) { if(empty($_POST['code'])) { $err="Enter the code!"; } else { $code=$_POST['code']; if(password_verify($code,$_SESSION['code'])) { $name=$_SESSION['name']; $email=$_SESSION['email']; $tel=$_SESSION['tel']; $dob=$_SESSION['dob']; $password=$_SESSION['password']; $age_category=$_SESSION['age_category']; require_once('./all_utils/connection.php'); $sql="INSERT INTO identity_table(name,email,password,tel,dob,age_category) VALUES ('$name','$email','".$password."','$tel','$dob','$age_category')"; if(mysqli_query($conn,$sql) === TRUE) { unset($_SESSION["name"]); unset($_SESSION["password"]); unset($_SESSION["dob"]); unset($_SESSION["tel"]); unset($_SESSION["age_category"]); header("location:welcome/welcome.php"); } else { $err="Error! Something went wrong"; } } else { $err="Incorrect code!"; } } } elseif(isset($_POST['resend'])) { require_once('./all_utils/mail.php'); $error="OTP has been sent again!"; } } } else{ header("location:signup.php"); } ?> <div class="cont"> <h2> Email Verification</h2> <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST"> <label for="verification">Enter the 5 digit code</label> <br/> <p> Didn't got the mail? Please check your spam folder </p> <input type="text" name="code" placeholder="Eg. 12345" value="<?php echo $code; ?>"> <br/> <div class="error"><?php echo $err; ?></div> <div class="resend"><?php echo $error;?></div> <input type="submit" name="resend" class="s" id="left" value="Resend OTP"> <input type="submit" name="verify" class="s" id="right" value="Verify"> </form> </div> </body> </html>
This is my signup.php code <?php session_start(); if(!empty($_SESSION['email'])) { require_once('./all_utils/connection.php'); $query="SELECT * FROM identity_table WHERE email='".$_SESSION['email']."'"; $result=mysqli_query($conn,$query); if(mysqli_fetch_assoc($result)) { header("location:welcome/welcome.php"); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>SignUp - Kanha Stories</title> <style> * { margin: 0; padding: 0; } body { width: 100vw; height: 100vh; display: flex; align-items: center; background-color: #ff9d00; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100%25' height='100%25' viewBox='0 0 1600 800'%3E%3Cg stroke='%23000' stroke-width='66.7' stroke-opacity='0' %3E%3Ccircle fill='%23ff9d00' cx='0' cy='0' r='1800'/%3E%3Ccircle fill='%23f27d00' cx='0' cy='0' r='1700'/%3E%3Ccircle fill='%23e55f00' cx='0' cy='0' r='1600'/%3E%3Ccircle fill='%23d84400' cx='0' cy='0' r='1500'/%3E%3Ccircle fill='%23cb2c00' cx='0' cy='0' r='1400'/%3E%3Ccircle fill='%23bf1600' cx='0' cy='0' r='1300'/%3E%3Ccircle fill='%23b20300' cx='0' cy='0' r='1200'/%3E%3Ccircle fill='%23a5000e' cx='0' cy='0' r='1100'/%3E%3Ccircle fill='%2398001c' cx='0' cy='0' r='1000'/%3E%3Ccircle fill='%238b0027' cx='0' cy='0' r='900'/%3E%3Ccircle fill='%237e0030' cx='0' cy='0' r='800'/%3E%3Ccircle fill='%23710037' cx='0' cy='0' r='700'/%3E%3Ccircle fill='%2364003b' cx='0' cy='0' r='600'/%3E%3Ccircle fill='%2358003c' cx='0' cy='0' r='500'/%3E%3Ccircle fill='%234b003a' cx='0' cy='0' r='400'/%3E%3Ccircle fill='%233e0037' cx='0' cy='0' r='300'/%3E%3Ccircle fill='%23310030' cx='0' cy='0' r='200'/%3E%3Ccircle fill='%23210024' cx='0' cy='0' r='100'/%3E%3C/g%3E%3C/svg%3E"); background-attachment: fixed; background-size: cover; overflow-x: hidden; } .cont { color: #ffffff; width: 500px; margin: auto; } h2 { color: #ffffff; text-align: center; padding: 1.5px; } .error { text-align: center; padding: 20px; font-size: 1rem; color: rgb(233, 76, 76); } form { font-size: 1.2rem; /* width: 40%; */ /* margin: auto; */ } .in{ margin: 5px 0; } input { border: 2px solid white; padding: 10px; margin: 5px 0; font-size: 1rem; width: 100%; } input:hover { border: 2px solid rgb(228, 81, 81); cursor: text; } p,a{ text-align: center; font-size: 1rem; } a{ color: deepskyblue; font-size:20px; } #s{ text-decoration:none; border-radius: 12px; } #s:hover { cursor: pointer; } a { text-decoration: none; } @media only screen and (max-width: 600px){ .cont{ width: 300px; } .error,input{ font-size: 0.8rem; } } @media only screen and (max-width: 400px){ .cont{ width: 70%; } h2{ font-size: 1.3rem; } a,p{ font-size: 0.7rem; } label{ font-size: 1.0rem; } input{ padding: 4px; } } </style> </head> <body> <?php $name=""; $email=""; $tel=""; $dob=""; $err=""; $name_err=""; $email_err=""; $tel_err=""; $dob_err=""; $password_err=""; if($_SERVER["REQUEST_METHOD"]=="POST") { if(isset($_POST['signup'])) { if(empty($_POST['name']) || empty($_POST['dob']) || empty($_POST['tel']) || empty($_POST['email']) || empty($_POST['password'])) { if(empty($_POST['name'])) { $name_err="Name is required!"; } else{ $name=$_POST['name']; } if(empty($_POST['email'])) { $email_err="Email is required!"; } else{ $email=$_POST['email']; } if(empty($_POST['tel'])) { $tel_err="Contact Number is required!"; } else{ $tel=$_POST['tel']; } if(empty($_POST['dob'])) { $dob_err="D.O.B is required!"; } else{ $dob=$_POST['dob']; } if(empty($_POST['password'])) { $password_err="Password is required!"; } } else { $today = new DateTime(date('m.d.y')); $dob = new DateTime($_POST['dob']); $diff1 = $today->diff($dob); $age = $diff1->y; if($age > 15 || $age <3) { $dob = $_POST['dob']; $dob_err = "Age criteria not satisfied , child's age must be between 3-15 years"; } else { require_once("./all_utils/connection.php"); $email=$_POST['email']; $query="SELECT * FROM identity_table WHERE email='".$email."'"; $result=mysqli_query($conn,$query); if(mysqli_fetch_assoc($result)) { $err="Email alredy registered!"; $name=$_POST['name']; $email=$_POST['email']; } else { if($age < 7) { $_SESSION['age_category'] = '1'; } else { $_SESSION['age_category'] = '2'; } $_SESSION['name']=$_POST['name']; $_SESSION['email']=$_POST['email']; $_SESSION['password'] = password_hash($_POST['password'],PASSWORD_DEFAULT); $_SESSION['tel']=$_POST['tel']; $_SESSION['dob']=$_POST['dob']; $_SESSION['xyz']='xyz'; require_once("all_utils/mail.php"); header("location:conf.php"); } } } } } ?> <div class="cont"> <h2>SignUp - Kanha Stories</h2> <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'])?>" method="POST"> <span class="error"><?php echo $err; ?></span> <br/> <label for="name">Name</label><br /> <input type="text" name="name" placeholder="Enter your name" value="<?php echo $name; ?>"> <span class="error"><?php echo $name_err; ?></span> <br/> <label for="email">Email</label><br /> <input type="email" name="email" placeholder="Enter your Email ID" value="<?php echo $email; ?>"> <span class="error"><?php echo $email_err;?></span> <br/> <label for="tel">Mobile Number</label><br /> <input type="tel" name="tel" placeholder="Enter Mobile Number" value="<?php echo $tel; ?>"> <span class="error"><?php echo $tel_err;?></span> <br/> <label for="date">D.O.B. of Child (Click on Calander icon)</label><br /> <input type="date" name="dob" placeholder="Enter date of birth " value="<?php echo $dob;?>"> <span class="error"><?php echo $dob_err;?></span> <br/> <label for="password">Password</label><br /> <input type="password" name="password" placeholder="Enter your Password"> <span class="error"><?php echo $password_err; ?></span> <br/> <div class="sub"> <input type="submit" name="signup" id="s" placeholder="Submit"><br /> </div> </form> <p>Already registered? <a href="./login.php">log in here</a></p> </div> </body> </html>
I don't know what I can do now , Please try to give me the solutions as soon as possible. Thanks New to classes, basic understanding of procedural. I am trying to echo rows from the data base using PDO. Here is the code: Code: [Select] <div id="admin"> <form method="POST" action="categoryAdmin.php"> <table> <tr><th bgcolor="#EEEEEE">Cat Id</th> <th bgcolor="#EEEEEE">Title</th> <th bgcolor="#EEEEEE">Description</th> </tr> <?php global $dbh; $sql = "SELECT * FROM categories"; $sth = $dbh->prepare($sql); $sth-> execute(); print_r($sth); $result = $sth->fetchAll(PDO::FETCH_ASSOC); print_r($result); while($row = $result->fetchAll(PDO::FETCH_ASSOC)) {echo "<tr><td>$row[0]<td><td>$row[1]<td><td>$row[2]<td><tr>\n";} ?> <tr><td><input type="text" name="CatId" size="15" maxlength="10"></td> <td><input type="text" name="CatTitle" size="40" maxlength="130"></td> <td><input type="text" name="CatDesc" size="45" maxlength="200"></td> </tr> </table> <input type="hidden" name="addRecord" value="1"> <input type="submit" name="submit" value="Add Category"> </div> print_r($sth); shows: PDOStatement Object ( [queryString] => SELECT * FROM categories ) print_r($result); shows: Array ( => Array ( [categoryId] => Fitness [title] => Sholder Guy [description] => Fix that sholder and more ) ) fatal error: Call to a member function fetchAll() on a non-object in /home/... the line in question is the while loop. I am not sure what to pass it with reguards to PDO. Thanks - AL I'm trying to build a Wordpress plugin where all the archives are nicely listed in a tabular form. I'm reading the book Wordpress Plugin Development - A Beginner's Guide And I'm having an error when trying to call the function to display the archives on a separate page. Here's the function: function display() { global $wpdb; // these variables store the current year, month and date // processed $curyear=''; $curmonth=''; $curday=''; // the beginning of our output $result=' <div class="snazzy"> <table cellspacing="15" cellpadding="0" border="0"> <tbody> <tr>'; // query to get all published posts $query= "SELECT * FROM $wpdb->posts WHERE post_status = 'publish' AND post_password='' ORDER BY post_date_gmt DESC "; $posts = $wpdb->get_results($query); foreach ($posts as $post) { // retrieve post information we need $title = $post->post_title; $excerpt= $this->get_excerpt($post->post_content); $url=get_permalink($post->ID); $date = strtotime($post->post_date); // format the date $day = date('d', $date); $month = date('M', $date); $year = date('Y', $date); // look for image in the post content $imageurl=""; preg_match('/<\s*img [^\>]*src\s*=\s*[\""\']?([^\""\'>]*) /i' , $post->post_content, $matches); $imageurl=$matches[1]; // get comments for this post $comcount = $wpdb->get_var(" SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_post_ID=$post->ID AND NOT (comment_type = 'pingback' OR comment_type = 'trackback')"); // additional formatiing if ($year!=$curyear) { // close the previous day/month if ($curday) $result.="</div></div></td>"; $curday=''; $curmonth=''; // year start in a new column (<td>) $result.= '<td valign="top"><div class="sz_date_yr">' .$year.'</div><div class="sz_cont">'; $result.= '</div></td>'; $curyear=$year; } if ($month!=$curmonth) { // close the previous day/month if ($curday) $result.="</div></div></td>"; $curday=''; // month starts in a new column (<td>) $result.= '<td valign="top"><div class="sz_date_mon">' .$month.'</div><div class="sz_month">'; $curmonth=$month; } if ($day!=$curday) { // close previous day if ($curday) $result.="</div>"; $result.= '<div class="sz_date_day">'.$day.' </div><div class="sz_day">'; $curday=$day; } // retrieve the archive entry representation ob_start(); include('snazzy-layout-1.php'); $output = ob_get_contents(); ob_end_clean(); $result.=$output; } // close the previous day/month if ($curday) $result.="</div></div></td>"; // close the main page elements $result.="</tr></tbody></table></div>"; // return the result return $result; } This is the part to which the error message is referring to: // retrieve post information we need $title = $post->post_title; $excerpt= $this->get_excerpt($post->post_content); $url=get_permalink($post->ID); $date = strtotime($post->post_date); // format the date $day = date('d', $date); $month = date('M', $date); $year = date('Y', $date); The error message says that I'm using $this when not in "object context". The part where $this is used is needed to display an excerpt of the post content. This is the same way how it's shown in the book, for some reason it doesn't work for me. What would be an alternative way that I could do to make it work, any ideas? First i will show the code that activates the error: Code: [Select] if($current_host != null) { print_r2("1"); print_r2($current_host); print_r2($current_foundResult); print_r2("2"); $current_host::addFoundResult($current_foundResult); } this is the output: Quote 1 Host Object ( [hostname] => www.google.nl [foundResults] => Array ( ) ) FoundResult Object ( [url] => [title] => [visits] => ) 2 Fatal error: Using $this when not in object context in ~~~~~~~~~~~~~ on line 385 the error comes from this line: $this->foundResults[] = $foundResult; Code: [Select] class Host { public $hostname; public $foundResults; public function __construct($hostname) { $this->hostname = $hostname; $this->foundResults = array(); } public function addFoundResult($foundResult) { $this->foundResults[] = $foundResult; } } what i don't get about it is that both the Host Object and the FoundResult Object exist... I get the error code "Fatal error: Using $this when not in object context in /home/feenetwo/public_html/language/english/mails/sale_third_party_notification.php on line 7" when I complete the form from the link in the screenshot atached... the site is feenetwork.com and im getting really fustrated with it.... Can anyone help? Hi,
This code works (and correctly shows just one result in my view);
$people = DB::table('people')->where('id', '=', $person_id)->get();But this one doesn't; $people = DB::table('people')->where('id', $person_id)->first();And produces the error; Trying to get property of non-object (View: /media/sf_sandbox/health/app/views/agreement/display.blade.php)The `people` table just has a few fields of information on the individual with a primary key called `id`. I followed the Laravel guide on select statements. I don't understand what the error is trying to tell me and I don't get why that second statement is wrong. What's so wrong about it? I just want to understand Laravel/Objects better.... Thanks |