PhP and MySQL are NOT on your machine: they are on your server.
Check first that your "site" server offers you these, through something like "Cpanel". Most servers (website hosts) have them included when you bought the domain and booked the storage on the server.
Then...
To learn a bit of PhP, go to www.php.net. If you know a bit of C or similar, you will see that most stuff is very similar in PhP.
You search for a function? Just enter the function in C in the search. It returns the similar functions. Check the parameters, read the code snipets that others have added and there you go.
Write a piece of code, upload to the server and check the result. Your new page will have ".php" extention, and the PhP code will be enclosed with "" at the end.
So your HTML page (say "test.html") would be:
"
....
....
the body text.
echo ("Hello world!
"); // to display "hello world!"
?>
the rest of the body text
And you save it as "test.php", then upload.
This will teach you to use PhP...
Now for MySQL...
First, you will have to get your username and password, and to create a data-base, directly, through the control panel of your site.
After that, you can create tables in your DB
Bit more complicated, but you mearly need a few functions:
Connect, make a table, add entries, delete entries, fetch entries...
function dbconnect()
{
$link = mysql_connect("localhost", "username", "password") or die(" Could not connect : " . mysql_error());
mysql_select_db("dbasename") or die("Could not select database");
return($link);
}
function makedbtable()
{
$tablename = "stories";
$link = dbconnect();
$cmdd = "DROP TABLE IF EXISTS " . $tablename;
mysql_query($cmdd) or die("Query failed : " . mysql_error());
$cmdd = "CREATE TABLE `".$tablename."` (
`number` VARCHAR(10) NOT NULL,
`title` VARCHAR(100) NOT NULL,
`text` LONGTEXT
) TYPE = MYISAM" ;
mysql_query($cmdd) or die("Query failed : " . mysql_error());
mysql_close($link);
}
function addstories($_POST)
{
while(list($name,$value) = each($_POST))
$$name=$value;
$link=dbconnect();
$txt = 'VALUES ("'.$number.'","'.$title.'","'.$text.'")';
$sql = 'INSERT INTO `stories` ( `number`,`title`,`text`) ' . $txt;
$result = mysql_query($sql) or die("Query failed : " . mysql_error());
mysql_close($link);
return ($result);
}
function delstories($_POST)
{
while(list($name,$value) = each($_POST))
$$name=$value;
$link=dbconnect();
$query="DELETE FROM `stories` WHERE `title` = '" . $title . "' AND `number`= '".$number."' LIMIT 1 ";
mysql_query($query) or die("Query failed : " . mysql_error());
mysql_close($link);
}
function getentries()
{
$link=dbconnect();
$query="SELECT * FROM `stories` WHERE 1";
$list = mysql_query($query) or die("Query failed : " . mysql_error());
while ($lst = mysql_fetch_array($list))
{
echo ($lst[0]."
");
echo ($lst[1]."
");
echo ($lst[2]."
");
}
mysql_free_result($list);
mysql_close($link);
}
?>
That's all you need to know to get started.
You will soon get the grip of it!
Good luck.
2007-06-30 05:32:25
·
answer #4
·
answered by just "JR" 7
·
0⤊
0⤋