Re: Sample of MSSQL/PHP

From: Date: Mon, 11 Dec 2000 12:36:02 +0000
Subject: Re: Sample of MSSQL/PHP
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-5177@lists.php.net to get a copy of this message
Nothing easier. In the example below, I do make a reference to my own MSSQL-handling class., I also haven't tested this (since I'm writing it on the fly), so there MAY be a few errors. The table: ---------- create table sys_users (id varchar(8) primary key, password varchar(8) not null, firstname varchar(32) not null, lastname varchar(32) not null) The form: --------- <html> <body> <form method='POST' action = 'adduser.php'> <input type = 'text' name = 'id'><br> <input type = 'password' name = 'pwd'><br> <input type = 'text' name = 'fname'><br> <input type = 'text' name = 'lname'><br> <input type = 'submit' value = 'Submit'> </form> </body> </html> The script: ----------- <html> <body> <? include ("mssql.php"); $conn = new MSSQL; // Create new instance of MSSQL class $conn->connect ("database", "user", "password"); // Connect to database $conn->exec ("select * from sys_users where id = '$id'"); // Check if this id already exists if ($conn->next()) // was there a row? { echo ("ID already exists!"); exit; } $conn->done (); // Release the "select" results $conn->exec ("insert into sys_users values ('$id', '$pwd', '$fname', '$lname'); echo ("User added successfully!"); $conn->close ();+ ?> </body> </html> You'll notice that the NAME we give out inputs on the form AUTOMATICALLY become the variable's name in the PHP script. This also applies to cookies and parameters passed in the URL itself (e.g. http://www.whatever.com/script.php?comment=hello - $comment will become a variable set to hello) ""Julio Cuz, Jr."" <jcuz@rccd.cc.ca.us> wrote in message news:4.3.2.7.2.20001208160932.00b37e78@rccd.cc.ca.us... > Hi-- > > Does anyone have a good sample program that uses FORMS, MSSQL and > PHP? (I'm new at this PHP thing, I like it, but I'm going crazy trying to > figure out those small details!). > > Thanks a lot! > > Julio Cuz, Jr. > Riverside Community College > jcuz@rccd.cc.ca.us > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#5177) next »