Jump to content

connect but wont select


studentofstone

Recommended Posts

This is my first project. Just a simple registration form. it will connect to the server but I can't convince it to select the the database 'learnphp'.

 

<?php
if($_POST['formSubmit'] == "Submit") 
    {
if(empty($_POST['formName'])) 
        {
		$errorMessage .= "<li>You forgot to enter your Name.</li>";
	}

if(empty($_POST['address'])) 
        {
		$errorMessage .= "<li>You forgot to enter your address.</li>";
        }
        	
if(empty($_POST['city'])) 
        {
		$errorMessage .= "<li>You forgot to enter your city.</li>";
	}
        	
if(empty($_POST['state'])) 
        {
		$errorMessage .= "<li>You forgot to enter your state.</li>";
	}

if(empty($_POST['zip'])) 
	{
		$errorMessage .= "<li>You forgot to enter your zip code.</li>";
	}

if(empty($_POST['phone'])) 
        {
		$errorMessage .= "<li>You forgot to enter your phone number.</li>";
	}

    if(empty($_POST['email'])) 
        {
		$errorMessage .= "<li>You forgot to enter your email.</li>";
	}
        	
        }


$varformName = $_POST['formName'];
$varaddress = $_POST['address'];
$varcity = $_POST['city'];
$varstate = $_POST['state'];
$varzip = $_POST['zip'];
$varphone = $_POST['phone'];
$varemail = $_POST['email'];




        
        
//generated by fatcow	


$link = mysql_connect('', '', ''); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
   }  
echo 'Connected successfully'; 
$db_selected = mysql_select_db("learnphp"); 

   if (!$mysql_select_db) { 
    die(' blast!' . mysql_error()); 
   }
       if(!empty($errorMessage))	 {
   echo("<p>There was an error with your form:</p>\n");
   echo("<ul>" . $errorMessage . "</ul>\n");
 }
     


		$sql = "INSERT INTO membership (memberName, address, city, state, zip, phone, email) VALUES (".
						PrepSQL($varmemberName) . ", " .
						PrepSQL($varAddress) . ", " .
						PrepSQL($varCity) . ",";
						PrepSQL($varState) . ",";
						PrepSQL($varZip) . ",";
						PrepSQL($varPhone) . ",";
						PrepSQL($varEmail) . ",";
		mysql_query($sql);

		//header("Location: thankyou.html");
		exit();



            
    // function: PrepSQL()
    // use stripslashes and mysql_real_escape_string PHP functions
    // to sanitize a string for use in an SQL query
    //
    // also puts single quotes around the string
    //
    function PrepSQL($value)
    {
        // Stripslashes
        if(get_magic_quotes_gpc()) 
        {
            $value = stripslashes($value);
        }

        // Quote
        $value = "'" . mysql_real_escape_string($value) . "'";

        return($value);
    }
   
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">

<head>
    <title>membership test</title>
</head>

<body>
<?php
	    if(!empty($errorMessage)) 
	    {
		    echo("<p>There was an error with your form:</p>\n");
		    echo("<ul>" . $errorMessage . "</ul>\n");
            }
        ?>
       
<form  action="form.php" method="post" name="ohta_membership_application" >
Name: <input type="text" name="formName" maxlenghth="45" value="<?=$varformName;?>" />
Address: <input type="text" name="address" maxlenghth="4" value="<?=$varAddress;?>" />
City: <input type="text" name="city" maxlenghth="4" value="<?=$varCity;?>" />
State: <input type="state" name="state" maxkength="2" value="<?=$varState;?>">
Zip: <input type="text" name="zip" maxlenghth="4" value="<?=$varZip;?>" />
Phone: <input type="text" name="phone" maxlenghth="4" value="<?=$varPhone;?>" />
Email: <input type="text" name="email" maxlenghth="4" value="<?=$varEmail;?>" />
<input type="submit" name="formSubmit"  value="Submit" />
<input type="reset" name="reset" value="Reset" >

</form>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.