Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 12-13-2004, 02:50 PM   #1
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quick PHP Question

I am new to PHP and trying to insert information into a table automatically by going to a URL. For example. I want it so when I go to www.url.com?user=test&password=word

it will automatically add the user name and password into the table (users)

I tried using the following for www.url.com/index.php

<?

$DBhost = "localhost";
$DBuser = "userdb";
$DBpass = "password";
$DBName = "namedb";

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select
database $DBName");


mysql_query("INSERT INTO `Users` VALUES ('$user','$password')") or die(mysql_error());


mysql_close();

?>

This brings me to a blank page but does not add anything to the table


Is there something I might be doing wrong?
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-13-2004, 02:59 PM   #2
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Nevermind, its working now ;)
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-13-2004, 03:18 PM   #3
Repetitive Monkey
Confirmed User
 
Join Date: Feb 2004
Posts: 3,505
Sloppy! ;) Here's how I would have done it.

PHP Code:
<?
$DBhost="localhost";
$DBuser="userdb";
$DBpass="password";
$DBName="namedb";
if(@mysql_connect($DBhost,$DBuser,$DBpass)){
    if(@mysql_select_db($DBName)){
        if(!@mysql_query("INSERT INTO 'Users' VALUES ('".$_GET["user"]."','".$_GET["password"]."')")){
        echo"Unable to insert new row into table on the database <i>".$DBName."</i>.";
        }
    }else{
    echo"Unable to select the database <i>".$DBName."</i>.";
    }
@mysql_close();
}else{
echo"Unable to connect to MySQL.";
}
?>

Last edited by Repetitive Monkey; 12-13-2004 at 03:21 PM..
Repetitive Monkey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-13-2004, 03:28 PM   #4
Repetitive Monkey
Confirmed User
 
Join Date: Feb 2004
Posts: 3,505
Actually, you might also want to check for whether the required variables really exist, and some memory can also be saved on the internal variables. Please use this:

PHP Code:
<?
if($_GET["user"] && $_GET["password"]){
    if(@mysql_connect("localhost","userdb","password")){
    $DBName="namedb";
        if(@mysql_select_db($DBName)){
            if(!@mysql_query("INSERT INTO `Users` VALUES ('".$_GET["user"]."','".$_GET["password"]."')")){
            echo"Unable to insert new row into the database <i>".$DBName."</i>.";
            }
        }else{
        echo"Unable to select the database <i>".$DBName."</i>.";
        }
    @mysql_close();
    }else{
    echo"Unable to connect to MySQL.";
    }
}else{
echo"Required variables are missing.";
}
?>
Replace the hahaha123; stuff with a right bracket.
Repetitive Monkey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.