SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Threaded View

  1. #1
    SitePoint Guru etidd's Avatar
    Join Date
    May 2011
    Location
    atlanta, ga
    Posts
    632
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question Connecting to the MySQL Database

    Hello all,

    So, I've successfully set up the columns and added the first few rows of test data into my database using phpMyAdmin on my web host. Now, the next step is to have the PHP properly set up to connect to the database. I've used the mysql_connect() and mysql_close() at the beginning and the end with the login credentials needed for my database entry- now, which method do I use to specify the table name? I see a pg_connect() for Postgre SQL (whatever that is). Then I need to know what PHP function do I use to write an SQL query inside of.

    Again, this is for my page at World Review Group.

    Code PHP:
    Code:
    <?php
    	  /*This is the scripting section for the e-mail collection box.*/
    	$email = " ";
    	$connection = mysql_connect("worldreviewgroupcom.fatcowmysql.com" , "username" , "password");
    	$dbconn = pg_connect("dbname=emailcollection");
    	if (!$connection){
    		die('Could not connect: ' . mysql_error());
       }
    	
    	function showWindowAndValidate()
    	{
    		echo'<div id="activeemailbox"><input type="checkbox" value="Yes, I would like to join the mailing list."><p>Enter the characters you see below.</p></div>' . generateRandom() . ;	
    	}
    	
    	if (isset($_POST["go"]){
    		$email = $_POST["go"];
    		if (isItAValidEmail($email)){
    			showWindowAndValidate();
    			//call a function to write the user to database
    		} else {
    			invalidEntry();
    	} else {
    		invalidEntry();
    		}
    	
    	/*test the e-mail address submission for valid entry */
    	function Boolean isItAValidEmail($email){
    		if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    		  return false;
    		} else {
    		  return true;
    		}
    	}
    	
    	function invalidEntry()
    	{
    		return echo'<div id="activeemailbox"><p id="error">You didn\'t enter a valid email, silly!</p><input type="submit" value="Go Back" 		  onclick="goBack()"></div>';
    	}
    	
    	function generateRandom()
    	{
    	
    	}
    	
    	function goBack()
    	{
    		header();
    	}
    	
    	mysql_close($connection);
    	
    	//end e-mail box scripting section
    ?>
    Thank you very much for your guidance. It keeps me going.
    Last edited by TechnoBear; Jan 7, 2013 at 13:32. Reason: Username and password removed


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •