FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Another dumb question <.<





Manntis
Okay here's my other dumb question:

Code:

CODE


<?PHP

//Database Information

$dbhost = "localhost";
$dbname = "your database name";
$dbuser = "username";
$dbpass = "yourpass";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

   
$name = $_POST['name'];
$email = $_POST['email'];   
$username = $_POST['username'];
$password = md5($_POST['password']);

// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
    echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";
    unset($username);
    include 'register.html';
    exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO users (name, email, username, password)
VALUES('$name', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";
   
// mail user their information

$yoursite = ‘www.blahblah.com’;
$webmaster = ‘yourname’;
$youremail = ‘youremail’;
   
$subject = "You have successfully registered at $yoursite...";
$message = "Dear $name, you are now registered at our web site. 
    To login, simply go to our web page and enter in the following details in the login form:
    Username: $username
    Password: $password
   
    Please print this information out and store it for future reference.
   
    Thanks,
    $webmaster";
   
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
   
echo "Your information has been mailed to your email address.";

?>


At the top of the code, it says CODE. Do I put that into the PHP document, or is that just saying this is now code?
Star Wars Fanatic
No, just put it in a file called "myfile.php" (change the myfile to whatever you want)... If you keep the "CODE" in there it will just appear at the top of the page...

Code:
<?PHP

//Database Information

$dbhost = "localhost";
$dbname = "your database name";
$dbuser = "username";
$dbpass = "yourpass";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

   
$name = $_POST['name'];
$email = $_POST['email'];   
$username = $_POST['username'];
$password = md5($_POST['password']);

// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
    echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";
    unset($username);
    include 'register.html';
    exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO users (name, email, username, password)
VALUES('$name', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";
   
// mail user their information

$yoursite = ‘www.blahblah.com’;
$webmaster = ‘yourname’;
$youremail = ‘youremail’;
   
$subject = "You have successfully registered at $yoursite...";
$message = "Dear $name, you are now registered at our web site.
    To login, simply go to our web page and enter in the following details in the login form:
    Username: $username
    Password: $password
   
    Please print this information out and store it for future reference.
   
    Thanks,
    $webmaster";
   
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
   
echo "Your information has been mailed to your email address.";

?>
Azmo
code/text before the first <? php tag is just for comment or stuff like that.. unless it's html ofc
chris20
The CODE text doesn't tell the web server that it is php code and should be handled as such. The part that does that is the <?php. Removing the CODE text won't do anything to the script.
Related topics
Kinda dumb question regarding DNS
A few simple questions about Frihost
[CSS] form design
possibly another dumb question.... cpanel/directadmin
~~~Free Subdomains
Question about resolutions
nikki here...........introducing myself seems silly.........
State your Political Philosophy! (1000 FRIH$ to the best!)
Thought--Another Philosophical Question
Another philosophical question...
O'calhoun's reusable stupid php question thread [NEW]
Moving phpBB from one host to another
dumb nu-b question on phpmyadmin
Probably a dumb question but..
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.