Jump to content

Problem pulling from the datbase and displaying on webpage


popcop

Recommended Posts

i created a webpage with a form which submits data to a datbase 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
// 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

 

// 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."')"; 

i created a webpage with a form which submits data to a datbase 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
// 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

 

// 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."')";

 

where is the mysql to actually execute the query??

ive updated my code to this now and still nothing is displaying....

 

<?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";

$mysql = new mysqli('$host, $user, $password');
$result = $mysql->query('SELECT * FROM $tablename WHERE rand = $rand');
while (($row = $result->fetch_assoc()) !== null) {
print_r($row);


$youremail = urlencode($row['youremail']);
$name = urlencode($row['name']);
$receiveremail = urlencode($row['receiveremail']);
$message = $row['message'];
// replace non flash line breaks with the flash \r newline
$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)
{
// if we have a result we can show the movie and pass the vars along in the strings
// a set back with this is that you can only pass so much data in the string, think its like 256 characters, but Im not sure.
echo "Hello, $name <br />";
echo "$message";
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.