View Single Post
  #3 (permalink)  
Old Sep 20th, 2006, 22:40
Micky-D Micky-D is offline
Junior Member
Join Date: Jun 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help with upload with ID script

Hey,

thanks for the reply. I currently have paid hosting.. 25GB storage.. 1TB xfer bandwidth.. unlimited MySQL databases and php 4 0r 5 or I can install my own php to my domain if needed so I can alter the php.ini if needed to turn certain things on or off

Ok so I have been reading here for some of the basics http://www.tizag.com/phpT/

and also

http://www.tizag.com/mysqlTutorial/index.php

As I figure they cover the basics.. I have learned HTML and I have played around with PHP but do not fully understand it yet.. So I'm hoping these small project exercises will help me

So where to start? I presume I would start with the upload form first and also the config?


//EDIT

I have started my form and insert script here

FORM

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Database Insert Form By Micky-D</title>
</head>

<body>
<!-------------------------------------------------------->
<!-------SIMPLE INSERT FORM DATA TO DATABASE SCRIPT------->
<!-----Created By Micky-D 21st September 2006 @ 00:15----->
<!-------------------------------------------------------->

<center><b><font face="verdana, arial" size="2">This Is A Simple Form I Created To Insert Data Into A Database<br />Thanks Go To <a href="http://www.blazonry.com/" title="Blazonry.com">Blazonry</a> For The Tutorial This Is Based On<br />This Is My First Ever Script Written By Hand As Opposed To Using Dreamweaver The Lazy Way LOL ;)</font></b></center>
<br />
<!-------FORM FOR DATA TO BE INSERTED------->
<form method ="post" action"post_data.php">
<center>
<b>Some Data</b> &nbsp;<input type="text" size="15" name="some_data" />
<br />
<br />
<b>More data</b>&nbsp;&nbsp; <input type="text" Size="15" name="more_data" />
</center>
<br />
<br />
<center><input type="submit" value="Insert Data" /></center>
</form>

</body>
</html>
INSERT DATA FROM FORM TO DATABASE PHP

Code: Select all
<?php
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////-------------------------------------------------------------////
////---------SIMPLE INSERT FORM DATA TO DATABASE SCRIPT----------////
////-------------------------------------------------------------////
////-------Created By Micky-D 21st September 2006 @ 00:15--------////
////------------------Designed For www.XXXXXXXX.com--------------////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

// ---This Is The Script To Open A Database Connection---
$usr = "----databaseusername";
$pwd = "databasepassword";
$db = "databasename";
$host = "hostname.to.database";

$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
// ---END OF DATABASE CONNECTION---
?>

<?php
// ---This Is The Section That Takes Form Data And Inserts It Into The Database---
if ($REQUEST_METHOD=="POST") {

$SQL = " INSERT INTO test ";
$SQL = $SQL . " (some_data, more_data) VALUES ";
$SQL = $SQL . " ('$some_data','$more_data') ";
$result = mysql_db_query($db,"$SQL",$cid);

if (!$result) {
    echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

echo ("Data Has Been Inserted\n");

}

mysql_close($cid);
// ---ENDO OF INSERT DATA SECTION---
?>
The insert form data is based on a tutorial from here http://www.blazonry.com/scripting/li...nsert_data.php

Now Im going to use this tutorial here http://www.tizag.com/mysqlTutorial/mysqltables.php to create a table to store this data in a test database I created.

I have a question about this part
Code: Select all
if (!$result) {
    echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

echo ("Data Has Been Inserted\n");

}
shouldnt or couldnt it be else echo ("Data Has Been Inserted\n"); ????

Last edited by Micky-D; Sep 20th, 2006 at 23:46.
Reply With Quote