PDA

View Full Version : connecting to an SQL database on a webserver


modeler4547
07-27-2004, 07:22 AM
Thanks for the help if you can. I have borrowed this code and am attempting to use it to connect to my SQL database on my web server. I have highlighted the text that I believe is unique to my database setup although the actual text names are not correct yet since I am not sure of the correlation. Ie. Is “fryshane_uk_db supposed to be my database name ‘washwrit_members’ or..table name?”
Here is what I know about my SQL setup.

Host=localhost
Database name=washwrit_members
Table name=Member Directory type=MyISAM
10 fields of which ‘age’, ‘initial’, and ‘interests’ are fields
There exists three records for three people right now

If this code DID work, how does it know to create a fourth record (for a new member) or just plug in the age, initial and interest for an existing member)?

What are the parameters in lay terms for mysql_connect? I think I know localhost as a default host name but what about ‘fryshane’? That isn’t the table name, is it?

As far as PHP goes, how does the html file know where the PHP related files are. I know in PERL you have to tell it the location of PERL, do you have to do this with PHP?

Finally, is this all that I need to connect to a server and input data? HTML, a PHP capable server and an SQL server?


If someone can answer these questions, I prob will be able to successfully connect to my SQL databse.







-----------------------------------------------HTML FORM CODE----------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<?php
$db = mysql_connect("localhost","fryshane","********") or die("Cannot connect to the database.");
mysql_select_db("fryshane_uk_db",$db);
?>
</head>
<body>

<b>Add Information to your plan file</b>
<form name="plan" method="post" action="<?php echo $PHP_SELF; ?>">
Date:
<input type="text" name="age">
<br>
Title: <input type="text" name="initial">
<br>
Plan update:<br>
<textarea name="interests" cols="100" rows="10"></textarea><br>
<input type="submit" name="Submit" value="Submit">
<?php

if (isset($age) && isset($initial) && isset($interests))
{
$sql = "INSERT INTO Jonathan ( age, initial, interests ) VALUES ( '$age', '$initial', '$interests' )";
$query = mysql_query($sql) or die("Cannot query the database." .mysql_error());
echo "Database Updated.";
}

?>
</form>

</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------

azlatin2000
07-27-2004, 09:54 AM
If this code DID work, how does it know to create a fourth record (for a new member) or just plug in the age, initial and interest for an existing member)?

It doesn;t, this code will insert a new record for every submit of the form, to update you need to use update, not insert.

What are the parameters in lay terms for mysql_connect? I think I know localhost as a default host name but what about ‘fryshane’? That isn’t the table name, is it?
mysql_connect(host[:port],user [,pass])
stuff within [ and ] is optional.

As far as PHP goes, how does the html file know where the PHP related files are. I know in PERL you have to tell it the location of PERL, do you have to do this with PHP?
It is all set within php.exe or php.ini or httpd.conf.

Finally, is this all that I need to connect to a server and input data? HTML, a PHP capable server and an SQL server?

Yes, and the knowledge of how to do so, and a web server.


If someone can answer these questions, I prob will be able to successfully connect to my SQL databse.