PHP help

Hi.. I am using godaddy hosting... Can I connect to the database this way..  because when I try to registar in my php form nothing is showing up in my database.. (NOTE: I did have my password in there I just took it off to send this email so, that is not a problem.) .. I have a feeling it has to do with my index.php page too. .I think..I'm not sure..Can somebody help me?? OR does it have to do with the connection to the database??  Thanks!

<!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>Untitled Document</title></head>
<body><?php$con = mysql_connect("craftofcharisma.db.4082414.hostedresource.com", "craftofcharisma", "password");if (!$con){   echo "<h2>Sorry, we cannot process your request at this time, please try again later</h2>\n";   echo "<a href=\"index.php?content=register\">Try again</a><br>\n";   echo "<a href=\"index.php\">Return to Home</a>\n";   exit;}mysql_select_db("craftofcharisma", $con) or die('Could not connect to database');$userid = $_POST['userid'];$password = $_POST['password'];$password2 = $_POST['password2'];$fullname = $_POST['fullname'];$email = $_POST['email'];$baduser = 0;// Check if userid was enteredif (trim($userid) == ''){   echo "<h2>Sorry, you must enter a user name.</h2><br>\n";   echo "<a href=\"index.php?content=register\">Try again</a><br>\n";   echo "<a href=\"index.php\">Return to Home</a>\n";   $baduser = 1;}//Check if password was enteredif (trim($password) == ''){   echo "<h2>Sorry, you must enter a password.</h2><br>\n";   echo "<a href=\"index.php?content=register\">Try again</a><br>\n";   echo "<a href=\"index.php\">Return to Home</a>\n";   $baduser = 1;}//Check if password and confirm password matchif ($password != $password2){   echo "<h2>Sorry, the passwords you entered did not match.</h2><br>\n";   echo "<a href=\"index.php?content=register\">Try again</a><br>\n";   echo "<a href=\"index.php\">Return to Home</a>\n";   $baduser = 1;}//Check if userid is already in database$query = "SELECT userid from users where userid = '$userid'";$result = mysql_query($query);$row = mysql_fetch_array($result, MYSQL_ASSOC);if ($row['userid'] == $userid){   echo "<h2>Sorry, that user name is already taken.</h2><br>\n";   echo "<a href=\"index.php?content=register\">Try again</a><br>\n";   echo "<a href=\"index.php\">Return to Home</a>\n";   $baduser = 1;}if ($baduser != 1){   //Everything passed, enter userid in database   $query = "INSERT into users VALUES ('$userid', PASSWORD('$password'), '$fullname', '$email')";   $result = mysql_query($query) or die('Sorry, we are unable to process your request.' . mysql_error());   if ($result)   {      $_SESSION['valid_recipe_user'] = $userid;      echo "<h2>Your registration request has been approved and you are now logged in!</h2>\n";      echo "<a href=\"index.php\">Return to Home</a>\n";      exit;   } else   {      echo "<h2>Sorry, there was a problem processing your login request</h2><br>\n";      echo "<a href=\"index.php?content=register\">Try again</a><br>\n";      echo "<a href=\"index.php\">Return to Home</a>\n";   }}?>
</body></html>
 
or do I have to do it this way:   Then what do  I put here $yourfield = 'your_field';
 
<?php//Connect To Database$hostname='craftofcharisma.db.4082414.hostedresource.com';$username='craftofcharisma';$password='your password';$dbname='craftofcharisma';$usertable='your_tablename';$yourfield = 'your_field';mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');mysql_select_db($dbname);$query = 'SELECT * FROM $usertable';$result = mysql_query($query);if($result) {    while($row = mysql_fetch_array($result)){        $name = $row['$yourfield'];        echo 'Name: '.$name;    }}

By jenkreider83 on

Stalk me!

Recommended Reading