PHP - Select, Update And Display
Guys, you are so going to be sick of me. But I really appreciate the help I am receiving here thus far.
I have the code below sending the data from the form to the database. That's excellent. However, where I am stuck is doing the following two: 1. Updating currently inserted data 2. Displaying the data on the site. Here is settings.php: <?php include "../settings.php"; include "../lang/english.php"; include "../config/config.php"; $errors = array(); // condition and map inputs $fields = array('site_name'=>'sitename','site_email'=>'email','your_name'=>'name','meta_description'=>'meta-description','meta_keywords'=>'meta-keywords'); foreach($fields as $var => $field){ $$var = isset($_GET[$field]) ? trim($_GET[$field]) : ''; } // check if the form was submitted if(isset($_GET['submit'])){ // connect to/select database mysql_connect("$db_hostname", "$db_username", "$db_password") or die(mysql_error()); mysql_select_db("$db_database") or die(mysql_error()); // basic validation (not empty) and escape data foreach($fields as $var => $field){ if(empty($$var)){ $errors[] = "The form field: $field, is empty!"; } // escape the data $$var = mysql_real_escape_string($$var); } // if no validation errors, insert the data if(empty($errors)){ $insert = sprintf("INSERT INTO settings (site_name, description, keywords, email, name) VALUES ('%s','%s','%s','%s','%s')", $site_name, $meta_description, $meta_keywords, $site_email, $your_name ); if(!mysql_query($insert)){ // a query error occurred // check if due to duplicate data if(mysql_errno() == 1062){ // 1062 = duplicate primary key error (your error number might be different depending on your table definition) $errors[] = "The site name: $site_name, already exists and cannot be inserted!"; } else { // all other query errors - $errors[] = "A database error occurred and your query cannot be processed!"; trigger_error(mysql_error()); // use error_reporting/display_errors/log_errors to display/log the error condition } } else { echo "The data was successfully inserted!"; } } } //database_connect(); $sql = "UPDATE settings SET site_name='$site_name', description='$description', keywords='$keywords', email='$site_email', name='$your_name' WHERE id='$id'"; $query = mysql_query($sql)or die("There's a problem with the query: ". mysql_error()); if($query) echo "<br>The settings have been updated.<br>"; $_SESSION['tekst']=""; ?> <!DOCTYPE html> <html> <head> <title><?php echo $site_name; ?> :: :: Powered by osPHPSite</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link href="css/admin.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="header"> <h1><?php echo $sitename; ?></h1> <ul id="top-navigation"> <li><a href="index.php"><?php echo $lang_button_index; ?></a></li> <li><a href="settings.php" class="active"><?php echo $lang_button_settings; ?></a></li> <li><a href="pages.php"><?php echo $lang_button_pages; ?></a></li> <li><a href="gallery.php"><?php echo $lang_button_gallery; ?></a></li> <li><a href="/"><?php echo $lang_button_viewsite; ?></a></li> <li><a href="logout.php"><?php echo $lang_button_logout; ?></a></li> </ul> </div> <div id="middle"> <div id="left-column"> <h3><?php echo $eng_navigation; ?></h3> <ul class="nav"> <li><a href="index.php"><?php echo $lang_button_index; ?></a></li> <li><a href="settings.php"><?php echo $lang_button_settings; ?></a></li> <li><a href="pages.php"><?php echo $lang_button_pages; ?></a></li> <li><a href="gallery.php"><?php echo $lang_button_gallery; ?></a></li> <li><a href="/"><?php echo $lang_button_viewsite; ?></a></li> <li><a href="logout.php"><?php echo $lang_button_logout; ?></a></li> </ul> <a href="http://www.osphpsite.com" target="_blank" class="link">osPHPSite</a> <a href="http://www.osphpsite.com/forums/" target="_blank" class="link">Support Forums</a> <a href="http://www.vichost.com" target="_blank" class="link">VicHost.Com</a> </div> <div id="center-column"> <div class="table"> <?php if(!empty($errors)){ echo 'The following errors occurred:<br />'; foreach($errors as $error){ echo "$error<br />"; } } ?> <form action="" id="settings" name="settings"> <table class="listing form" cellpadding="0" cellspacing="0"> <tr> <th class="full" colspan="2">Site Configuration</th> </tr> <tr> <th colspan="2">From the options below, define the default settings for your website.</th> </tr> <tr> <th colspan="2"></th> </tr> <tr> <td>Site name: </td> <td><input type="text" name="sitename" value="<?php echo $site_name; ?>" width="172" /> <em>Site name for logo</em></td> </tr> <tr> <td>Email: </td> <td><input type="text" name="email" value="<?php echo $site_email; ?>" width="172" /> <em>Your email address</em></td> </tr> <tr> <td>Name: </td> <td><input type="text" name="name" value="<?php echo $your_name; ?>" width="172" /> <em>Your own name</em></td> </tr> <tr> <td>Meta Description: </td> <td><input type="text" name="meta-description" value="<?php echo $meta_description; ?>" width="172" /> <em>SEO</em></td> </tr> <tr> <td>Meta Keywords: </td> <td><input type="text" name="meta-keywords" value="<?php echo $meta_keywords; ?>" width="172" /> <em>Separate with Commas</em></td> </tr> <tr> <td><input type="submit" class="button" name="submit" value="Submit"></td> </tr> </table> </form> </div> </div> </div> </div> </body> </html> This will be a huge hurdle if I can get passed this one, I am well and truly on my way. Any help, advice etc that you can give, and what needs to go where, I would really appreciate it and I promise not to annoy you guys unless absolutely necessary. Similar Tutorialswhat Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. Hi guys, Im developing a stock system and so far new stock and can be added with the quantity, however im trying to update the stock by using a select box and selecting the type of stock and inputting a new qty. the form and everything is set up and i can select files from the database, however i dont know how to update files from a select box The code i got so far is Code: [Select] <!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>stock manager</title> </head> <body> <?php $stockqty =&$_POST['stock_qty1']; ?> <center> <table> <td> <table> <td> <form action='stockview.php' method='POST'> Please Enter a Stock Name and Stock Value <table> <tr> <td> Stock Name: </td> <td> <input name="stock_name" type="text" /><BR /> </td> </tr> <tr> <td> Stock Qty: </td> <td> <input name="stock_qty" type="text" /> </td> </tr> </table> <input name="submit" type="submit" value="Add New Stock Items" /> </form> </td> </table> </td> <td> <table> <td> <form action='stockmanager.php' method='POST' enctype="multipart/form-data"> Please Select from the list the item you wish to update <table> <tr> <td> Stock Name: </td> <td> <?php $connect = mysql_connect("localhost","root", "") or die ("Couldn't Connect!"); mysql_select_db("stock", $connect) or die("Couldn't find db"); // select database $query=("SELECT id, stockname FROM stocks"); $result = mysql_query ($query); echo "<select name=stock value=''>Edit Stock QTY</option>"; while($nt=mysql_fetch_array($result)) { //Array or records stored in $nt echo "<option value=$nt[id]>$nt[stockname]</option>"; /* Option values are added by looping through the array */ } $queryreg = mysql_query("SELECT * FROM stocks WHERE stockqty='$stockqty'"); $numrows = mysql_num_rows($queryreg); $update = mysql_query("UPDATE stocks SET stockqty='$stockqty' WHERE stockname = '$stockname'"); echo("Its updated"); ?> </td> </tr> <tr> <td> Stock Qty: </td> <td> <input name="stock_qty1" type="text" /> </td> </tr> </table> <input name="submit" type="submit" value="Update stock items" /> </form> </td> </table> </td> </table> </center> </body> </html> Any help would be greatly appreciated. Thanks Lance I want to update a value by setting cookie. I use this code: Code: [Select] <?php if (isset($_POST['ChangeOrdering'])) { setcookie("Ordering", $_POST['ChangeOrdering'], time() + 31536000); } echo $_COOKIE["Ordering"]; ?> <form method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>"> Reorder messages: <select name="ChangeOrdering"> <option value="DateAdded ASC">Oldest first</option> <option value="DateAdded DESC">Newest first</option> <option value="Title ASC">By Title, A-Z</option> <option value="Title DESC">By Title, Z-A</option> </select> <input type="submit" value=" Save Settings " /> </form> Problem is that echo will return the previous cookie set, not the last value. As a matter of fact, my problem is about updating the cookie. It seems that the browser load the cookie before it is updated by the POST value. This has been bugging me for quite a while and I've tried so many different things and just run into all kinds of problems... What I'm doing or trying at least is pulling data from a table displaying it into a multiple select box allowing the user the oppertunity to remove one or more options. As the code stands now I'm getting no value at all in the post variable, by taking the [] brackets out of the inputs name i was able to get the first selected option but the php code was then unable to remove that value from the database. I hope I'm explaining this well enough but the code follows I'd really appreciate some help or direction on this one. The FORM Code: [Select] <FORM action='' method='post'> <select size='8' multiple name='remove_player[]'> <?php foreach ($members as $key => $mem) { if ($mem != "") { $mem = str_replace("-", " ", $mem); $mem = ucwords($mem); echo ("<option value='" . $mem . "'>" . $mem . "</option>"); } } ?> </select> and then the handler code: Code: [Select] $to_remove = $_POST['remove_player']; $as_team = str_replace(" ", "-", $teamname); $as_team = strtolower($as_team); $for_remove = "SELECT * FROM teams WHERE name = '$as_team'"; $for_query = (mysql_query($for_remove)); foreach ($to_remove as $y => $z) { $z = str_replace(" ", "-", $z); $z = strtolower($z); } while($arr_remove = mysql_fetch_array($for_query)) { foreach ($arr_remove as $a => $b) { foreach ($to_remove as $c => $d) { if ($b == $d) { unset($arr_remove[$a]); } } } foreach ($arr_remove as $e => $f) { $add_replace = (mysql_result($for_query, 0, 'members')); $replace = ($add_replace . "\r\n" . $f . "\r\n"); $replace_mem = "UPDATE teams SET members = '$replace'"; $replace_q = (mysql_query($replace_mem)); } } echo "Member List successfully updated.<br>"; foreach ($to_remove as $h => $g) { echo ($g . " removed from the team.<br>"); } Also any time i try to print any part of the array/s I get no values but the database is being updated with 2 line breaks and a "3" at the end of the table which has me a bit confused as well. Thanks! Hi there, I'm having a problem with updating a record with an UPDATE mysql query and then following that query with a SELECT query to get those values just updated. This is what I'm trying to do...I'd like a member to be able to complete a recommended task and upon doing so, go to a page in their back office where they can check off that task as "Completed". This completed task would be recorded in their member record in our database so that when they return to this list, it will remain as "Completed". I'm providing the member with a submit button that will call the same page and then update depending on which task is clicked as complete. Here is my code: Code: [Select] $memberid = $_SESSION['member']; // Check if form has been submitted if(isset($_POST['task_done']) && $_POST['task_submit'] == 'submitted') { $taskvalue = $_POST['task_value']; $query = "UPDATE membertable SET $taskvalue = 'done' WHERE id = $memberid"; $result = mysqli_query($dbc, $query); } $query ="SELECT task1, task2, task3 FROM membertable WHERE id = $memberid"; $result = mysqli_query($dbc, $query); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); $_SESSION['task1'] = $row['task1']; $_SESSION['task2'] = $row['task2']; $_SESSION['task3'] = $row['task3']; ?> <h4>Task List</h4> <table> <form action="" method="post"> <tr> <td>Task 1</td> <td><?php if($_SESSION['task1'] == 'done') {echo '<div>Completed</div>';} else{ echo '<input type="submit" name="task_done" value="Mark As Completed" />';} ?></td> </tr> <input type="hidden" name="task_value" value="task1" /> <input type="hidden" name="task_submit" value="submitted" /> </form> <form action="" method="post"> <tr> <td>Task 1</td> <td><?php if($_SESSION['task1'] == 'done') {echo '<div>Completed</div>';} else{ echo '<input type="submit" name="task_done" value="Mark As Completed" />';} ?></td> </tr> <input type="hidden" name="task_value" value="task2" /> <input type="hidden" name="task_submit" value="submitted" /> </form> <form action="" method="post"> <tr> <td>Task 1</td> <td><?php if($_SESSION['task1'] == 'done') {echo '<div>Completed</div>';} else{ echo '<input type="submit" name="task_done" value="Mark As Completed" />';} ?></td> </tr> <input type="hidden" name="task_value" value="task3" /> <input type="hidden" name="task_submit" value="submitted" /> </form> </table> The problem that I am having is that the database is not updated with the value "done" but after submission, the screen displays "Completed" instead of "Mark As Completed". So the value is being picked up as "done", but that is why I have the SELECT after the UPDATES, so that there is always a current value for whether a task is done or not. Then I refresh and the screen returns the button to Mark As Complete. Also, when I try marking all three tasks as, sometimes all three are updated, sometimes only one or two and again, I leave the page or refresh and the "Marked As Completed" buttons come back. Bizarre. If anyone can tell me where my logic is going wrong, I would appreciate it. Well, I made this yesterday then realised, I need to check is it exists... I got this but when I go to accept the application and the member exists in the table it enters it anyway... Code: [Select] <?php $member=$_POST['memberid']; $status=$_POST['Status']; $con = mysql_connect("host","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("a2186214_hbclan",$con); $sql="UPDATE application SET Status = '$status' WHERE ID = '$member'"; $sql1="INSERT INTO table_members(name) SELECT application.Name FROM application WHERE application.ID = '$member'"; if ($status == 'ACCEPTED') { if(mysql_num_rows(mysql_query("SELECT name FROM table_members WHERE name = '$member'"))) { if(mysql_query($sql, $con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } } else { if(mysql_query($sql, $con) or die(mysql_error())) { if(mysql_query($sql1, $con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } } else { die('Could not submit: ' . mysql_error()); } } } else { if(mysql_query($sql, $con) or die(mysql_error())) { echo 'Status Changed.<br /><a href="../applications.php">Return To Members List</a>'; } else { die('Could not submit: ' . mysql_error()); } } mysql_close($con); ?> I am trying to update a mysql table called AvItems with the value 'Torso' in the Equip "section?" I have been through the forums and cannot see anything to match. I dont mind if the page looses the onsubmit() and has a button instead. Though I would like to update the database and link back to the same page: There is a display that shows the item that is currently equiped, I have put this in to show it works, or doesn't as the case may be. Hope I got the code /code right this time. many thanks in advance Andy Curtis Code: [Select] create table Items( ItemID integer unsigned auto_increment primary key, ItemName varchar(20) not null, Type varchar(10), UsedOn varchar(10), ); create table AvItems( AvItemID integer unsigned auto_increment primary key, AvID integer unsigned, ItemID integer unsigned, Equip varchar(8)); <?php $username="root"; $password="MyPassword"; $database="MyDataBase"; $AvName = "AndyJCurtis"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $AvAccR = mysql_query( " SELECT AvID FROM AvAcc WHERE AvName = '$AvName' " ); $AvID = mysql_result($AvAccR, 0, 'AvID'); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $Torso = mysql_query(" select ItemName from AvItems, Items where AvItems.itemID = Items.itemID AND AvItems.AvID = '$AvID' AND UsedON = 'Body' "); $TorsoE = mysql_query(" select ItemName from AvItems, Items where AvItems.itemID = Items.itemID AND AvItems.AvID = '$AvID' And UsedON = 'Body' AND Equip = 'Body' "); if(mysql_num_rows($TorsoE) != 0) { $TorsoItem = mysql_result($TorsoE ,0,"ItemName"); //mysql_close(); ?> <title></title> <head></head> <body> <form action="http://localhost/CI/Equip2.php" method="post"> <table border=1> <tbody> <tr> <td>Torso<BR> <?PHP echo "$TorsoItem <BR>"; ?> <select name="Torso" onchange="submit();" value =" Update"> <?PHP while($TorsoRow = mysql_fetch_array($Torso)) { echo "<option value=\"".$TorsoRow['ItemName']."\">".$TorsoRow['ItemName']."\n </option>"; } ?> </select> </td> </tr> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// <?php if($_POST['Torso'] == 'Update') { mysql_query("update AvItems set Equip = '' where Equip='Torso'") or die("cant update unequip"); mysql_query("update AvItems set Equip = 'Torso' where ItemID='{$_POST['ItemName']}'") or die("cant update equip"); } ?> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// </tbody> </table> </.form> </body> </html>
In the same $-POST , i wanted to perform update and delete. With the updated and deleted database, I need to select the updated data from the database. However, it tells me: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in... .I am new to sql in php, is it true that i cannot perform sql in this way? Or is there any suggestion to perform select straight after deleting and updating? CANCEL BOOK RESERVATION if(isset($_POST['cancelres'])) { $query = "DELETE FROM reserved_books WHERE id='$resid';"; //delete reservation $query .="UPDATE reserved_books SET queue = queue - 1 WHERE bookid = '$bookid' AND queue > '$bookqueue';";//update queue number where reservation that queue behind/after/ the current reservation $query_run = mysqli_multi_query($connection, $query); if($query_run) { $_SESSION['success'] = "Reservation Cancelled"; } else { $_SESSION['status'] = " Reservation Not Cancelled"; } $query= "SELECT title FROM books WHERE id = '$bookid';"; //get book title from db $query_run = mysqli_query($connection,$query); if(mysqli_num_rows($query_run)>0) { foreach ($query_run as $row) { $title = $row['title']; } } $bookres = "SELECT * FROM reserved_books WHERE bookid = '$bookid' AND queue = 1"; $bookres_run = mysqli_query($connection,$bookres); foreach($bookres_run as $row) { $res_username = $row['username']; $res_id = $row['id']; } $query= "SELECT option_value FROM settings WHERE option_name = 'email_temp_rescollect'"; //get email template from db $query_run = mysqli_query($connection,$query); if(mysqli_num_rows($query_run)>0) { $row = mysqli_fetch_array($query_run); $rescollect_template = $row[0]; }}
There are about 400 records in a database with a field zabp_package = T_SIMT. They were uploaded in an order where specific category lists were uploaded together. For example, first 100 dining, then 75 insurance, then 150 health, then 75 cars. So from an auto increment standpoint they were inserted in that order. I want to select at random 100 of these 400 and update two fields. My update statement is: update `usersOld` SET `m_org` = 'ZABP.org Corporate HQ' , `m_orgID` = 'PFL2a96bW' WHERE `zabp_package` = 'T_SIMT' This works for all, I just need to limit a random selection to 100. Any Help on this, thanks in advance. Or something like that... I am not sure how to put this.. Anyway, I'll just get started with explaining my problem. I have an admin-page in which you can delete the comments given on blogs, using checkboxes and clicking on a button with the value 'verwijderenSubmit'. The deletion part works just fine, nothing wrong. However, I also want to be able to EDIT the comments with an other button called 'bewerkenSubmit', using the same checkboxes that I use for deletion. Selecting the right CID (CommentID) is no problem, because that works the same as the deletion-part, but selecting the right textarea to update into the database is the problem... I uploaded a file here with the whole code: http://dhost.info/ddfs/myproblem.html I escaped the textarea within with square brackets, because otherwise the whole textarea would screw up.. I also added <!-- RELEVANT CODE --> to select the parts that I need to change. Well, I hope you understand my problem and can help. Hi, all... have a basic question here as a newbie that I am... Many times, in some scripts I see (I think, if not mistaken), places where within a echo sentence I see variables echoed like this with no quotes: echo "First Name: $firstName and Last Name: $lastName"; as opposed to like one would expect: echo "First Name: " . $firstName . " and Last Name: " . $lastName"; Sometimes I see that also when variables are used in select/update statements I think.. like this: $query = mysql_query("SELECT FROM table WHERE column = $columnname"); Instead of like this within quotes: $query = mysql_query("SELECT FROM table WHERE column = '$columnname'"); Is it because some of these values may be numbers (numeric) as opposed to "strings"?? Not sure if I make sense... appreciate teh feedback, Thanks! I have a page in my admin control panel which allows for adding and editing an existing entry on the same page. At the moment, it displays the entries on the page in a table like format. After I edit an entry and hit Submit, I display a message on that page that says "Link updated successfully!", but the table on the page doesn't load the new entry until I refresh again - obviously since the data isn't entered into the database until I hit the submit button to process the form. But I'm wondering if it's possible to update the table on the page and display that new updated table all after hitting the submit button?? Hey guys, not sure what's gone wrong here, but this displays the select query twice on my page. Code: [Select] <?php $result = mysql_query("SELECT * FROM members WHERE Username='$_SESSION[Username]'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo '<b>Resources</b><br />'; echo 'Wood: ' . $row['res1'] . ' <br />'; echo 'Iron: ' . $row['res2'] . ' <br />'; } ?> Displays as: Resources Wood: 2000 Iron: 1000 Resources Wood: 0 Iron: 0 The first set of numbers are correct, but I'm not sure where the second lot are been called from? Thanks in advance. Okay so, I'm adding a reply feature to my text-board, and I'm wondering how I can select a single result from the DB I've tried this $board = mysql_real_escape_string($_GET['board']); $thread = mysql_real_escape_string($_GET['thread']); $result = mysql_query("SELECT subject, name, id, timestamp, body FROM $board LIMIT $thread,$thread"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("<div id='html1' style='background-color:#F0E0D6;border:solid 1px #800000;font-family:arial; font-size: 12px; padding:2px; margin:2px;'><font color='#CC1105'>%s </font><font color='#117743'>%s</font> <font color='#800000'>Post # %s - %s<br />%s<br /></div>", $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6]); mysql_free_result($result); } ?> Kinda works but if I pu ?thread=56 then it would show thread 57, which in this example does not exist. Hi all, I am a php student and i am doing a project in php. I am doing the project of online attendance register. I am stuck with the part of reports. We need to select three different values from an HTML form and pick the selected rows and wants to display those rows in a table. I have done a code but it is not working. Please help me out of this issue. HTML Form: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body><form action="reportpro.php" method="get" name="services"> <table width="447" border="0" align="center" > <tr style="text-align: center"> <td width="441"><table width="481" border="1"> <tr> <td width="216"><div align="center"> SECTION </div></td> <td width="102"><div align="center"> MONTH </div></td> <td width="141"><div align="center"> YEAR </div></td> </tr> <tr> <td><select name="section" id="select"> <option>SERVICES-A</option> <option>SERVICES-B</option> <option>SERVICES-C</option> </select></td> <td><select name="month" id="select"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select></td> <td><select name="year" id="select"> <option>2014</option> <option>2015</option> <option>2016</option> <option>2017</option> <option>2018</option> <option>2019</option> <option>2020</option> </select></td> </tr> <tr> <td colspan="4"> <center><input name="submit" type="submit" id="submit" formaction="reportpro.php" formmethod="get" value="Search"></center></td> </tr> </table> <p> </p> <p> </p> <p> </p></td> </tr> </table> </form> </body> </html> PHP Code: <!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> </head> <body> <form action="" method="get"> <table border="1" align="center" > <tr> <td>BOOK NO</td> <td>Name</td> <td>Desigination</td> <td>Section</td> <td>Day</td> <td>Month</td> <td>Year</td> <td>Attendance</td> </tr> <?php $con=mysql_connect("localhost","root",""); mysql_select_db("niy",$con); $m=$_REQUEST['month']; $y=$_REQUEST['year']; $sec=$_REQUEST['section']; $sql="select month='$m', year='$y', sectn='$sec' from attendance "; echo $sql; $res=mysql_query($sql,$con); while($row=mysql_fetch_array($res)) { ?> <tr> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><?php echo $row[5];?></td> <td><?php echo $m;?></td> <td><?php echo $y;?></td> <td><?php echo $row[8];?></td> </tr> <?php } ?> </table> </body> </html> Hello: I am trying to select all the records from a table, and display them. Having an issue... This is the code: Code: [Select] <ul> <?php $query = mysql_query("SELECT id,mySectionTitle FROM myWebSiteData"); while($menuData = mysql_fetch_array($query)) { <li><a href="a_websiteData.php?id=" .echo $menuData['id'] ."">echo $menuData['mySectionTitle']</a></li> } ?> </ul> This is the error: Code: [Select] Parse error: syntax error, unexpected '<' in /html/admin/a_websiteData.php on line 91 line 91 is the one that starts with "<li>" What am I missing, or what would be the best way to do this? I have the following html code and php code. I would like clients to select which fields in the mysql database they would like to have appear in the resultant table by checking the text box next to the field in the html form. For instance they should be able to select first name and city and have only those columns appear in the resultant table. # <html> # <head> # <title>Search Clients Database</title> # </head> # # <body> # <h1>Clients Database Search Page</h1> # <form action="searchclients.php" method="post"> # <table width="100%" border="1" cellspacing="1" cellpadding="1"> # <tr> # <th width="37" scope="col"> </th> # <th width="114" scope="col">Fields</th> # <th width="169" scope="col">Filter Value</th> # <th width="1157" scope="col"> </th> # </tr> # <tr> # <td><input type="checkbox" name="idc" id="idc"></td> # <td>ID</td> # <td><input type="text" name="ID" id="ID"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="fnc" id="fnc"> # </label></td> # <td>First Name</td> # <td><input type="text" name="FirstName" id="FirstName"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="lnc" id="lnc"> # </label></td> # <td>Last Name</td> # <td><input type="text" name="LastName" id="LastName"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="cc" id="cc"> # </label></td> # <td>City</td> # <td><input type="text" name="City" id="City"></td> # <td> </td> # </tr> # <tr> # <td><label> # <input type="checkbox" name="pc" id="pc"> # </label></td> # <td>Province</td> # <td><select name="Province" id="Province"> # <option selected> </option> # <option>KZN</option> # <option>North West Province</option> # <option>Gauteng</option> # <option>Free State</option> # <option>Mpumalanga</option> # <option>Eastern Cape</option> # <option>Limpopo Province</option> # <option>Northern Cape</option> # <option>Western Cape</option> # </select></td> # <td> </td> # </tr> # </table> # <p> # <input type="submit" name="submit" value="Search" /> # </p> # </form> # # </body> # </html> # <?php # mysql_connect ("localhost", "username","password") or die (mysql_error()); # mysql_select_db ("clients"); # # $fn = $_POST['FirstName']; # $ln = $_POST['LastName']; # $city = $_POST['City']; # $prov = $_POST['Province']; # # $idc = $_POST['idc']; # $fnc = $_POST['fnc']; # $lnc = $_POST['lnc']; # $cc = $_POST['cc']; # $pc = $_POST['pc']; # # ?> # # <html> # <body> # # <table border=1> # <tr> # <th>ID</th> # <th>First Name</th> # <th>Last Name</th> # <th>City</th> # <th>Province</th> # </tr> # # <?php # $sql = mysql_query("select ID, FirstName, LastName, City, Province from clients where FirstName like '%$fn%' and LastName like '%$ln%' and City like '%$city%' and Province like '%$prov%'"); # # while ($row = mysql_fetch_array($sql)){ # # $id = $row['ID']; # $fname = $row['FirstName']; # $lname = $row['LastName']; # $city = $row['City']; # $prov = $row['Province']; # # ?> # # <tr> # <th><?php echo $id;?></th> # <th><?php echo $fname;?></th> # <th><?php echo $lname;?></th> # <th><?php echo $city;?></th> # <th><?php echo $prov;?></th> # </tr> # # <?php } //this ends the if?> # # </table> # </html> Hey guys I'm really confused at the minute, I have products in my database (It's MySQL) I want to display attributes from the products in a filtering form.
I currently have select elements in my template and I want to display all current manufacturers that are listed in the manufacturers column of my database.
How can I display the manufacturers once in the select element without displaying them multiple times and in alphabetical order? For example I might have 4 products that are Sony but I don't want the brand to display 4 times.
Any resources or examples on how to do this?
Thanks
I wrote the page below to display a member's area of a website. The page is a mix of html and php code. the first part of is a block of php, which authenticates the user and displays the header. The middle part is a block of html which contains the bulk of the page. Embedded in this block of html are two sections of php, the first of which is supposed to display a user uploaded picture, enclosed in div tags, and the second of which, prints out the user's first name, from the database. The end of the script is a line of php that displays the footer. Now the page displays correctly when the section of php that contains the select query for displaying the picture(starting line 104) is omitted. But once I include that section, all i see is a blank page. Why is that section of php problematic? What can be done to fix it? Here is the data for the full page. Thanks for any help. <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //define title define('TITLE' , 'Members'); require ('header.html'); //need the header ?> <div id="main" style="background-color: #FFFFFF; height:71%; width:101%; border:0px none none; margin:auto; "> <!-- --> <div id="main_left" style="float:left; height:100%; width:20%; border:0px none none;"> <!--opens main left--> <div id="main_left_top" style="float:left; position:relative;bottom:5px;right:5px; height:31.25%; width:100%; background-color: #FFFFFF; border:1px solid #c0c0c0; margin:1px;"> <!--opens main left top--> </div> <!-- closes main left top--> <div id="main_left_center" style="float:left; background-color: #FFFFFF; height:33%; width:100%; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <!--opens the white content area--> </div> <!-- closes main left center--> <div id="main_left_bottom" style="float:left; background-color: #FFFFFF; height:33%; width:100%; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <!--opens the white content area--> </div> <!-- closes main left bottom--> </div> <!-- closes main left--> <div id="main_center" class="content_text" style="float:left; height:100%; width:58%; background-color: #FFFFFF; border:1px solid #c0c0c0;"> <!--opens main center--> <div id="image_box" style="float:left; background-color: #c0c0c0; height:150px; width:140px; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); $query = "SELECT* FROM images WHERE member_id ='{$_SESSION['id']}' AND cartegoty 'main' "; $result = mysql_query($query); $result_data = mysql_fetch_array($result); header("Content-type: image/jpeg") ; echo $result_data['image']; ?> </div> <a href="upload_image_page.php">click here to uplaod a picture</a> <h1>Welcome <?php echo ucfirst($_SESSION['firstname']);?></h1> <a href="member_profile.php">My Profile</a> | <a href="logout.php">Logout</a> <p>This is a password protected area only accessible to members. </p> <a href="blog_entries.php">Add to Hahap Tok Library</a> </div> <!-- closes main center--> <div id="main_right" style="float:left; background-color: #FFFFFF; height:100%; width:20%; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <!--opens the white content area--> <div id="main_right_top" style="float:left; background-color: #FFFFFF; height:33%; width:100%; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <!--opens the white content area--> </div> <!-- closes main left top--> <div id="main_right_center" style="float:left; background-color: #FFFFFF; height:33%; width:100%; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <!--opens the white content area--> </div> <!-- closes main left center--> <div id="main_right_bottom" style="float:left; background-color: #FFFFFF; height:34%; width:100%; border-color:#a0a0a0;border-style:outset;border-width:1px; margin:auto; "> <!--opens the white content area--> </div> <!-- closes main left bottom--> </div> <!-- closes main right--> </div> <!-- closes main--> <?php require('footer.html'); ?> Hi, I have come up with the following code, I need it to get the details of several scattered products and echo the results, the trick is I don't want it to echo the results one after the other... I want to have the products scattered between unique text on the page but don't want to run the query several times for performance reasons. E.g.- PAGE to look like this: $Product_1 unique text/images $Product_2 $Product_3 unique text/images $Product_4 Current Code: Code: [Select] <? $result = mysql_query("SELECT * FROM products where Product_ID IN (475, 465, 234, 567, 845)"); while($row = mysql_fetch_array($result)) { $x = "1"; while ($x<=3) { echo $x; $Product = "Product_"; $Product = $Product.$x; echo $Product; $Product = $row['Product_ID']; echo $Product; $x++; echo $x; } } At the moment it returns the following results: Quote 1 Product_1 465 2 2 Product_2 465 3 3 Product_3 465 4 1 Product_1 475 2 2 Product_2 475 3 3 Product_3 475 4 A few problems... In Blue... it duplicates for product 465 In Red... It repeats again for 475 Also.... it starts with 465, but I want it to go in order as how it appears - $result = mysql_query("SELECT * FROM products where Product_ID IN (475, 465, 234, 567, 845)"); so should start with 475 I want to get the following result: Quote 1 Product_1 475 2 2 Product_2 465 3 3 Product_3 234 4 4 Product_4 567 4 (and so on.....) If anyone could provide me assistance with my troubled 'while loop' statement that would be much appreciated! |