www.webdeveloper.com
Results 1 to 2 of 2

Thread: Problem pulling from the datbase and displaying on webpage

  1. #1
    Join Date
    May 2004
    Posts
    288

    Problem pulling from the datbase and displaying on webpage

    i created a webpage with a form which submits data to a database and also sends a URL to an email address with random ID at the end which will link to specific data from the database when viewed in a browser

    when i try and pull the data nothing seems to display, heres my code:

    PHP Code:
    <?php

    // since the id is being passed in the url, you will need to declare it using the get method
    $rand $_GET['rand'];
    $action $_GET['action'];


    // if an id was sent to the script, then execute it
    if ($rand)
    {
    // connection vars
    $host "localhost";
    $user "****";
    $password "****";
    $dbname "****";
    $tablename "cards";

    // connect to and select the database
    @mysql_connect($host,$user,$password) or die("&success=no&");
    @
    mysql_select_db($dbname) or die("&success=no&");

    // query the database and return an array of data
    $result = @mysql_query("SELECT * FROM $tablename WHERE rand = $rand") or die("&success=no&");




    // break the array down into the parts you need
    while($row mysql_fetch_array($result)){

    $youremail urlencode($row['youremail']);
    $name urlencode($row['name']);
        
    $receiveremail urlencode($row['receiveremail']);
        
    $message $row['message'];


    $message str_replace('\n''\r'$message);
    $message str_replace('\r\n''\r'$message);
    $message str_replace('<br>''\r'$message);
    $message str_replace('%0D%0A''\r'$message);


    }
    // if there was a result echo the stuff below
    if($result)
    {


    echo 
    "my name is "$name" my email address is ",$youremail," " ?>


    <?php
    exit();
    }
    mysql_close();
    }
    ?>

    This is how im adding to the databse

    PHP Code:
    // insert your data here with $rand as the id
    $youremail mysql_real_escape_string($_POST['youremail']);
    $name mysql_real_escape_string($_POST['name']);
    $receiveremail mysql_real_escape_string($_POST['receiveremail']);
     
    $message mysql_real_escape_string($_POST['message']);

     
    $query="INSERT INTO $tablename (rand, youremail, name, receiveremail, message) 
     VALUES ('"
    .$rand."', '".$youremail."', '".$name."', '".$receiveremail."',   '".$message."')"

  2. #2
    Join Date
    Dec 2009
    Posts
    35
    Are you getting any error in your Apache's log file? (if you are using Apache as web server, of course.. ). If you dont have an specified file for it written in your virtual host, it should be in /var/log/apache2/error.log if your are under Linux.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles