popcop Posted February 6, 2013 Share Posted February 6, 2013 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."')"; Quote Link to comment https://forums.phpfreaks.com/topic/274101-problem-pulling-from-the-datbase-and-displaying-on-webpage/ Share on other sites More sharing options...
gristoi Posted February 6, 2013 Share Posted February 6, 2013 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?? Quote Link to comment https://forums.phpfreaks.com/topic/274101-problem-pulling-from-the-datbase-and-displaying-on-webpage/#findComment-1410426 Share on other sites More sharing options...
popcop Posted February 6, 2013 Author Share Posted February 6, 2013 thats the code that pulling the data from the database Quote Link to comment https://forums.phpfreaks.com/topic/274101-problem-pulling-from-the-datbase-and-displaying-on-webpage/#findComment-1410432 Share on other sites More sharing options...
popcop Posted February 6, 2013 Author Share Posted February 6, 2013 (edited) 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(); } ?> Edited February 6, 2013 by popcop Quote Link to comment https://forums.phpfreaks.com/topic/274101-problem-pulling-from-the-datbase-and-displaying-on-webpage/#findComment-1410442 Share on other sites More sharing options...
P5system Posted February 8, 2013 Share Posted February 8, 2013 Print the query and run it in phpmyadmin interface. U will come to know i guess some syntax issue is there Quote Link to comment https://forums.phpfreaks.com/topic/274101-problem-pulling-from-the-datbase-and-displaying-on-webpage/#findComment-1410947 Share on other sites More sharing options...
Jessica Posted February 8, 2013 Share Posted February 8, 2013 You need to check for errors. rand is a reserved keyword. Quote Link to comment https://forums.phpfreaks.com/topic/274101-problem-pulling-from-the-datbase-and-displaying-on-webpage/#findComment-1410948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.