Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,688 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,297 people online right now. Registration is fast and FREE... Join Now!




create table insert values

 
Reply to this topicStart new topic

create table insert values

islander
post 5 Jun, 2008 - 12:26 PM
Post #1


New D.I.C Head

*
Joined: 5 Jun, 2008
Posts: 2

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.

CODE

$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 );





CODE

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.gif blink.gif blink.gif
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 5 Jun, 2008 - 12:48 PM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


you would need to use the insert command
User is offlineProfile CardPM

Go to the top of the page

Akelo
post 5 Jun, 2008 - 01:46 PM
Post #3


D.I.C Head

**
Joined: 12 Dec, 2007
Posts: 77


My Contributions


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


$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
{

}

User is offlineProfile CardPM

Go to the top of the page

akozlik
post 6 Jun, 2008 - 11:19 AM
Post #4


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 596



Thanked 22 times

Dream Kudos: 750
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:28AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month