Jump to content

simple mysql insert question


Synergic

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
Link to comment
https://forums.phpfreaks.com/topic/21283-simple-mysql-insert-question/
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
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')";

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.