0

I am having a little problem with the following code:

<?php
class appointments
{
    private $conn;

    function __construct($conn)
    {
        $this->conn = $conn;
    }

    function usercompany($uid)
    {
        return $this->conn->getone("SELECT company FROM signup WHERE UID = '".$uid."'");
    }

    function hastemplate($uid)
    {
        return $this->conn->getone("SELECT COUNT(parentid) FROM appointments_templates WHERE parentid = '$uid'");
    }

    function gettemplate($uid)
    {
        if($this->hastemplate($uid)){
            return $this->conn->getrow("SELECT * FROM appointments_templates WHERE parentid = '" . $uid . "'");
        } else {
            $appointment_template = 'This is a reminder to let you know that you have an appointment on {appointment} at '. $this->usercompany($uid);

            $sql = "INSERT INTO appointments_templates SET parentid = '" . $uid . "', content = '" . $appointment_template . "'";
            $this->conn->execute($sql);

            return $this->gettemplate($uid);
        }
    }  
}
?>

When I call usercompany($uid) by itself I get a correct result which is the users company. However when I call gettemplate($uid) the new template gets added to the database but without the results of usercompany($uid). Am I doing something wrong?

Edit: Regarding the INSERT syntax: http://milov.nl/2836

To recap: Issue is not that its not getting added to the database but rather than getting inserted as "This is a reminder to let you know that you have an appointment on {appointment} at XYZ Inc." its getting added as "This is a reminder to let you know that you have an appointment on {appointment} at "

1
  • can you put the code that uses this class ? Commented Dec 12, 2011 at 5:51

2 Answers 2

3

insert statements do not work like that. Rather than:

insert into table set column1 = value1, column2 = value2

They work like this:

insert into table (column1, column2) values (value1, value2)

Additionally, I don't see any escaping going on, so I hope nobody has a company with an apostrophe in its name.

Sign up to request clarification or add additional context in comments.

1 Comment

The issue is not that its not getting added to the database but rather the issue is its getting added as "This is a reminder to let you know that you have an appointment on {appointment} at" instead of "This is a reminder to let you know that you have an appointment on {appointment} at XYZ Inc." The company name is escaped when its stored in the database.
0

it seems to be you have wrong syntax for insert query. You can refer the syntax for mysql insert query here http://www.w3schools.com/php/php_mysql_insert.asp

Try using this instead using single quotes,

$appointment_template = "This is a reminder to let you know that you have an appointment on {appointment} at ". $this->usercompany($uid)."";

5 Comments

The issue is not that its not getting added to the database but rather the issue is its getting added as "This is a reminder to let you know that you have an appointment on {appointment} at" instead of "This is a reminder to let you know that you have an appointment on {appointment} at XYZ Inc."
Also $appointment_template = "This is a reminder to let you know that you have an appointment on {appointment} at ". $this->usercompany($uid).""; doesnt work.
try storing $this->usercompany($uid) in a variable and see whether the function returns any value. i mean inside the gettemplate .
@MeisamMulla What is the return value of $this->usercompany($uid) ? Probably it is returning an empty string...
It is the users company name. When I call $appointment->usercompany($uid) I get the correct result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.