PHP - Data Transfer From Earlier Page To Next Page Not Happening
Similar TutorialsHi: How do I transfer an ID to a 3rd page. Meaning: Events.php Code: [Select] ... <a href="eventDetails.php?calID=<?=$row['calID'];?>"><?=$row['calName'];?></a> ... Goes to eventDetails.php, and transfer/displays the calID properly: Code: [Select] <?php include('include/myConn.php'); include('include/myNav.php'); $calID = $_REQUEST['calID']; $query=mysql_query("select * from calTbl where calID = $calID") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $calName=$result['calName']; $calDesc=$result['calDesc']; $calDate=$result['calDate']; $calID=$result['calID']; } ?> ... <a href="?calID=<?php echo $calID; ?>" onclick="openSesame();" class="myBold">Print</a> ... However, when I click the "Print" link (I see it is properly writing the calID on the link - like eventDetailsPrint.php?calID=7. The "eventDetailsPrint.php" is written from a JavaScript file as a new window function), it is coming up blank. Code: [Select] <?php include('include/myConn.php'); //$calID = $_REQUEST['calID']; //$calID = $_SERVER['calID']; //$calID = echo $_GET['calID']; echo $_POST["calID"]; $query=mysql_query("select * from calTbl where calID = calID") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $calName=$result['calName']; $calDesc=$result['calDesc']; $calDate=$result['calDate']; $calID=$result['calID']; } ?> ... <?php echo $calID; ?> ... What is the trick to pass an ID from page to page to page? Thanks. Hi, I am new to Php and having problems with redirecting of page particularly sending variables across pages. I have this page1 which contains an if else statement. If { User types in two text fields code should be executed and the page should be resubmitted to the same page with database results. For this reason I am using the form attribute of the page and directing the action variable in the form attribute to page1 ( this page itself) on submit. Else { Now if user types in only one text field, it should go to another page wherein the another page should be able to receive the value entered by the user in the page1. I have got suggestions saying I can do this by using page header redirect to another page and concating the value of the textbox to the header variable. I am using this in page 1 <code> header("Location: Decryption.php?usersubmit=".urlencode($_POST($usersubmit))); </code> // Usersubmit is the value entered in the textbox field by the user. and in page 2 <code> $userId = $_GET['usersubmit']; </code> But of no use. I also tried creating a session variable here and using the session variable in the page2. But that does not work either. } Someone please help me. Let me know if you have any questions? Thanks, <!DOCTYPE html> <html> <head> <script> $(document).ready(function() { if($("#getPIN").click(function(){ <?php $char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ1234567890'; $generated_password = substr(str_shuffle($char), 0, 10); ?> var genNumber; $("#txtpin").val() = genNumber; return false; })); }); </script> </head> <body> <input type = "text" name = "txtpin" id = "txtpin" value = ""> <input type = "button" name = "getPIN" id = "getPIN" value = "getPIN"> </body> </html> Hey you guys need your help... Basically what im trying to do is when the user clicks the getPIN button, the value generated using php is assigned to the txtpin textfield without refreshing the page.... thanks alot guys.... Quesion: Show each movie in the database on its own page, and give the user links in a "page 1, Page 2, Page 3" - type navigation system. Hint: Use LIMIT to control which movie is on which page. I have provided 3 files: 1st: configure DB, 2nd: insert data, 3rd: my code for the question. I would appreciate the help. I am a noob by the way. First set up everything for DB: <?php //connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //create the main database if it doesn't already exist $query = 'CREATE DATABASE IF NOT EXISTS moviesite'; mysql_query($query, $db) or die(mysql_error($db)); //make sure our recently created database is the active one mysql_select_db('moviesite', $db) or die(mysql_error($db)); //create the movie table $query = 'CREATE TABLE movie ( movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, movie_name VARCHAR(255) NOT NULL, movie_type TINYINT NOT NULL DEFAULT 0, movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0, movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type, movie_year) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); //create the movietype table $query = 'CREATE TABLE movietype ( movietype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, movietype_label VARCHAR(100) NOT NULL, PRIMARY KEY (movietype_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create the people table $query = 'CREATE TABLE people ( people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, people_fullname VARCHAR(255) NOT NULL, people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (people_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Movie database successfully created!'; ?> ******************************************************************** *********************************************************************** second file to load info into DB: <?php // connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //make sure you're using the correct database mysql_select_db('moviesite', $db) or die(mysql_error($db)); // insert data into the movie table $query = 'INSERT INTO movie (movie_id, movie_name, movie_type, movie_year, movie_leadactor, movie_director) VALUES (1, "Bruce Almighty", 5, 2003, 1, 2), (2, "Office Space", 5, 1999, 5, 6), (3, "Grand Canyon", 2, 1991, 4, 3)'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the movietype table $query = 'INSERT INTO movietype (movietype_id, movietype_label) VALUES (1,"Sci Fi"), (2, "Drama"), (3, "Adventure"), (4, "War"), (5, "Comedy"), (6, "Horror"), (7, "Action"), (8, "Kids")'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the people table $query = 'INSERT INTO people (people_id, people_fullname, people_isactor, people_isdirector) VALUES (1, "Jim Carrey", 1, 0), (2, "Tom Shadyac", 0, 1), (3, "Lawrence Kasdan", 0, 1), (4, "Kevin Kline", 1, 0), (5, "Ron Livingston", 1, 0), (6, "Mike Judge", 0, 1)'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Data inserted successfully!'; ?> ************************************************************** **************************************************************** MY CODE FOR THE QUESTION: <?php $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('moviesite', $db) or die(mysql_error($db)); //get our starting point for the query from the URL if (isset($_GET['offset'])) { $offset = $_GET['offset']; } else { $offset = 0; } //get the movie $query = 'SELECT movie_name, movie_year FROM movie ORDER BY movie_name LIMIT ' . $offset . ' , 1'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); ?> <html> <head> <title><?php echo $row['movie_name']; ?></title> </head> <body> <table border = "1"> <tr> <th>Movie Name</th> <th>Year</th> </tr><tr> <td><?php echo $row['movie_name']; ?></td> <td><?php echo $row['movie_year']; ?></td> </tr> </table> <p> <a href="page.php?offset=0">Page 1</a>, <a href="page.php?offset=1">Page 2</a>, <a href="page.php?offset=2">Page 3</a> </p> </body> </html> I am trying to write a basic Private Messaging script.
I have my main page which lists all messages that have been received. I then want to click on an href link to run an ajax query to bring information in from another .php file which shows the content of the selected message.
But I can't fathom out how to do this with an href. First off, is it possible? If so, can anyone tell me what I am doing wrong?
The relevant script is:
privatemessage.php:
<?php $query2 = DB::getInstance()->query("SELECT c.id as cid, c.title, c.time, m.id as membersid, m.username, m.member_first_name, m.member_last_name FROM conversation as c, members as m WHERE ((c.member1='{$memberid}' and c.read1='Yes' and c.removed1='No' and m.id=c.member2) OR (c.member2='{$memberid}' and c.read2='Yes' and c.removed2='No' and m.id=c.member1)) GROUP BY m.id ORDER BY m.id DESC"); ?> <table> <tr> <td align="left"> <?php echo htmlentities($result2->member_first_name); ?> <?php echo htmlentities($result2->member_last_name); ?> <?php echo "("; echo htmlentities($result2->username); echo ")"; ?> </td> <td align="right"> <?php echo timeAgo(strtotime($result2->time)); ?> </td> </tr> <tr> <td colspan="2" align="left"> <form action="" method="post"> <?php echo "Subject: "; ?> <?php echo "<input type='hidden' name='id' id='id' value='{$result2->cid}'>"; ?> <a href="#$result2->cid" onClick="showMessages(this.value)"><?php echo htmlentities($result2->title); ?> </form> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="js/readmessage.js"></script> </td> </tr>My readmessage.js code is: function showMessages(str) { if (str=="") { document.getElementById("txtMessage").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtMessage").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","readmessage.php?q="+str,true); xmlhttp.send(); }And my readmessage.php code is: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $req1 = DB::getInstance()->query("SELECT title, member1, member2 FROM conversation WHERE id='{$q}' AND id2='1'"); foreach ($req1->results() as $dn1) if($req1->count()==1) { if(($dn1->member1=='{$memberid}') or ($dn->member2=='{$memberid}')) { if($dn1->member1=='{$memberid}') { DB::getInstance()->query("UPDATE conversation SET read1='Yes' where id='{$q}' and id2='1'"); $user_partic = 2; } else { DB::getInstance()->query("UPDATE conversation SET read2='Yes' where id='{$q}' and id2='1'"); $user_partic = "1"; } $req2 = DB::getInstance()->query("SELECT conversation.time, conversation.message, members.id as userid, members.username, members.member_first_name, members.member_last_name FROM conversation, members WHERE conversation.id='{$id}' AND members.id=conversation.member1 ORDER BY conversation.id2"); if(isset($_POST['message']) and $_POST['message']!='') { $message = $_POST['message']; if(get_magic_quotes_gpc()) { $message = stripslashes($message); } $message = $string(nl2br(htmlentities($message, ENT_QUOTES, 'UTF-8'))); if( DB::getInstance()->query("INSERT into conversation (id, id2, title, member1, member2, message, time, read1, read2) VALUES('{$q}', '{(intval($req2->id2)+1)}', '', '{$memberid}', '', '{$message}', '.time().', '', '')") and DB::getInstance()->query("UPDATE conversation SET read'{$user_partic}'='Yes' WHERE id='{$q}' AND id2='1'")); } echo "<h4>"; echo $dn1->title; echo "</h4><br><br>"; echo "<table><col width='150px'><col width='50px'><col width='150px'>"; echo "<tr><th>Member</th><th> </th><th>Message</th></tr>"; foreach ($req2->results() as $dn2) { echo "<tr><td>"; echo $dn2->members.member_first_name; echo $dn2->members.member_last_name; echo " ("; echo $dn2->members.username; echo ") </td><td></td><td>"; echo timeAgo(strtotime($dn2->time)); echo "<br>"; echo $dn2->message; echo "</td></tr>"; } echo "</table>"; } } } ?>However, just to try and find where the error lies, I have tried the following code for my readmessage.php file: <?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = intval($_GET['q']); echo $q; } ?>Which always returns a "0" reply - which says to me that my files are talking, but that the id isn't being carried across. Anybody got any suggestions? Many thanks for any help offered. Hi, I'm quite new to PHP and I'd like to know if there's a way for me to use some PHP solution to get data from another PHP file instead of used AJAX. My intention is to have some kind of a loop in one PHP file that'll have a variable that gets the returned data from a different PHP file on every iteration and does something with it. Would be simple enough to do it with Ajax but I can't use it in this instance. Any thoughts? I am having trouble transferring data from provideX ODBC to MySQL using Navicat. So, I am wanting to write a php script that will write all of the data to a text file, then do a MySQL "DATA LOAD INFILE". I am VERY limited as far as the SQL functions that are available to me with the ODBC connection. The table does not have a special unique identifier other than the item number. This table I am pulling from has a little over 100,000 items. How can I get php to process the full 100,000 rows. I thought about getting it to process 5,000 rows sorted by item #> break > pass the last item to the next page > then process the next batch of 5,000 sorted by item # where the item is greater than the item processed on the last page. ?? Jake I have not tested this code yet. I just kind of threw it together. Code: [Select] <?php set_time_limit(900); ini_set('max_execution_time', '999'); $myFile = "item_master.txt"; unlink($myFile); $fp = fopen("item_master.txt", "w"); require("..\inc/data.inc"); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT ITEM_NUM, DESCRIPTION_1, DESCRIPTION_2, ITEM_CLASS, ALPHA_SORT, STANDARD_PACK, GL_TABLE, PRIMARY_VND_NUM, VENDOR_ITEM_NUM, ACTIVE, ITEM_PRICE_CLS FROM ic_inventry_mast"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} while (odbc_fetch_row($rs)) { $ITEM_NUM=trim(odbc_result($rs,"ITEM_NUM")); $DESCRIPTION_1=trim(odbc_result($rs,"DESCRIPTION_1")); $DESCRIPTION_2=trim(odbc_result($rs,"DESCRIPTION_2")); $ITEM_CLASS=trim(odbc_result($rs,"ITEM_CLASS")); $ALPHA_SORT=trim(odbc_result($rs,"ALPHA_SORT")); $STANDARD_PACK=trim(odbc_result($rs,"STANDARD_PACK")); $GL_TABLE=trim(odbc_result($rs,"GL_TABLE")); $PRIMARY_VND_NUM=trim(odbc_result($rs,"PRIMARY_VND_NUM")); $VENDOR_ITEM_NUM=trim(odbc_result($rs,"VENDOR_ITEM_NUM")); $ACTIVE=trim(odbc_result($rs,"ACTIVE")); $ITEM_PRICE_CLS=trim(odbc_result($rs,"ITEM_PRICE_CLS")); $ITEM_NUM=str_replace('@','',$ITEM_NUM); $DESCRIPTION_1=str_replace('@','',$DESCRIPTION_1); $DESCRIPTION_2=str_replace('@','',$DESCRIPTION_2); $ITEM_CLASS=str_replace('@','',$ITEM_CLASS); $ALPHA_SORT=str_replace('@','',$ALPHA_SORT); $STANDARD_PACK=str_replace('@','',$STANDARD_PACK); $GL_TABLE=str_replace('@','',$GL_TABLE); $PRIMARY_VND_NUM=str_replace('@','',$PRIMARY_VND_NUM); $VENDOR_ITEM_NUM=str_replace('@','',$VENDOR_ITEM_NUM); $ACTIVE=str_replace('@','',$ACTIVE); $ITEM_PRICE_CLS=str_replace('@','',$ITEM_PRICE_CLS); $row="$ITEM_NUM@$DESCRIPTION_1@$DESCRIPTION_2@$ITEM_CLASS@$ALPHA_SORT@$STANDARD_PACK@$GL_TABLE@$PRIMARY_VND_NUM@$VENDOR_ITEM_NUM@$ACTIVE@$ITEM_PRICE_CLS\r\n"; fwrite($fp, $row); } fclose($fp); ?> Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? I have the following code Code: [Select] while($player = mysql_fetch_array($players)) { #Lets loop through all the players echo "<BR><input type=submit onclick=this.form.action='points.php?points=".$_GET['points']."&player=".$player['playerID']."&playerName=".$player['name']."' value='".$player['name']."'>"; }but the problem is that $player['name'] is always two words and it doesn't work. So I have removed '&playerName=".$player['name']."' but now don't know how to transfer that info. Is there a way of having the player name in the header or another way of sending this data to the next page? Another way of doing it is to check for the players name via there playerID number but this involves another call to the database which I am trying to avoid. Is it possible to write a php script that would extract data from an external web page. I've been working with php for a few years as a hobby, but I've never seen this done or needed a reason to until now. Thanks in advance for any responses. Hi there. I have a page(portfolio.php) that shows all the pictures from my db. Now what i want is: when i click on the picture to send me to a page(portfolio_single.php) where other datas are shown but those datas that are related to that picture. ex: when i click first picture it will open (portfolio_single.php) showing the infos of that picture, then when i click to the secon picture it will open same page with different datas (retreiving them from db). Anyone have any idea how to do that? here is my portfolio.php: Code: [Select] <?php require_once('Connections/ecommerce_dbcon.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_ecommerce_dbcon, $ecommerce_dbcon); $query_portofolioPicRec = "SELECT picture FROM `form` ORDER BY formid DESC"; $portofolioPicRec = mysql_query($query_portofolioPicRec, $ecommerce_dbcon) or die(mysql_error()); $row_portofolioPicRec = mysql_fetch_assoc($portofolioPicRec); $totalRows_portofolioPicRec = mysql_num_rows($portofolioPicRec); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Portfolio</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- Stylesheets --> <link rel="stylesheet" href="css/reset.css" /> <link rel="stylesheet" href="css/styles.css" /> <!-- Scripts --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <!--[if IE 6]> <script src="js/DD_belatedPNG_0.0.8a-min.js"></script> <script> /* EXAMPLE */ DD_belatedPNG.fix('.button'); /* string argument can be any CSS selector */ /* .png_bg example is unnecessary */ /* change it to what suits you! */ </script> <![endif]--> </head> <body class="portfolio"> <div id="wrapper" class="container_12 clearfix"> <!-- Admin Login --> <h1 id="login" class="grid_4"> <form id='login' action="checkAdminLogin.php" method='POST' accept-charset='UTF-8'> <fieldset > <legend class="meta">Admin Login</legend> <input type='hidden' name='submitted' id='submitted' value='1'/> <table> <tr><th> <label for='username'>Name:</label> </th> <td><input type='text' name='username' id='username' maxlength="50" /> </td></tr> <tr><th> <label for='password'>Password:</label></th> <td><input type='password' name='password' id='password' maxlength="50" /> </td> <th><input type='submit' name='Submit' value='Login' /> </th></tr> </table> </fieldset> </form> </h1> <!-- Navigation Menu --> <ul id="navigation" class="grid_8"> <li><a href="contact.php"><span class="meta">Get in touch</span><br />Contact Us</a></li> <li><a href="blog.php"><span class="meta">Latest news</span><br />Blog</a></li> <li><a href="portfolio.php" class="current"><span class="meta">Our latest work</span><br />Portfolio</a></li> <li><a href="about.php"><span class="meta">Who are we?</span><br />About</a></li> <li><a href="index.php"><span class="meta">Homepage</span><br />Home</a></li> </ul> <div class="hr grid_12 clearfix"> </div> <!-- Portfolio Items --> <!-- Section 1 --> <!-- Section 3 --> <div class="catagory_1 clearfix"> <!-- Row 1 --> <div class="grid_3 textright" > <span class="meta">Our Latest and Greatest Work</span> <h4 class="title ">Portfolio</h4> <div class="hr clearfix dotted"> </div> <p>Here you can see all the cars that exist in our database. You can navigate through all of them.</p> </div> <div class="grid_9"> <table > <tr> <?php $portofolioPicRec_endRow = 0; $portofolioPicRec_columns = 3; // number of columns $portofolioPicRec_hloopRow1 = 0; // first row flag do { if($portofolioPicRec_endRow == 0 && $portofolioPicRec_hloopRow1++ != 0) echo "<tr>"; ?> <td><a class="portfolio_item float alpha" href="portfolio_single.php"> <span>Read More</span> <img class="" src="adminform_images/<?php echo $row_portofolioPicRec['picture']; ?>" alt=""/></a></td> <?php $portofolioPicRec_endRow++; if($portofolioPicRec_endRow >= $portofolioPicRec_columns) { ?> </tr> <?php $portofolioPicRec_endRow = 0; } } while ($row_portofolioPicRec = mysql_fetch_assoc($portofolioPicRec)); if($portofolioPicRec_endRow != 0) { while ($portofolioPicRec_endRow < $portofolioPicRec_columns) { echo("<td> </td>"); $portofolioPicRec_endRow++; } echo("</tr>"); }?> </table> </div> </div> <div class="hr grid_12 clearfix"> </div> <!-- Footer --> <p class="grid_12 footer clearfix"> <span class="float"><b> EpokaUniversity || All Rights Reserved © Copyright</b> || HarisKrasniqi, DiamantNeziri, HarisMemeti, KelmendTairi.</span> <a class="float right button" href="#">top</a> </p> </div><!--end wrapper--> </body> </html> <?php mysql_free_result($portofolioPicRec); ?> portofolio_single.php: suppose it is a table that contains the: name: (it will echo out the name of the picture depending on which picture u click) date: path: etc of the photo I'm using PHP and MySQL to display images on the first page.
When the image is clicked on I'm passing an ID to a new page.
I want that ID to display the ID data that's associated with that ID.
For example:
ID 1 should display - Title - title1, Details - details1, image - image1
and ID 2
ID 1 should dislay - Title - title2, Details - details2, image - image2
But only displaying ID 1 data not matter if the URL is - website.com/thedetials.php?id=1 or website.com/thedetials.php?id=2
In other words, it displays the same data even though the id in the URL is different.
Page 1
$sql="SELECT * FROM thetable"; $result = mysqli_query($con,$sql); echo " <ul>"; while($row = mysqli_fetch_array($result) { echo "<li'>"; echo "<a href='page2.php?id=$row[id]'><img src=$row[image]></a>"; echo "</li>"; } echo "</ul>"; ?> <?php // End while loop. mysqli_close($con); ?>Page 2 $id = $_GET['id']; $sql="SELECT id, title, details, image, FROM thetable"; $result = mysqli_query($con,$sql); $row = mysqli_fetch_array($result); ?> <?php echo $row['title'] ?> <?php echo $row['details'] ?> <img class='projectItem-pic' src="<?php echo $row['image']?>">If I use below - No data displays, not sure why. $sql="SELECT * FROM thetable WHERE id = $id";Can someone tell me what I'm doing wrong? Edited by patmon, 08 June 2014 - 09:22 PM. I must be mixing apples and oranges here or something trying to get two columns/fields of MySQL data to display.
The basic HTML page display OK and there are no MySQL Connection errors (finally resolved those).
<HTML snipped> <?php require '...<URL snipped>...'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT `name`, `id` FROM `roster`"; $result = mysqli_query($con,$sql); $num=mysqli_num_rows($result); mysqli_close($con); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td> <font face="Arial, Helvetica, sans-serif">NAME</font> </td> <td> <font face="Arial, Helvetica, sans-serif">ID</font> </td> </tr> <?php function mysqli_result($res, $row, $field=0) { $res->data_seek($row); $datarow = $res->fetch_array(); return $datarow[$field]; } $i=0; while ($i < $num) { $f1=mysqli_result($result,$i,$datarow[$field]); $f2=mysqli_result($result,$i,$datarow[$field]); ?> <tr> <td> <font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font> </td> <td> <font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font> </td> </tr> <?php $i++; } ?> </table> <?php ?> <HTML snipped>Any assistance is appreciated. Thanks very much. - FreakingOUT I'm trying to loop "Question" as a list of links (link is #id_number), and then later on the page loop "Question" and "Answer", anchored by the id_number tag. It's looping "Question" just fine, but how do I then loop the same data again later in the same page? Code: [Select] <?php $username="username"; $password="password"; $database="database_name"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM ft_form_17 WHERE Include='Include'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> Header Goes here<br /><br /><br /> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"question"); //Question $f2=mysql_result($result,$i,"answer"); //Answer $f3=mysql_result($result,$i,"submission_id"); //id number ?> <a href="#<?php echo $f3; ?>"><?php echo $f1; ?></a><br /> <?php $i++; } ?> <br /><br /><br /> <strong><a name="<?php echo $f3; ?>"><?php echo $f1; ?></a></strong> <?php echo $f2; ?> I'm new to PHP and I have an html page I would like to pull specific data into certain areas on the page that I will modified for php. Here are some details. The page is a static html page that has the prices of 40+ products in a standard <li> list. When I update the prices in our database through our shopping cart, I have to change these prices manually in the html. https://www.novon.co...mic_mixers.html. It would be great if I could link the field for Base_Price in the products table to each affiliated <li> tag, I am pulling all the data I need into ($results) and can display it all but I don't know how to get just the single products Base_Price in my <li> tag. <?=$row['Base_Price'] ?> I know this code is not correct but to get the point across, can I create a variable that I define in each <li> tag with a statement like,,,, <?=$row['Base_Price with Product_Code=123456'] ?> I could create a new SQL query for each <li> like "SELECT Base_Price from Products WHERE Product_Code='123456' ", but that's a lot of calls to the DB and a lot of code on the page. And just so I weed out the hard core coders, I can not rebuild the entire page. This is too big of a project for me and my limited coding with PHP. Can anyone help?? Thanks in advance Michael I have been playing around with this. Thought I had it nailed, and then found that It was fubar when I started to add more entries to the database. I basically want to display 2 tables from my database on the page. One is called "players" the other is called "editlog". The output with my current script came out as this: and here is the dreaded code: <html> <body> <u><h3>Performance Point Monitor (PPM): Knights of Shadow WoW Officers.</h3></u> <?php include('/home/a3269923/public_html/ppm/admin/config.php'); include('/home/a3269923/public_html/ppm/admin/dbopen.php'); $query="SELECT * FROM players"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <table border="1" style="position:absolute;width:500;height:10;left:0;top:70"> <tr> <th><font face="Arial, Helvetica, sans-serif">PLAYER</font></th> <th><font face="Arial, Helvetica, sans-serif">POINTS</font></th> <th><font face="Arial, Helvetica, sans-serif">DATE</font></th> </tr> <?php $i=0; while ($i < $num) { $f2=mysql_result($result,$i,"PLAYER_NAME"); $f3=mysql_result($result,$i,"ND_POINTS"); $f4=mysql_result($result,$i,"DATE ADDED"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> </tr> </table> <?php $i++; } ?> <?php include('/home/a3269923/public_html/ppm/admin/config.php'); include('/home/a3269923/public_html/ppm/admin/dbopen.php'); //USER LOG $query="SELECT * FROM editlog"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <table border="1" style="position:absolute;width:600;height:10;left:510;top:70"> <tr> <th><font face="Arial, Helvetica, sans-serif">USER</font></th> <th><font face="Arial, Helvetica, sans-serif">TYPE</font></th> <th><font face="Arial, Helvetica, sans-serif">POINTS</font></th> <th><font face="Arial, Helvetica, sans-serif">NOTES</font></th> <th><font face="Arial, Helvetica, sans-serif">DATE</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"USER"); $f2=mysql_result($result,$i,"TYPE"); $f3=mysql_result($result,$i,"POINTS"); $f4=mysql_result($result,$i,"NOTE"); $f5=mysql_result($result,$i,"TIMESTAMP"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr> </table> <?php $i++; } ?> What am I doing wrong? Halp! index.php?page=1 that link style but there is not hard files it is all to be stored in the DB here is what i have got so far Code: [Select] <? $result = mysql_query("SELECT * FROM page") or die(mysql_error()); $row = mysql_fetch_array( $result ); if(isset($_GET['page'])) { echo $row['text']; } else { $result = mysql_query("SELECT * FROM page WHERE id='1'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo $row['text']; } ?> but always shows page ID 1 (home page) so i no i am missing something just not sure what hehe DB structu Code: [Select] menu ----id (auto increase) ----name (home, about etc) ----id2 (page weight) pages ----id (auto increase) ----name (page name home, about etc) ----text (page text) link structure from the menu Code: [Select] <? $result = mysql_query("SELECT * FROM menu ORDER BY id2") or die(mysql_error()); ?> <table> <? while($row = mysql_fetch_array( $result )) { ?> <tr><td> <a href="index.php?page=<? echo $row['id'];?>"><? echo $row['name']; ?></a> </td></tr> <? } ?> </table> dont think i have missed any info that i have on file but not sure why it will not link so thought of you guys hehe Thanx in advance I'm getting data from a remote XML file using the following as a result of a form: Code: [Select] <?php header('Content-type: text/xml'); //extract data from the post extract($_POST); //set POST variables $url = 'https://www.*******'; $fields = array( 'ESERIES_FORM_ID'=>urlencode($ESERIES_FORM_ID), 'MXIN_USERNAME'=>urlencode($MXIN_USERNAME), 'MXIN_PASSWORD'=>urlencode($MXIN_PASSWORD), 'MXIN_VRM'=>urlencode($MXIN_VRM), 'MXIN_TRANSACTIONTYPE'=>urlencode($MXIN_TRANSACTIONTYPE), 'MXIN_PAYMENTCOLLECTIONTYPE'=>urlencode($MXIN_PAYMENTCOLLECTIONTYPE), 'MXIN_CAPCODE'=>urlencode($MXIN_CAPCODE) ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); ?> Which is displaying what was the remote XML page, but has brought it to my domain. How would I go about taking the results of the displaying XML page and displaying them on the next page rather than just displaying the XML data? Many thanks in advanced! Hello, I've been hacking at this for about 5 hours, and have been unable to get my session data to pass through to the 3rd page. Here is my code. As you can see I've been trying all types of variation of retrieval. On page 2 I can pull the data from page 1 fine with REQUEST or the longer version.. But for some reason page 3 will not display the first_name and last_name... I'm desperate at this point. I have not been able to find a working answer. I'm running php 5 w/ trans... OFF (default) in .ini. Page 1 Code: [Select] <?php session_start(); ?> <?php $PHPSESSID = session_id(); echo "<strong>Session ID:</strong> $PHPSESSID"; "<br /><br />"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>0</title> </head> <body> <form method="post" action="multi_page_post_2.php"> <label>First Name</label> <input name="first_name" value="" width="50" type="text" /> <br /><br /> <label>Last Name</label> <input name="last_name" value="" width="50" type="text" /> <br /><br /> <input type="submit" name="submit" value="Enter your Data - Continue to Step 2 >>" /> </form> </body> </html> Page 2 Code: [Select] <?php session_start(); ?> <?php $PHPSESSID = session_id(); echo "<strong>Session ID:</strong> $PHPSESSID"; $first_name = $_REQUEST['first_name']; echo $first_name; ?> <?php echo "<br /><br />"; print_r($_SESSION); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Step 2</title> </head> <body> <h2>Step 2 - Is this data correct?</h2> <hr /> <strong>First Name:</strong> <?php echo $_SESSION['first_name'] = $_POST['first_name']; ?> <br /><br /> <strong>Last Name:</strong> <?php echo $_SESSION['last_name'] = $_POST['last_name']; ?> <br /><br /> <form method="post" action="multi_page_post_3.php"> <label>Sons First Name: </label> <input name="sons_first_name" value="" width="50" type="text" /> <br /><br /> <input type="submit" name="submit" value="YES! Continue to Step 3 >>" /> <input type="hidden" name="PHPSESSID" value="<?php echo $PHPSESSID ?>" /> <input type="button" value="No! Back to Previous Page" onClick="javascript: history.go(-1)"> </form> <br /><br /> <a href="" onclick="<?php session_destroy(); ?>">Session D E S T R O Y !</a> </body> </html> Page 3 Code: [Select] <?php session_start(); ?> <?php $PHPSESSID = session_id(); echo "<strong>Session ID:</strong> $PHPSESSID"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Step 3</title> </head> <body> <h2>Step 3 - Is this data correct?</h2> <hr /> <strong>First Name:</strong> <?php echo $_SESSION['first_name'] = $_REQUEST['first_name']; ?> <br /><br /> <strong>Last Name:</strong> <?php echo $_SESSION['last_name']; ?> <br /><br /> <strong>Sons First Name:</strong> <?php echo $_REQUEST['sons_first_name']; ?> <br /><br /> <form method="post" action="multi_page_post_4.php"> <input type="hidden" name="PHPSESSID" value="<?php echo $PHPSESSID ?>" /> </form> <br /><br /> <a href="" onclick="<?php session_destroy(); ?>">Session D E S T R O Y !</a> </body> </html> |