Jump to content

Archived

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

Synergic

simple mysql insert question

Recommended Posts

i haven't figured why i'm getting unidentified variable with the following insert statements. i mean using values work fine but as soon as i stick a variable inside the insert clause i get unidentified variable:

[code]

<?php
include_once 'DatabaseClass.php';

class BookStoreClass extends DatabaseClass {

var $name = 'hello';
var $birthday = 'hello';

function registerUser($user)
{
parent::connect();

mysql_query ("INSERT INTO birthdays (name, birthday) VALUES ('$name','$birthday')");
parent::close();
}

}
?>

[/code]

Notice: Undefined variable: name in

Notice: Undefined variable: birthday in

Share this post


Link to post
Share on other sites
i am not familiar with classes and such but something this simple why make it complicated

[code]<?php
$name = 'hello';
$birthday = 'hello';

$sql = "INSERT INTO birthdays (name, birthday) VALUES ('$name', '$birthday')";
  mysql_query($sql) or die(mysql_error());
?>[/code]

Ray

Share this post


Link to post
Share on other sites
actually i still want to use OO concepts. i still can't figure out why the original code doesn't work. If i remove the variables and insert values instead it works no problems. The funny thing is if i declare the variable locally and use it, it works.

Share this post


Link to post
Share on other sites
and if i pass a $user object with a username, password i can print it within the function, it works. However if i use it in the insert statement i get undefined variable:

$sql = "INSERT INTO birthdays (name, birthday) VALUES ('$user->getUserName()', '$birthday')";

Share this post


Link to post
Share on other sites
ok solution was to:

[code]

$sql = "INSERT INTO userinfo VALUES ('','".$user->getUserName()."')";

[/code]

???

Share this post


Link to post
Share on other sites

×

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.