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 Link to comment https://forums.phpfreaks.com/topic/21283-simple-mysql-insert-question/ 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 Link to comment https://forums.phpfreaks.com/topic/21283-simple-mysql-insert-question/#findComment-94669 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. Link to comment https://forums.phpfreaks.com/topic/21283-simple-mysql-insert-question/#findComment-94672 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')"; Link to comment https://forums.phpfreaks.com/topic/21283-simple-mysql-insert-question/#findComment-94678 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] ??? Link to comment https://forums.phpfreaks.com/topic/21283-simple-mysql-insert-question/#findComment-94688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.