Synergic Posted September 19, 2006 Share Posted September 19, 2006 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]<?phpinclude_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 inNotice: Undefined variable: birthday in Quote Link to comment Share on other sites More sharing options...
craygo Posted September 19, 2006 Share Posted September 19, 2006 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 Quote Link to comment Share on other sites More sharing options...
Synergic Posted September 19, 2006 Author Share Posted September 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
Synergic Posted September 19, 2006 Author Share Posted September 19, 2006 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')"; Quote Link to comment Share on other sites More sharing options...
Synergic Posted September 19, 2006 Author Share Posted September 19, 2006 ok solution was to:[code]$sql = "INSERT INTO userinfo VALUES ('','".$user->getUserName()."')";[/code] ??? Quote Link to comment 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.