PHP - Processing And Displaying Data
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. Similar TutorialsThis has probably been asked a bunch of times , but : I only recently started to self learn PHP , and this small project i am making is quite a challange for me. The scripts below are not realy writen by me , but i wished to tie them together to get a fully working code. What is suppose to happen is : In the form i wish to put a special button that puts extra input fields in the form. After the form is submited ,with whatever amount of feilds in it, the data goes to a processing.php file that sorts all the info gathered and finaly sends all this data formated in to the last file that will be inluded in the index.php. i already have the code for increcing the amount of inputs but the problem is , all inputs have the same names. Coz of that i get a mess. What i need is each input to have a unique name or id , that way the processing file would receive different names(id's) with different values(what ever is writen in the inputs by users). for example: I have 2 enitial fields displayed on form.html , i click the button "add new" 5 times and add 5 more input fields. All this data must be sent to a process.php and on the output write all of this information formated in the last file in a row that will be displayed in the index by useing <?include("blablabla.php");?> The input increment is done by a java script. the problem is sending data with unique id(name) and receiving it. The form file : <?include("header.php");?> <?$i = 1; ?> <script type="text/javascript"> function validate(frm) { var ele = frm.elements['feedurl[]']; if (! ele.length) { alert(ele.value); } for(var i=0; i<ele.length; i++) { alert(ele[i].value); } return true; } function add_feed() { var div1 = document.createElement('div'); // Get template data div1.innerHTML = document.getElementById('newlinktpl').innerHTML; // append to our form, so that template data //become part of form document.getElementById('newlink').appendChild(div1); } var ct = 1; function new_link() { ct++; var div1 = document.createElement('div'); div1.id = ct; // link to delete extended form elements var delLink = '<div style="text-align:right;margin-right:65px"><a href="javascript:delIt('+ ct +')">Del</a></div>'; div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink; document.getElementById('newlink').appendChild(div1); } // function to delete the newly added set of elements function delIt(eleId) { d = document; var ele = d.getElementById(eleId); var parentEle = d.getElementById('newlink'); parentEle.removeChild(ele); } </script> <TABLE> <style> #newlink {width:600px} </style> <form action='sendorder.php' method='post'> <div id="newlink"> <div> <table align="center" border=0> <TR><TD><B>Product:</B> </TD><TD><input type=text name=prodname1 value="<?=$_GET['prodname1'];?>"> </TD> <TD><B>Price:</B> </TD><TD><input type=text name=price1 value="<?=$_GET['price1'].$curency;?>"><b>%</b></TD></TR> </table> </div> </div> <p> <br> <input type="submit" name="submit1"> <input type="reset" name="reset1"> </p> <p id="addnew"></p> <FORM> <INPUT type="button" value="Add New" name="button2" onClick="javascript:new_link()"> </FORM> </form> <!-- Template --> <div id="newlinktpl" style="display:none"> <div> <table border=0> <TR><TD><B>Product:</B> </TD><TD><input type=text name=<?$_POST[++$i];?> value="<?$_GET[$i];?>"> </TD> <TD><B>Price:</B> </TD><TD><input type=text name=<?$_POST [++$i];?> value="<?$_GET[$i].$curency;?>"> </TD></TR> </form> </TABLE> <?include("footer.php");?> in the code above i tryed to make the programm POST the numbers in the name increcing it by 1. But when i click submit i get offset error. The processing file : <? $timestamp = strftime("%d-%m-%Y %H:%M:%S %Y"); // for later use (ignore it) $i =1; #################################################################################### if(($_POST['prodname']!="")&&($_POST['price']!="")){ ############################################################ $writetocsv = $_POST['prodname1'] . "," . $_POST['price1']"%" <BR> . $_POST[$i] . $_POST[$i]; $fp = fopen("data/data.csv", "a"); fwrite ($fp,$writetocsv); fclose ($fp); echo "<script>alert('Data sent.')</script>"; } else{ echo "<script>alert('Error! Please fill the form!')</script>"; } echo "<script>location.replace('index.php')</script>"; ?> Perhaps someone knows a easyer way , since i am not sure how to make stuff due to the lack of knowlage in php. I also tryed arrays but , as said before , too tough when you are a noob Please help. I have a PHP file that does some data processing work in the database and I run in from a web browser each weekend. The PHP file usually completes the job in 4 hours, but past 2 weekends, it failed to complete. Then, i need to reexecute the file. Why? And how to fix this? 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 :
Hi all! I've been recently messing with PHP and MySQL to attempt to create a search function for my tables (too advanced, so I toned it down to learning to just display data from my table). Anyways, I'm watching a YouTube video on how to do it, and I'm copying his code exactly, but I'm still getting an error. Can anyone help? Thanks. Edit: Sorry, my error was snuggled down below the code. Anyways, my error is just my while echo appearing in and out of my tables on the page. My code: <?php //Make connection mysql_connect('localhost', 'root', 'test'); // select db mysql_select_db('testdatabase'); $sql="SELECT * FROM employees"; $records=mysql_query($sql); ?> <html> <head> <title>Employee Data</title> </head> <body> <table width="600" border="1" cellpadding="1" cellspacing="1"> <tr> <th>ID</th> <th>First name</th> <th>Surname</th> <th>Age</th> </tr> <?php while($employees=mysql_fetch_assoc($records)){ echo "<tr>"; echo "<td>".$Employee['ID']."</td>"; echo "<td>".$Employee['First name']."</td>"; echo "<td>".$Employee['Surname']."</td>"; echo "<td>".$Employee['Age']."</td>"; echo "</tr>"; } // end while ?> </table> </body> </html> Edited by thwikehu1990, 19 January 2015 - 01:33 PM. 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? 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> 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! 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>"; ?>] 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 pull some records out of a mysql table and i want to display them in 5 even columns. I'm not entirely sure how to do the math & logic to accomplish this. The pull is simple $qry = "SELECT DIST_PART_NUM FROM $tablename"; $sql = mysql_query($qry) or die(mysql_error()); while($res = mysql_fetch_assoc($sql)) { // CREATE 5 even columns here. } so let's say i just retrieved 5,000 part numbers, i'd like to display then in a table of 5 columns with 1000 records per column. This is easy math, but i need the script to automatically figure out the #'s. Also the tricky part is that i dont want to display the part numbers like so 11111 22222 33333 44444 55555 66666 77777 88888 99999 00000 but rather 11111 44444 77777 22222 55555 88888 33333 66666 99999 00000 the remainder if there is one can go in the last column or whatever is easier. I'd tried googling this, but it's not easy to phrase what i'm looking for. Thanks for the help. PS: I'm not looking to copy and paste code, if possible please explain your way so that i can learn the logic. 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 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 PHP Code Code: [Select] <?php $username=""; $password=""; $database=""; mysql_connect("","",""); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename"; $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,"id"); $field2-name=mysql_result($result,$i,"Location"); $field3-name=mysql_result($result,$i,"Property type"); $field4-name=mysql_result($result,$i,"Number of bedrooms"); $field5-name=mysql_result($result,$i,"Purchase type"); $field6-name=mysql_result($result,$i,"Price range"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> HTML code for the form Code: [Select] <table id="tb1"> <tr> <td><p class="LOC">Location:</p></td> <td><div id="LC"> <form action="insert.php" method="post"> <select multiple="multiple" size="5" style="width: 150px;" > <option>Armley</option> <option>Chapel Allerton</option> <option>Harehills</option> <option>Headingley</option> <option>Hyde Park</option> <option>Moortown</option> <option>Roundhay</option> </select> </form> </div> </td> <td><p class="PT">Property type:</p></td> <td><div id="PS"> <form action="insert.php" method="post"> <select name="property type" style="width: 170px;"> <option value="none" selected="selected">Any</option> <option value="Houses">Houses</option> <option value="Flats / Apartments">Flats / Apartments</option> </select> </form> </div> </td><td> <div id="ptype"> <form action="insert.php" method="post"> <input type="radio" class="styled" name="ptype" value="forsale"/> For Sale <p class="increase"> <input type="radio" class="styled" name="ptype" value="forrent"/> To Rent </p> <p class="increase"> <input type="radio" class="styled" name="ptype" value="any"/> Any </p> </form> </div> </td> </tr> </table> <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <form action="insert.php" method="post"> <select name="number of bedrooms"> <option value="none" selected="selected">No Min</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> </select> to <select name="number of bedrooms"> <option value="none" selected="selected">No Max</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> </select> </form> </div> </td> <td><p class="PR">Price range:</p></td> <td><div id="PR"> <form action="insert.php" method="post"> <select name="price range"> <option value="none" selected="selected">No Min</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> to <select name="price range"> <option value="none" selected="selected">No Max</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> </form> </div> </td> </tr> </table> </div> <form id="submit" action=""> <input type="submit" value="search" /> </form> 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. Hi guys, I have a problem.. I have a table which shows the results, but the table is showing right at the bottom below the button "delete members" although the code is right above it so I don't really understand.. and hope someone can shed the light? Appreciated Code: [Select] <?php include "connect.php"; session_start(); if(!isset($_SESSION['email'])) { die('You have no access to this page.'); } else{ //Check if records were submitted for deletion if(isset($_POST['id']) && count($_POST['id'])) { //Ensure values are ints $deleteIDs = implode(', ', array_map('intval', $_POST['id'])); $query = "DELETE FROM member WHERE id IN ({$deleteIDs})"; //Debug line echo "Successfuly deleted member(s)"; mysql_query($query) or die(mysql_error()); } ?> <link rel="stylesheet" type="text/css" href="view.css" media="all"> <script type="text/javascript" src="view.js"></script> <body id="main_body" > <img id="top" src="top.png" alt=""> <div id="form_container"> <h1>Consult, Modify or Delete a Member</h1> <form id="form_362567" class="appnitro" method="post" action="searchmember.php"> <div class="form_description"> <h2> Consult, Search, Modify or Delete a Member</h2> <p></p> </div> <ul > <li class="section_break"> <br>Search members with any keyword or character within the options id/email/firstname/lastname/phone/address1/address2/city/county/postcode - relevant matches will show.<br><br> <b>Keyword/Character:</b><br> <input id="search" name="search" class="element text medium" type="text" maxlength="50" value=""/> <br><br> <b>Search on</b>:<br> <select name="searchvalue" id="searchvalue"> <option name="id" id="id">id</option> <option name="email" id="email">email</option> <option name="firstname" id="firstname">firstname</option> <option name="lastname" id="lastname">lastname</option> <option name="phone" id="phone">phone</option> <option name="address1" id="address1">address1</option> <option name="address2" id="address2">address2</option> <option name="city" id="city">city</option> <option name="county" id="county">county</option> <option name="postcode" id="postcode">postcode</option> </select><br><input type='submit' value='Search' name='go' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br> <br> To consult or modify a profile click on the member's E-mail address. <li class="section_break"> </form> <?php $result = mysql_query("SELECT * FROM member"); ?> <table border='1'> <tr> <th>First Name</th> <th>Last Name</th> <th>Phone Number</th> <th>Postcode</th> <th>E-mail</th> <th>Delete</th> </tr> <?php while($row = mysql_fetch_array($result)) { echo "<form action='' method='POST'>"; echo "<tr>"; echo "<td>" . $row['firstname'] . "</td>"; echo "<td>" . $row['lastname'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; echo "<td>" . $row['postcode'] . "</td>"; echo "<td>"; echo '<a href="consultmember.php?email='; echo $row['email']; echo '">'; echo $row['email']; echo "</a></td>"; echo "<td><input type='checkbox' name='id[]' value='{$row['id']}' /></td>"; echo "</tr>"; } ?> <br><input type='submit' value='Delete Members' name='delete' /><INPUT TYPE="button" VALUE="Cancel" onClick="history.go(-1);return true;"><br> </form> <div id="footer"> </div> </div> <img id="bottom" src="bottom.png" alt=""> </body> <?php } ?> Hi i'm new to PHP/web development but not new to coding. I have some php code that I grabed from a template where I am selecting data from a file and having it diplay on the screen in a form. My $query = "select * from file where" statement works and bring the data back to the screen. However, I want the data to be returned in a textarea instead of a text field that is not big enough to display the 3 paragraph that i need to display. Please see code below, thsi code will return the data but the text box only returns the data in a line, I need the data to be returned in a textarea, so I can update it. I have looked for the correct syntex with no luck, please correct me. $row = mysql_fetch_array($result, MYSQL_ASSOC); $recordid = $row['recordid']; $homepage = $row['homepage']; echo "<h2>Update About Us Information</h2>\n"; echo "<form enctype=\"multipart/form-data\" action=\"admin.php\" method=\"post\">\n"; echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\">\n"; echo "<tr><td><h3>Record ID</h3></td><td>$recordid</td></tr>\n"; echo "<tr><td><h3>Homepage</h3></td><td><input type=\"text\" size=\"100\" name=\"homepage\" value=\"$homepage\" /></td></tr>\n"; echo "</table>\n"; echo "<input type=\"submit\" name=\"button\" value=\"Update\">\n"; echo "<input type=\"submit\" name=\"button\" value=\"Delete Product\">\n"; echo "</form>\n"; Hello again. I'm trying to load data from a Facebook Share Data XML file and then displaying them in a WordPress plugin. Here's my code so far: // Fetch Share Count Data function fb_button () { $fbshareUrl = urlencode(get_permalink($post->ID)); $fbshareTitle = urlencode($post->post_title); $fbLinkStats = simplexml_load_file('http://api.facebook.com/restserver.php?method=links.getStats&urls='.$shareUrl); $fb_params = '?u=' . $fbshareUrl . '&t=' . $fbshareTitle . '' ; // Vertical Facebook Button $fb_share = ' <div class="fsbsharer" id="fb"> <a href="http://www.facebook.com/sharer.php' . $fb_params . '" class="facebookShare"> <span class="fb_share_size_Small fb_share_count_wrapper"> <span></span> <span class="fb_share_count_nub_top "></span> <span class="fb_share_count fb_share_count_top"> <div class="fb_share_count_inner"> '. $fbLinkStats->link_stat->total_count .' </div> </div> <span style="cursor:pointer;" class="FBConnectButton FBConnectButton_Small"><span class="FBConnectButton_Text">Share</span></span> </a> </div> '; echo $fb_share; } This code works for everything except the title and the share count. I can fix the title myself but the share count isn't working. When I use this in plain HTML: <?php echo $fbLinkStats->link_stat->total_count.''; ?> it works fine, but when I combine it all into another function to echo, it no longer works properly. Thanks. Hello, I'm trying to build a registration/login system. I managed to set it up but i need that for the user when he/she is logged in to display his own information and to manage to edit them, First i need to display them, because i seem to not be doing it.. i know it's easy in principal but i am really new at this... So here is my code: The login.php page Code: [Select] <?php include ('database_connection.php'); if (isset($_POST['formsubmitted'])) { // Initialize a session: session_start(); $error = array();//this aaray will store all error messages if (empty($_POST['e-mail'])) {//if the email supplied is empty $error[] = 'You forgot to enter your Email '; } else { if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) { $Email = $_POST['e-mail']; } else { $error[] = 'Your EMail Address is invalid '; } } if (empty($_POST['Password'])) { $error[] = 'Please Enter Your Password '; } else { $Password = $_POST['Password']; } if (empty($error))//if the array is empty , it means no error found { $query_check_credentials = "SELECT * FROM members WHERE (Email='$Email' AND password='$Password') AND Activation IS NULL"; $result_check_credentials = mysqli_query($dbc, $query_check_credentials); if(!$result_check_credentials){//If the QUery Failed echo 'Query Failed '; } if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successfull { // A match was made. $_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable header("Location: page.php"); }else { $msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect'; } } else { echo '<div class="errormsgbox"> <ol>'; foreach ($error as $key => $values) { echo ' <li>'.$values.'</li>'; } echo '</ol></div>'; } if(isset($msg_error)){ echo '<div class="warning">'.$msg_error.' </div>'; } /// var_dump($error); mysqli_close($dbc); } // End of the main Submit conditional. ?><!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>Login Form</title> <style type="text/css"> body { font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; font-size:12px; } .registration_form { margin:0 auto; width:500px; padding:14px; } label { width: 10em; float: left; margin-right: 0.5em; display: block } .submit { float:right; } fieldset { background:#EBF4FB none repeat scroll 0 0; border:2px solid #B7DDF2; width: 500px; } legend { color: #fff; background: #80D3E2; border: 1px solid #781351; padding: 2px 6px } .elements { padding:10px; } p { border-bottom:1px solid #B7DDF2; color:#666666; font-size:11px; margin-bottom:20px; padding-bottom:10px; } a{ color:#0099FF; font-weight:bold; } /* Box Style */ .success, .warning, .errormsgbox, .validation { border: 1px solid; margin: 0 auto; padding:10px 5px 10px 60px; background-repeat: no-repeat; background-position: 10px center; font-weight:bold; width:450px; } .success { color: #4F8A10; background-color: #DFF2BF; background-image:url('images/success.png'); } .warning { color: #9F6000; background-color: #FEEFB3; background-image: url('images/warning.png'); } .errormsgbox { color: #D8000C; background-color: #FFBABA; background-image: url('images/error.png'); } .validation { color: #D63301; background-color: #FFCCBA; background-image: url('images/error.png'); } </style> </head> <body> <form action="login.php" method="post" class="registration_form"> <fieldset> <legend>Login Form </legend> <p>Enter Your username and Password Below </p> <div class="elements"> <label for="name">Email :</label> <input type="text" id="e-mail" name="e-mail" size="25" /> </div> <div class="elements"> <label for="Password">Password:</label> <input type="password" id="Password" name="Password" size="25" /> </div> <div class="submit"> <input type="hidden" name="formsubmitted" value="TRUE" /> <input type="submit" value="Login" /> </div> </fieldset> </form> Go Back to <a href="#">Account Verification on sign up</a> </body> </html> This is the page's code where user is redirected after login Code: [Select] <?php ob_start(); session_start(); if(!isset($_SESSION['Username'])){ header("Location: login.php"); } ?> <!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>Member Area </title> <style type="text/css"> .success { border: 1px solid; margin: 0 auto; padding:10px 5px 10px 60px; background-repeat: no-repeat; background-position: 10px center; font-weight:bold; width:450px; color: #4F8A10; background-color: #DFF2BF; background-image:url('images/success.png'); } </style> </head> <body> <div class="success">Welcome , <?php echo $_SESSION['Username'] ; ?></div> <? $b = time (); $date1 =date( "Y-m-d;h:i:s" , mktime(date("h")+6, date("i"), date("s"), date("m") , date("d"), date("Y"))); $str_time = "&receivedtimestamp="; $str_msg = "&msg=bkt"; $str_from = "from="; ?> <a href="http://testext.i-movo.com/api/receivesms.aspx?<?echo $str_from;?><?echo $_SESSION['phone'];?><?echo $str_time;?><?echo $date1;?><?echo $str_msg;?>">Get a Cupon</a> </br> <?php echo $_SESSION['Email'] ; ?> </br> <?php echo $_SESSION['phone'] ; ?> <p><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> </body> </html> And finally the database structure is this one ... Code: [Select] CREATE TABLE IF NOT EXISTS `members` ( `Memberid` int(10) NOT NULL AUTO_INCREMENT, `Username` varchar(20) NOT NULL, `Email` varchar(50) NOT NULL, `Password` varchar(10) NOT NULL, `phone` varchar(25) NOT NULL, `Activation` varchar(60) DEFAULT NULL, PRIMARY KEY (`Memberid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=30 ; Please help me with this because i'm going mad |