PHP - Displaying Data Using Href By $_get['id'];
After several attempts, I now have data displayed on my index.php page, but the data is from all rows. Luckily I have two rows. The page also has a menu - with two links. What I would like help with is: How to display index.php with just the data for it - i.e. home page data. How to display data if either the ‘home’ or ‘copyright’ links are clicked. I understand you can use $_GET[‘id’], and isset(), but I don’t know how to do that. I include the full html page code: <?php // database connection require_once('admin/databasecon.php'); ?> <!DOCTYPE html> <html> <?php include 'includes/headsection.php'; ?> <body> <?php // displaying data $table = "pages"; // table $sqli = "SELECT * FROM $table ORDER BY id ASC"; $result = $conn->query($sqli); ?> <!-- topMenu --> <table id="topMenu"> <tr> <td><h1 class="siteName">Scarab Beetle</h1></td> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<td class='navItem'>" . "<a href=index.php>" . $row["menuheader"] . "</a>" . "</td>"; } } ?> </tr> </table> <!-- topMenu end --> <!-- timeline menu --> Menu goes here <!-- timeline menu end --> <!-- page title --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<h1 class='centered'>" . $row["pageheader"] . "</h1>"; } } ?> <hr> <!-- page content --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo $row["pagetext"]; } } ?> <hr> <div class="clear"></div> <!-- footer content --> <?php include 'includes/footersection.php'; ?> <!-- footer content end --> </body> </html> Any help to achieve what I want will be appreciated. Thank you. Similar TutorialsI'm trying to add voucher codes to my shopping basket. When someone submits a voucher code it adds ?vouchercode=WHATEVERTHECODE to the URL. I then $_GET this data and store is as $_SESSION['vouchercode']. The problem is, on the next page it $_GET's the ?vouchercode again, which is this time blank, and sets the session to blank as well. Any help? Here's my code: Code: [Select] $vouchercode = $_GET['vouchercode']; $_SESSION['vouchercode'] = $vouchercode; if ($rows['brand'] == 'Dank' AND $_SESSION['vouchercode'] == 'DANKINT') { echo 'Voucher Code DANKINT Used'; } I recently had a customer say that one of my forms isn't working. For some reason the ID number is getting lost when she submits the form. The form code looks like: ... print "<form method='post' name='form' action='update.php'>"; ... print "<input type='hidden' name='id' value=\"$id\" />"; print "<input type='submit' name='submit' value=\"Save Session\" />"; print "</form>"; ... And the PHP code that gets executed looks like: ... //GET SESSION ID if(isset($_GET['id'])) { //ID from HTML link, before updates have been made $id = $_GET['id']; } elseif(isset($_POST['id'])) { //ID from form, after updates have been made $id = $_POST['id']; } else { $id = ''; } //IF SESSION ID IS VALID if(preg_match("/^\d+$/", $id)) { ... //ELSE, INVALID ID } else { $msg = "<span class='errorText'>Session ID not found or invalid.</span>"; } ... For some reason she usually gets the "Session ID not found..." error when submitting the form. Do you see any problems with the above code? Note that she has been able to sucessfully use the form before (in the same day); we have nearly 1,800 records submitted using these forms; and I am unable to duplicate the issue. So I'm at a loss on what to do next. Also, she talked with her IT person about the form. The IT person was able to submit data on his computer. So he reset her Internet options which seemed to fix the problem on her end temporarily. Note that she is using IE 7. She also said that she doesn't have access to any other browsers. I'm tempted to chalk this up as a personal computer issue, but wanted to get your input first. Hi, I am a curious fellow just beginning to use PHP. I understand the basics of what the $_GET and $_POST superglobals do, and how we can use them to retrieve data after form submission. I also know that since $_GET and $_POST are just associate arrays, we can create our own values in both $_GET and $_POST by writing statements like $_POST['variable'] = "value". I am wondering if it is at all possible to send data beyond form data by adding new key/value pairs into $_GET and $_POST. So for example, if I had a form that transferred username/password through Post, would it be possible for me to include further data by just saying $_POST['formtype'] = "house_insurance_form"? Basically what I'm getting at is trying to physically add your own data to $_POST or $_GET that you could pull from the next page where the form redirects to. In other words, can I send data beyond form data using these superglobals? I know I can do this with $_SESSION, but could I do it through $_POST or $_GET? I haven't been able to accomplish this, and I was just wondering if someone could give me an in-depth explanation of how this might work or how this is not possible. I would really really really appreciate it. Best Regards, -Sky Hi, Firstly, I am a complete newcomer to PHP though I am enjoying my first tentative steps into learning the language! I have been searching Google for hours now to try and find a simple solution to a problem I just can't seem to figure out, though I thought would be easy to find? I have found a lot of very informative solutions to other questions on this forum so figured it was the best one to join? My question is: I have built and can interact with a simple database and now populate a page with usernames in a list. Each one is a link which, when clicked sends the username to another page. On this page I use the $_GET function and see the username displayed ok. What I can't figure out is how to then display other information about them from the fields in the database identified with that user? Any help would be greatly appreciated as this is driving me nuts! Also can anyone suggest a good book for learning PHP? There are lots out there but the reviews on Amazon seem to always talk about coding errors in print etc. so I really don't know which one to buy? FF Hi all, I find myself in need again on PHP coding and the support last time was outstanding (no creeping here) so I am trying my luck again! I am trying to use a HREF link (lots of individual ones) to search a Mysql database and return the results in a PHP page. Example of HREF links on the page are he https://flighteducation.co.uk/Create.html and in theory you click a career and it 'gets' and 'shows' the data from the database he https://flighteducation.co.uk/Careers.php so, you click the 'Animator' link ->it goes to my database and drags back all the data to the Careers.php page
So far this is what I have managed to not get right: HTML (screen shot added/attached Links.png)
<a href="Careers Results.php?jobTitle=Animator"> PHP
$id = $_GET['jobTitle']; if( (int)$id == $id && (int)$id > 0 ) { $link = mysqli_connect('localhost','MYUSERNAME','MYPASSWORD','MYDATABASE'); // Connect to Database if (!$link) { die('Could not connect: ' . mysqli_connect_error()); } $sql='SELECT * FROM careers WHERE jobTitle=' .$id; $result = mysqli_query($link,$sql); $row = mysqli_fetch_array($result); echo $row['jobTitle']; echo $row['jobDescription']; } else { echo "Record NOT FOUND"; } Up to now the code returns "Record NOT FOUND" so it is passing through the php to the end. I am new to PHP and trying to get my head around it all, and in theory this is the kind php code that I should be looking at, but I am still very new to it!! Any help or advice very much appreciated again!!!
Thanks
Hi people, I've been having trouble with this for a while now. Basically, i have this website: http://el07jpg.info . You can log in with username:doctor1 password:password1 Once you've logged on, u can click on "Patients". Then, if you click on a patient, it shows their info. Then at the bottom, I have links to glucose readings and heart rate readings... but when I click on either of those links, it goes back to the main page, showing all the patients.. The weird thing is that I got this to work for the first step, u click on the <a href> link of a patient, and it brings you to their page. Then I've done the EXACT same thing to link to the glucose or heart rate readings of that specific patient, but it doesn't work. I really can't see what i've done wrong. Although I noticed in the address bar, when I click on glucose readings for example, the url is http://el07jpg.info/index.php?op=patients&id=&reading=glucose (id should be equal to a number, like id=4, but there's no number... Any help would be much appreciated! Cheers! Code for op_patients.php page: <?php //Page if a set of records is selected from a single patient's page if ($_REQUEST[reading]+0) { $GLOBALS['html']['css'][]="default.css"; $reading_source=$_REQUEST[reading]+0; $sql="select * from {$reading_source}_readings where patientRFID='{$patient[patientRFID]}' "; $results=mysql_select_assoc($sql); if (!$results){ $GLOBALS[err][]="No records exist!"; exit; } $GLOBALS['html']['title']="Patient: {$patient[first_name]} {$patient[last_name]}'s {$reading_source} readings "; echo $reading_source; } //Page if a single patient is selected if ($_REQUEST[id]+0) { $GLOBALS['html']['css'][]="default.css"; $id=$_REQUEST[id]+0; $sql="select * from patients where doctorID='{$_SESSION[user][id]}' and patientID='$id' "; $patient=mysql_select_assoc($sql); if (!$patient){ $GLOBALS[err][]="The patient can't be found!"; exit; } $GLOBALS['html']['title']="Patient: {$patient[last_name]}, {$patient[first_name]} "; $output.=" <br> <table border='1' cellpadding='5' cellspacing='5' width='600'> <tr><td rowspan=6><img src=\"$patient[photo]\"> </td> <th>Name: </th><td>{$patient[first_name]} {$patient[last_name]} </td></tr> <tr><th>D.O.B: </th><td>{$patient[dob]} </td></tr> <tr><th>Email: </th><td>{$patient[email]} </td></tr> <tr><th>Phone Number: </th><td>{$patient[phone_no]}</td></tr> <tr><th>Address: </th><td>{$patient[address]}</td></tr> <tr><th><br> Comments:<br> </th> <td>{$patient[comments]} </td></tr> </table> <table border='1' cellpadding='5' cellspacing='5' width='600'> <tr><th colspan=3><br>Medical Readings<br><br></th></tr> <tr> <td align='center' width='300'> <a href='index.php?op=patients&id={$v[patientID]}&reading=glucose'>Glucose Readings</a> </td> <td colspan=2 align='center' width='300'> <a href='index.php?op=patients&id={$v[patientID]}&reading=heart'>Heart Rate Readings</a> </td> </tr> </table> "; echo $output; exit; } //Main Page showing all patients $GLOBALS['html']['title']="Patients"; $GLOBALS['html']['css'][]="default.css"; if(!$_SESSION[user][id]) { $er="Access Denied! Please Log in."; echo "<div style='color:red;'>$er</div>"; } else { $sql="select * from patients where doctorID='{$_SESSION[user][id]}' order by last_name"; $d=mysql_getarray_assoc($sql); $output=''; foreach ($d as $v){ $output.=" <tr><td> <a href='index.php?op=patients&id={$v[patientID]}'>{$v[last_name]}, {$v[first_name]}</a> </td></tr> "; } echo " <table width=80% align=left border='1' cellpadding='5' cellspacing='5' width='100%'> <tr><th class=popupheader align='left'> Patient Name<br><br> </th></tr> $output </table> "; } ?> A few months ago, and a good amount of time before that, I had people telling me to use isset() instead of performing to see if the variable is empty, such as: !$_GET[''] I know the differences in the function and what they do, but when could isset() be used in a situation where it's better/more efficient then: !$_GET[''] I do use isset(), though. Hello im working on a project which involves marking attendance via an RFID tag and saving the time into an sql file. Everything seems to be working fine and the time stamp is successfully punched into the SQL but something is wrong with the php code thats supposed to display this data. Please if any one can take a look and help.
MY CODE for displaying the data (ViewAttendance.php): <?php include_once("header.php"); $attData = array(); $totDays = 0; if(isset($_REQUEST['submit'])){ $totDays = cal_days_in_month(CAL_GREGORIAN,$_REQUEST['month'],$_REQUEST['year']); $attData = $commonObj->getAttendanceData($_REQUEST['month'],$_REQUEST['year']); //print_r($attData); //print_r(date("d",strtotime($attData[0]['punch_time']))); } ?> <div class="container"> <div class="row"> <div class="col-sm-12"> <h4>Showing Attendance</h4> <form name="showAtt" method="post"> <div class="col-sm-4"><label>Select Month</label> <select name="month" class="form-control"> <?php for($i=1;$i<=12;$i++){?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?> </select> </div> <div class="col-sm-4"><label>Select Year</label> <select name="year" class="form-control"> <?php for($i=date("Y");$i>=2010;$i--){?> <option value="<?php echo $i;?>"><?php echo $i;?></option> <?php }?> </select> </div> <div class="col-sm-4"> <p> </p> <input type="submit" value="Show" name="submit" class="btn btn-primary"> </div> </form> </div> </div> <div class="row"> <div class="col-sm-2"> <label class="btn btn-success btn-sm">Month:<?php echo @$_REQUEST['month'];?></label> </div> <div class="col-sm-2"><label class="btn btn-info btn-sm">Year: <?php echo @$_REQUEST['year'];?></label></div> </div> <div class="row"> <div class="col-sm-12" style="overflow: scroll;"> <?php if($totDays>0){?> <table class="table table-striped"> <tr> <th> Employee Name </th> <?php for($i=1;$i<=$totDays;$i++){?> <th> <?php echo $i;?> </th> <?php }?> <?php foreach($attData as $attk=>$attv){ $punchin = $commonObj->getTimeOfDate($attData[$attk]['punchin']); $punchout = $commonObj->getTimeOfDate($attData[$attk]['punchout']); ?> <tr> <th class="danger"> <?php echo $attv['name'];?> </th> <?php for($i=1;$i<=$totDays;$i++){?> <?php if($commonObj->getDayOfDate($attData[$attk]['punch_time']) == $i){ echo "<td class='success' id='att_$i'>".$punchin.'-'.$punchout;?> <table class="table table-responsive"style="display: none; position:relative;min-width:100px;max-width:200px; margin-top: -40px;" id="<?php echo "det_att_".$i;?>"> <tr> <td>Total hours:</td> <td><?php echo $commonObj->getHoursBetweenDates($attData[$attk]['punchin'],$attData[$attk]['punchout']);?> </td></tr> <tr> <td>UID:</td> <td><?php echo $attData[$attk]['rfid_uid'];?></td> </tr> </table> <?php }else {echo "<td class='info'>#na";}?> </td> <?php }?> </tr> <?php }?> </tr> </table> <?php }?> </div> </div> </div> </body> </html> <script> $(document).ready(function(){ $("td").hover( function () { var id = "#det_"+this.id; $(id).css({"display":"block"}); }, function () { var id = "#det_"+this.id; $(id).css({"display":"none"}); //console.log(id); //$(id).css("display","block"); }); }); </script> Display of (ViewAttendance.php):
MY SQL TABLE :
I have a some value that are being generated from a database then thrown into <li><href> to create a list that user can click and fetch data through ajax right now its in a form select/menu and works fine however I need to convert to a list and use and onKeyDown event Code: [Select] <form> <select name="users" size="<?php echo $num_rows;?>" onchange="showUser(this.value)" > <?php do { ?> <option value="<?php echo $row_Recordset1['item_id']?>"><?php echo $row_Recordset1['item_id'].' '. $row_Recordset1['item_name']?></option> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </select> </form> I need to correct this Code: [Select] <ol> <?php do { ?> <li onKeyDown="showUser(this.value)"><a href="getmenu.php?item_id="<?php echo $row_Recordset1['item_id']?>"> <?php echo $row_Recordset1['item_name']?></a></li> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </ol> Hi guys; I've managed to find my way into something of a maze. <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> I'm looking at this line in the code. I realise it's currently in the wrong syntax but I'm just trying multiple different variations. At the moment I'm actually just trying to make it go to a static link but my real goal is to - get it to pick up the id number, of the id row I click, and concatenate that with the rest of my address string. Then use that as the href. Something like this: - "'Details/' + $id + '/index.php'" It's really confusing me though inside this loop and for some reason the id number is being picked up as an int, by the looks of things. It's getting above my level of understanding. Any chance one of you masters would through a n00b a lifeline?
This is my code below
<!DOCTYPE html> <html> <head> <title>LifeSaver DB</title> <h1> LifeSaver Database </h1> </head> <body> <table> <tr> <th>Id</th> <th>Location</th> <th>Initials</th> <th>TimeStamp</th> <th>Notes</th> </tr> <?php $conn = mysqli_connect("localhost", "meh", "pas", "DB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM LifeSaver1 ORDER BY id DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //for href row $id = $row['id']; $Footage = ['Footage']; echo "<tr> <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> <td>" . $row["Location"] . "</td> <td>" . $row["Initials"]. "</td> <td>" . $row["TimeStamp"]. "</td> <td>" . $row["Notes"] . "</td> </tr>";} //show table echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> <style> table, td, th { border: 1px solid black; margin: auto; } table { border-collapse: collapse; color: #000; <!--font colour --> font-family: monospace; font-size: 18px; text-align: center;} th { background-color: #337AFF; color: white; font-weight: bold; } tr:nth-child(odd) {background-color: #add8e6} </style> </html> Edited February 8, 2020 by JonnyDriller I have page1.php which has a post form and page2.php which display data/results. I have a seperate php script file which queries a database. Having completed the query and assuming a result, I would end up with something like Code: [Select] while($result = mysql_fetch_assoc($query)) how do I get the data onto the display page. Looking at example approaches I found this using a go-between file Code: [Select] <?PHP include_once(process.php; process($_POST); display_results; ?> would display_results be a form of redirect? If not? Any help appreciated. I have a field in my table that gets populated with a custom value from a subscription form, but when the data gets inserted into the table, it adds some text I do not want to output. The field is for the user's name, but when the form saves it, it saves the name, plus the text #2# (this is from a Wordpress plugin and I can't figure out how to remove the #2# when I insert the value there either). Is there a way to remove this #2# text when I display the field's value in MySQL and PHP? Ok... I need some help - I want to show a players balance in a game beside there name (Balance is in mysql database)I can do that but... - I also want to show if there online or offline at the same time( This is stored in a different database) I have the code which says whether they are online or offline <?PHP // Conect to the Mysql Server $connect = mysql_connect("localhost","scswccla_bukkit","********"); //connect to the database mysql_select_db("scswccla_bukkit"); //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 1"); //title echo "<font size='100'>NovaCraft Users</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='black'>|Online|<br><font color='green'>$users</font></font><br>"; endwhile; //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 0"); //title echo "<font color='black'>|Offline|</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='red'>$users</font><br>"; endwhile; ?> Here is the page: www.scswc.com/Offline_Users.php displaying that But I want to Create something like this: Nocvacraft Players |Online| Name:Player Balance:$20 |Offline| Name:Player Balance:$15 Here is what I have tried: <?PHP // Conect to the Mysql Server $connect = mysql_connect("localhost","scswccla_bukkit","**********"); //connect to the database mysql_select_db("scswccla_bukkit"); //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 1"); $query2 =mysql_query("SELECT * FROM iBalances WHERE player = $users"); //title echo "<font size='100'>NovaCraft Users</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query) $rows2 = mysql_fetch_array($query2)): $users = $rows['name']; $balance = $rows2['balance']; echo "<font color='black'>|Online|<br><font color='green'>Name:$usersBalance:$balance</font></font><br>"; endwhile; //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 0"); //title echo "<font color='black'>|Offline|</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='red'>$users</font><br>"; endwhile; ?> I know I am trying to use a variable before it is been set - but if I don't how I have tried this as well... <?PHP // Conect to the Mysql Server $connect = mysql_connect("localhost","scswccla_bukkit","**********"); //connect to the database mysql_select_db("scswccla_bukkit"); //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 1"); //title echo "<font size='100'>NovaCraft Users</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='black'>|Online|<br><font color='green'>Name:$users</font></font><br>"; endwhile; //query the database $query = mysql_query("SELECT * FROM users_online WHERE online = 0"); //title echo "<font color='black'>|Offline|</font><br>"; // fetch the results / convert into an array WHILE($rows = mysql_fetch_array($query)): $users = $rows['name']; echo "<font color='red'>$users</font><br>"; endwhile; $query = mysql_query("SELECT * FROM iBalances WHERE player = $users"); WHILE($rows = mysql_fetch_array($query)): $balance = $rows['balance']; echo "<font color='red'>$users $balance</font><br>"; endwhile; // ?> Can you use variables in mysql_query()?Is that why it isn't working? This is my first php script so if I need to give you more information for you to help me just tell me Thanks Here is database pictures iBalances users_online Hi, I'm trying to joing two tables together, in the resulting PHP coding (See below) the issue I'm having the coding saying select the colour from the colour table where the model of car is the same as the model in the cars table. For example, if the car model is KA and in the table it is KA show the colours. I know this manual fix does the trick. [ $test = "KA"; $query_cols = "SELECT * FROM colours WHERE colours.model = '$test' "; ] But not the soultion any help would be much appericated thank you. [ include "connections/dbconnect.php"; $manfactures = "Ford"; $car_query = "SELECT * FROM cars WHERE make = '$manfactures'"; $car_result = mysql_query($car_query) or die ("Error in query: $car_query. ".mysql_error()); setlocale(LC_MONETARY, 'en_GB'); $fmt = '%i'; if (mysql_num_rows($car_result) > 0) { while ($car_row = @ mysql_fetch_array($car_result)) { $test = "KA"; $query_cols = "SELECT * FROM colours WHERE colours.model = cars.model"; $cols_result = mysql_query($query_cols) or die ("Error in query: $query_cols. ".mysql_error()); print " <table class='details'> <tr> <td rowspan='2'> <img src=\"". $car_row["image"] ."\" alt='" . $car_row["image_alt"] . "' /> </td> <td colspan='2'> <a href='" . $car_row["what_link"] . "'> " . $car_row["model"]." ".$car_row["model_details"] . " </a> </tr> <tr> <td> <p class='info'> RRP:<br/> What Price:<br/> Our Price:<br/> Savings of:<br/> Delivery Time: </p> </td> <td> <p class='info1'> "; echo money_format($fmt, $car_row["rrp"] ); print "<br/>"; echo money_format($fmt, $car_row["what_price"] ); print "<br/>"; echo money_format($fmt, $car_row["our_price"] ); $savings = $car_row["rrp"] - $car_row["our_price"]; print " <br/> <font color=\"red\">"; echo money_format($fmt, $savings ); print " </font><br/> " . $car_row["delivery_time"] . " </p> </td> </tr> <tr> <td> "; while ($cols_row = @ mysql_fetch_array($cols_result)) { ?> <a href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $cols_row["colour"] . ""; ?>");return false'> <?php print " <img src=\"". $cols_row["colour_img"] ."\" alt='" . $cols_row["colour_img_alt"] . "' /> "; } print " </td> </tr> "; } } else { echo "Aids!"; } print "</table>"; ?>] hello, i have a table in a database that stores information on powerpoint presentations like so: id, title, filename, presenter, program, session I want to query the data so that all entries are grouped by session (which is a date) and each presentation is displayed under its respective session in a table like so: [session] (i want to display each session once) [title] - [program] (then i want to display this information for each presentation in each session) [presenter] [session] [title] - [program] [presenter] etc... i am thinking of using group_concat for this but am not sure exactly how to pull it off. any help is greatly appreciated. thank you! Hey guys have been trying to get this script to work for a while now, i am new to php and mysql so i am sure i am missing something simple. I have DB setup and need to pull data based on the key item code and get the following I want to get the fields item_code description allergy_statement useable_units region_availability order_lead_time ingredients for item_code 12-100 LITERALLY 12-100, no range, but like i said before i am really new to php and mysql. I have 1187 items that when a user clicks a link in search results it takes them to the product details page for that item code All that data is in my database just can't figure out how to get it out of the database. Is this even the right script to achieve that result. here is the code to get the data from database Code: [Select] <?php require_once('includes/mysql_connect_nfacts_ro.php'); $query = "SELECT item_code, description, allergy_statement, useable_units, region_availability, order_lead_time, ingredients " . "FROM products " . "WHERE item_code = '12-100' "; $resuts = mysql_query($query) or die(mysql_error()); ?> And need to display the data like so : Code: [Select] <td width="715" align="center" valign="top"> <h1>Product Details</h1> <h3>DISPLAY description HERE</h3> <table width="420" border="0"> <td class="ingreg"> </td> </table> <h5>Item Number</h5> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY ITEM_CODE HERE</td> </tr> </table> <h3>Ingredients:</h3> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY INGREDIENTS HERE</td> </tr> </table> <h4>Allergy Statement:</h4> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY Allergy Statement HERE</td> </tr> </table> <h4>Useable Units Per Package:</h4> <table width="420" border="0"> <tr> <td class="ingreg">DISPLAY Useable Units Per Package HERE</td> </tr> </table> <h4>Region Availability: </h4> <table width="420" border="0"> <tr> <td class="ingreg">&DISPLAY ITEM_CODE HERE</td> </tr> </table> <h4>Order Lead Time:</h4> <table width="420" border="0"> <tr> <td class="ingreg">&DISPLAY order lead time HERE</td> </tr> </table> <p> </p> <div align="right"></div></td> </tr> </table> how do i get data in database to display where i need it to? Can any one shine some light on this I am trying to display data from a database from a form entry here is the php <?php include('dbconnect.php'); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM child_info"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $field1-name=mysql_result($result,$i,"file_number"); $field2-name=mysql_result($result,$i,"first_name"); $field3-name=mysql_result($result,$i,"middle_name"); $field4-name=mysql_result($result,$i,"last_name"); $field5-name=mysql_result($result,$i,"birthdate"); $field6-name=mysql_result($result,$i,"gender"); $field7-name=mysql_result($result,$i,"features"); $field8-name=mysql_result($result,$i,"diagnosis"); $field9-name=mysql_result($result,$i,"description"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> here is the form I am using <form name="child_info" action="selectdata.php" method="post" id="child_info"> <table width="444" align="center" > <tr> <td> Search by Name: </td> <td> First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br /> Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" /> </td> </tr> <tr> <td width="208"> Choose Male or Female: </td> <td width="224"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="Female" /> Female </td> </tr> <tr> <td> Choose age range: </td> <td> <select name="first_age" id="first_age"> <option value="00">From</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> <select name="second_age" id="second_age"> <option value="00">To</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> </div></td> </tr> </table> </form> first problem is getting the form to use the php second problem is when i try to use the php alone is I get this error Parse error: syntax error, unexpected '=' in /home/fathersh/public_html/selectdata.php on line 17 17 is highlighted above in the php So I have an simple account centre up, and i'm wanting to display their 'Name' 'Username' and 'Email' as part of their details. But I have one problem... My code doesn't seem to be getting the data from my database... It may be messy to some people, just warning you! Code: [Select] <?php session_start(); if($_SESSION['username']){ $connect = mysql_connect("****","****","****") or die("Could not connect to database."); mysql_select_db("****") or die ("Could not find database!"); $sql = mysql_query("SELECT * FROM login"); $username = $rows['username']; $email = $rows['email']; $rows = mysql_fetch_assoc($sql); echo "<p>"; } else header("location: suggestion.html"); ?> <!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>Untitled Document</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-color: #CCC; } body,td,th { color: #000; font-family: "MS Serif", "New York", serif; } </style> </head> <body> <div id="wrap"> <!--Header--> <div id="header_member"> </div> <!--Log out and time--> <div id="info"> <div id="date"><script type="text/javascript"> var currentDate = new Date() var day = currentDate.getDate() var month = currentDate.getMonth() + 1 var year = currentDate.getFullYear() document.write("<b>" + day + "/" + month + "/" + year + "</b>") var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes()</script> </div> <div id="time"><script type="text/javascript"> var suffix = "AM"; if (hours >= 12) { suffix = "PM"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes < 10) minutes = "0" + minutes document.write("<b>" + hours + ":" + minutes + " " + suffix + "</b>")</script> </div> </div> <div id="logout"><center><?php echo "<a href='logout.php'>Log out.</a>";?></center></div> <!--Main section which will contain everything else--> <div id="member_main"> <div id="member_right"><center> <p><img src="images/accountinf.png" width="175" height="30" /></p> <p>Name: <?php echo $username;?></p> <p>Email: <?php echo $email;?></p> </center> </div> <div id="member_top"><center><?php echo "Welcome, ".$_SESSION['username'];?></center></div> <div id="member_left" align="center"><img src="images/navigation.png" width="105" height="30" /><img src="images/home_member.png" width="105" height="30" /><img src="images/account.png" width="105" height="30" /></div> </div> <!--Footer--> <div id="footer_member"></div> </div> </body> </html> |