/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=php]<?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(‘rn’, ‘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();
}
?>[/code]

[B]This is how im adding to the databse[/B]

[code=php]// 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.”‘)”;[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@tirengarfioFeb 07.2013 — 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.
×

Success!

Help @popcop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...