Jump to content

Catchable fatal error


Smudly

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/234786-catchable-fatal-error/
Share on other sites

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(8) "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"

}

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.

 

 

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);
    }

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.