Smudly Posted April 26, 2011 Share Posted April 26, 2011 I'm creating a Contact Us page that has a form users may use to send a message. I've run into an issue and I have never seen this error before. Could anyone help explain how to fix this please? Catchable fatal error: Object of class stdClass could not be converted to string in /homepages/30/d354929366/htdocs/contact.php on line 13 Line 13 is: $contactsql = "SELECT * FROM users WHERE username='$username'"; <?php include("inc/config.php"); include_once("inc/functions.php"); $ip = $_SERVER['REMOTE_ADDR']; $username = $_SESSION['customer']; $submit = (isset($_POST['submit'])); $to = "[email protected]"; $subject = "New Contact!"; $contactsql = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($contactsql); $row = mysql_fetch_assoc($result); $userid = $row['userid']; $name = $row['name']; $email = $row['email']; $username = $row['username']; if($submit){ if(!isset($_SESSION['customer'])){ $getusername = mysql_query("SELECT username FROM users WHERE email='$email'"); $getrow = mysql_fetch_assoc($getusername); $username = $getrow['username']; } $answered = 0; $date = date("Y-m-d"); $name = mysql_safe($_POST["name"]); $email = mysql_safe($_POST["email"]); $message = mysql_safe($_POST["comments"]); $name = $name; $email = $email; if($name){ if($email){ if($comments){ $success = "<div id='contsuccess'>We have received your message!</div>"; $newcontquery = "INSERT INTO contact VALUES ('','$userid','$username','$name','$email','$message','$answered','$date')"; mysql_query($newcontquery); mail("$to", "$subject", "My Site Title","From: [email protected]"); } else{ $error = "<div id='conterror'>Please type a question or comment!</div>"; } } else{ $error = "<div id='conterror'>Type in your Email!</div>"; } } else{ $error = "<div id='conterror'>Type in your Name!</div>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Language" content="en" /> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <title> my site </title> <meta name="description" content="" /> <meta name="keywords" content="" /> <link rel="stylesheet" type="text/css" href="styles/main.css" /> <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="styles/ie6.css" media="screen" /> <![endif]--> <!--[if gte IE 7]> <link rel="stylesheet" type="text/css" href="styles/ie7.css" media="screen" /> <![endif]--> </head> <body id="contact"> <div id="wrap"> <? include("inc/header/header.php")?> <div id="cwrap"> <div id="content"> <center><p><?php echo $success, $error; ?></p></center> <div class="contGen"> <FORM ACTION="contact.php" METHOD="POST" name="contactform1"> <div id="contformfirst">First Name: </div> <div id="contformfirstfld"><INPUT NAME="name" SIZE="30" class="FormField" value="<?php echo $dbfname; ?>"></div> <div id="contformemail">E-mail: </div> <div id="contformemailfld"><INPUT NAME="email" SIZE="30" class="FormField" value="<?php echo $dbemail; ?>"></div> <div id="contformcomments"><br><br>Comments: </div> <div id="contformcommentsfld"><textarea NAME="comments" rows="6" cols="23" SIZE="250"></textarea></div> <div id="contformsubmit"></div> <div id="contformreset"><input type='submit' name='submit' value='Submit'> <input type='reset' value='Reset'></div> </FORM> </div> </div> <? include("inc/left/leftnav.php")?> </div> <? include("inc/content/footer.php")?> </div> </body> </html> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2011 Share Posted April 26, 2011 $_SESSION['customer'] must be an instance of a class or an object. Are you trying to access a method or a property of that class to get the username? Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/#findComment-1206608 Share on other sites More sharing options...
Smudly Posted April 26, 2011 Author Share Posted April 26, 2011 Honestly I'm not sure. I had a pro setup the member's system and it's over my head. He has a bunch of Classes that take care of this stuff, so I'm unsure how I'm supposed to use it. Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/#findComment-1206609 Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2011 Share Posted April 26, 2011 Add the following code right before the $username = $_SESSION['customer']; line to find out what $_SESSION['customer'] contains - echo "<pre>"; var_dump($_SESSION['customer']); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/#findComment-1206612 Share on other sites More sharing options...
Smudly Posted April 26, 2011 Author Share Posted April 26, 2011 object(stdClass)#1 (12) { ["id"]=> string(2) "25" ["member_type"]=> string(1) "1" ["username"]=> string(6) "Smudly" ["password"]=> string(32) "63ab6b8cc73215d1608b4c10607452c7" ["email"]=> string(19) "[email protected]" ["name"]=> string(6) "bob" ["referrer"]=> string( "myfriend" ["country"]=> string(13) "UNITED STATES" ["join_date"]=> string(10) "2011-04-22" ["session"]=> string(42) "afef8c6234410e4970067f052f67b37b1303445583" ["confirm_code"]=> string(10) "0194688414" ["status"]=> string(6) "Active" } Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/#findComment-1206613 Share on other sites More sharing options...
PFMaBiSmAd Posted April 26, 2011 Share Posted April 26, 2011 You can access the username property using either - $_SESSION['customer']->username or after you assign $username = $_SESSION['customer']; using - $username->username However, I suspect that $_SESSION['customer'] is supposed to be an instance of a customer class, had the class definition existed before the session_start() statement. You need to find where $_SESSION['customer'] was created and at a minimum the person who wrote this code should have given you a list of the classes and the definition of the properties and methods of each class. Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/#findComment-1206615 Share on other sites More sharing options...
Smudly Posted April 26, 2011 Author Share Posted April 26, 2011 That did it. Thanks for the rundown on it all. It helps a lot. I found that the session was created in the Customer class (customer.php) function reload_session($cod) { $rowCutomer= $this->mPer->getOne($cod); $_SESSION['customer'] = mysql_fetch_object($rowCutomer); } Quote Link to comment https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/#findComment-1206617 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.