Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 I cant get this code to work...someone please help

Author  Topic 

Blackmore
Starting Member

1 Post

Posted - 2008-09-19 : 20:05:40
Ive been trying to get my SQL code to actually check if a DB and table exists, and then based on that, take the next action. If they dont exist, then the code should create them. If they do exist, simply proceed to insert the values.

This is my progress so far.

<?php

$username=$_POST['username'];
$offence=$_POST['offence'];
$punishment= $_POST['punishment'];
mysql_connect ('localhost','root','panda');

mysql_query IF NOT EXISTS (select * from sys.databases where name = 'naughtylist');
create database naughtylist

if (object_id('watchlist') is NULL)
CREATE TABLE watchlist (

username VARCHAR(16) NOT NULL
offence TEXT NOT NULL
punishment TEXT NOT NULL
PRIMARY KEY (username)
);


$sql=mysql_query ("INSERT INTO watchlist (username, offence, punishment) VALUES ('$username','$offence', '$punishment')");
$sql2="SELECT * FROM table_anme WHERE data = data_inserted LIMIT 1;"
echo $sql;
echo $sql2;
?>

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-09-19 : 20:35:38
You should not really be creating tables like this. Typically your schema is static and defined before your application is deployed.
Any anyway this is a SQL Server forum not MySQL
Go to Top of Page
   

- Advertisement -