3 Replies - 2217 Views - Last Post: 06 June 2008 - 12:19 PM Rate Topic: -----

#1 islander  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-June 08

create table insert values

Post icon  Posted 05 June 2008 - 01:26 PM

Hello:
I'm a newer user at PHP, MYSql and have taken a four day intro course. I Was using AccessVB before going down this newer web programming.
I can use the code block pasted below in the phpMyAdmin window to create a table named OutStdCnts which also get populated or records append to by the SELECT part of the code. This works in the phpMyAdmin window. I'm trying to duplicate it from within PHP code. I was able to create table with this code in php see the first code block.
But can't find how to populate the table based on the SELECT statement below second code block?
Any help would be greatly appreciated.

$sql = 'DROP TABLE IF EXISTS `OutStdCnts`';
mysql_query( $sql );


$sql = 'CREATE TABLE `outstdcnts` (
		`TotalOSP` VARCHAR( 20 ) NOT NULL,
		`outstandingPositive` VARCHAR( 20 ) NOT NULL,
		`Livingunit` VARCHAR( 5 ) DEFAULT 0 NOT NULL,
		`Region` VARCHAR( 25 ) NOT NULL,
		PRIMARY KEY ( `Region` )
	   )';

echo 'Creating table: \'OutStdCnts\'....';
mysql_query( $sql );






CREATE TABLE IF NOT EXISTS OutStdCnts(
TotalOSP varchar(20) NOT NULL ,
outstandingPositive Varchar( 5 ) NOT NULL DEFAULT '0',
Livingunit Varchar( 35 ) NOT NULL ,
Region Varchar( 25 ) NOT NULL
) SELECT Region, Livingunit, outstandingPositive, COUNT( `OutstandingPositive` ) AS TotalOSP
FROM clients AS c, dailylog AS d
WHERE c.ID = d.ClientID
AND `OutstandingPositive` <> 'NULL'
AND `Region` = 'Wyndham'
AND `livingunit` = 'grigg'
GROUP BY `OutstandingPositive` 

:blink: :blink: :blink:

Is This A Good Question/Topic? 0
  • +

Replies To: create table insert values

#2 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: create table insert values

Posted 05 June 2008 - 01:48 PM

you would need to use the insert command
Was This Post Helpful? 0
  • +
  • -

#3 Akelo  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 98
  • Joined: 12-December 07

Re: create table insert values

Posted 05 June 2008 - 02:46 PM

Here's the base idea behind it. Also, remember to sanitize your input or else Satan will eat your soul. Cheers!

$query = "INSERT INTO outstdcnts (TotalOSP, outstandingPostive, Livingunit, Region) VALUES ('$tOSP','$oPos','$Lunit','$reg')";
$result = mysql_query($query);
if($result)//if the query ran alright
{

}
else//if it didn't
{

}



Was This Post Helpful? 0
  • +
  • -

#4 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: create table insert values

Posted 06 June 2008 - 12:19 PM

Quote

Also, remember to sanitize your input or else Satan will eat your soul.


Classic. Maybe the threat of eternal damnation will help protect applications.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1