Re: inserting data into database!

From: Date: Fri, 14 May 2004 19:32:10 +0000
Subject: Re: inserting data into database!
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-34432@lists.php.net to get a copy of this message
"Ronald Allen" <sesel@omantel.net.om> wrote in message news:20040514192305.43601.qmail@pb1.pair.com... > Two questions? > First why am I getting undefined variable tmp , yet it works > Second how would I insert data into this table? > <? > $db_table = 'log'; > $conn = mysql_connect($db_host,$db_user,$db_pass); > > if ($conn == true) { > mysql_select_db($db_name,$conn); > $result = mysql_query("SELECT * from $db_table",$conn); > while($row = mysql_fetch_object($result)) { > $tmp .= "ID : $row->ID <br>\n"; > $tmp .= "Base : $row->Base <br>\n"; > $tmp .= "Date_and_Time : $row->Date_and_Time <br>\n"; > $tmp .= "Event_Type : $row->Event_Type <br>\n"; > $tmp .= "Description : $row->Description <br>\n"; > $tmp .= "Initials : $row->Initials <br><hr>\n"; > } > } else { > echo 'could not connect to database : '. mysql_error(); > } > print $tmp; > ?> You have to initialize $temp before using it with '.=' $temp = ''; $temp .= 'my string'; Or just set the first line with = $tmp = "ID : $row->ID <br>\n"; $tmp .= "Base : $row->Base <br>\n"; $tmp .= "Date_and_Time : $row->Date_and Your insert should look like this (if ID is an auto-increment field): $insert = "INSERT INTO $db_table SET "; $insert .= "Base = '" . $row->Base . "', "; $insert .= "Date_and_Time = '" . $row->Date_and_Time . "', "; $insert .= "Event_Type = '" . $row->Event_Type . "', "; $insert .= "Description = '" . $row->Description . "', "; $insert .= "Initials = '" . $row->Initials . "'"; mysql_query($insert, $conn); Hope this helps, Regards, Torsten

« previous php.db (#34432) next »