PHP - Generating Table Based On Form Input Order By Bug...
What I'm trying to do here is generate a table based on a form in which the user selects two options. The first option tells the script which database entries to put in the table, the second option tells it how to arrange them. The first works perfectly, the second not at all - it doesn't produce an error, it just doesn't do anything. I've found a number of tutorials that seem to suggest that the problem is somewhere in my punctuation around ORDER BY '$POST[sort]' but I've been unable to find a solution that actually works. Any help would be much appreciated, my code is below.
Thank you! mysql_select_db($database, $con); $result = mysql_query("SELECT * FROM main WHERE state='$_POST[state]' ORDER BY '$POST[sort]'"); if(mysql_num_rows($result)==0){ echo "<p align='left'>View Pantries by State</p><div id='stateform'> <form action='../admin/viewstate.php' method='post'> <select name='state' /> <option value='AL'>Alabama</option> <option value='AK'>Alaska</option> <option value='AZ'>Arizona</option> </select> <select name='sort' /> <option value='name'>Name</option> <option value='id'>Id</option> <option value='city'>City</option> <option value='zip'>Zip</option> <option value='timestamp'>Timestamp</option> </select> <input type='submit' value='Go'></input></form> </div>"; } else{ echo "<p align='left'>View Pantries by State</p> <div id='stateform'> <form action='../admin/viewstate.php' method='post'> <select name='state' /> <option value='AL'>Alabama</option> <option value='AK'>Alaska</option> <option value='AZ'>Arizona</option> </select> <select name='sort' /> <option value='name'>Name</option> <option value='id'>Id</option> <option value='city'>City</option> <option value='zip'>Zip</option> <option value='timestamp'>Timestamp</option> </select> <input type='submit' value='Go'></input></form> </div>"; echo "<div id='fptext'><span class='h1'>Food Pantries for " . $_POST['state'] . "</span><br><br></div>"; } echo "<table border='1' align='center' cellpadding='3' width='900px'> <tr> <th>ID</th> <th>Name</th> <th>Type</th> <th>Address</th> <th>State</th> <th>Phone</th> <th>E-mail</th> <th>Website</th> <th>Hours</th> <th>Requirements</th> <th>Additional Information</th> <th>Lat</th> <th>Lng</th> <th>Update</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['type'] . "</td>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; echo "<td>"; echo "<a href=mailto:".$row['email'].">".$row['email']."</a>"; echo "</td>"; echo "<td>"; echo "<a href=".$row['website']."\>".$row['website']."</a>"; echo "</td>"; echo "<td>" . $row['hours'] . "</td>"; echo "<td>" . $row['requirements'] . "</td>"; echo "<td>" . $row['additional'] . "</td>"; echo "<td>" . $row['lat'] . "</td>"; echo "<td>" . $row['lng'] . "</td>"; echo "<td><a href='../public/updatepage.php?id=".$row['id']."'>Update Pantry</a></td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Similar Tutorialsim wanting to change the sql in my query based on if a field is empty or not. if the field is empty then i dont want it to post anything, but if its not empty then it can post the content. heres what i have so far but it does post the content even if the field is empty. (!empty($password)) ? $pass_sql = "u_password = '$password'," : $pass_sql = null; $link->query("UPDATE ".TBL_PREFIX."users SET $pass_sql u_allow_user_pm = '".$_POST['allow_user_pm']."' WHERE u_username = '".$_POST['user_name']."'") or die(print_link_error()); how can i stop it from updating if the field is empty? Hi there, I found a Javascript with what I want, but I want it to be in PHP because if people don't have Javascript enabled, they won't see the login. Here is what I have, but I need it to be converted to PHP: Code: [Select] function loginArea() { val = document.loginForm.password.value; switch(val) { case "password1": document.location = 'http://www.google.com/password1-page/'; break; case "password2": document.location = 'http://www.google.com/password2-page/'; break; default: document.location ='http://www.google.com/sorry/'; break; } } Code: [Select] <form name="loginForm" id="loginForm" method="post" action=""> <input name="password" type="text" id="password" maxlength="5" /> <input name="login" type="button" id="login" value="Check" onclick="loginArea()" /> </form> Help? - Steph We recently upgraded from PHP4 to PHP5 and the below script that was working perfectly in 4 has completely stopped working and I can't figure out why for the life of me. I'm not an experienced PHP programmer--I've done some forms, but this is the first time I've used a database. What needs to (and was) happen: A user enters their username in the form and gets a readout of their participation so far that month. The problem(s): I know that it's storing the variable 'user' because it echoes it back properly, but the database is no longer allowing me to select the row based on that variable. I know it's not that I can't connect to the database because if instead of '$user' I change the code to a username I know is in there, I get the proper readout. This all started as soon as I transferred over to PHP5--before that, no problems at all. The database information is all correct, I just took it out for privacy's sake. <form id="feedback" method="post" action="index.php"> <input name="user" type="text" value="Enter user name" size="20" maxlength="50" /><br /> <input name="send" id="send" type="submit" value="Submit" /> </form> <?php if (isset($_POST['user'])) { $_session['user'] = $_POST['user']; } ?> <p>You entered your username as: <strong><? echo $_session['user'];?></strong>. If this is not correct or you do not see your information below, please re-enter your username and click Submit again.</p> <?php $con = mysql_connect("database","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT * FROM March WHERE Username='$user'") or die ('Error: '.mysql_error ()); while($row = mysql_fetch_array($result)) { echo "<table border='0'>"; echo "<tr>"; echo "<td><strong>Username:</strong> </td><td>" . $row['Username'] . "</td></tr>"; echo "<tr><td><strong>Mar. 2 Discussion:</strong></td><td>" . $row['Mar2Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 2 Poll:</strong></td><td>" . $row['Mar2P'] . "</td></tr>"; echo "<tr><td><strong>Mar. 9 Discussion:</strong></td><td>" . $row['Mar9Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 9 Poll:</strong></td><td>" . $row['Mar9P'] . "</td></tr>"; echo "<tr><td><strong>Mar. 16 Discussion:</strong></td><td>" . $row['Mar16Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 16 Poll:</strong></td><td>" . $row['Mar16P'] . "</td></tr>"; echo "<tr><td><strong>March Participation To-Date:</strong></td><td>" . $row['Participation'] . "</td></tr>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> ANY help would be greatly appreciated! I've got a couple hundred people who use this on a regular basis and are starting to ask why it's not working. I need to build a hierarchical product category table with data from another table. The original product info table has a basic structu ID | SKU | Category1 | Category2 | Category3 1 | 001 | Apparel | Boots | Work Boots 2 | 002 | Apparel | Shirts | Long Sleeve The categories table this is going into: ID | Name | Parent_ID 1 | Apparel | 0 2 | Boots | 1 3 | Work Boots | 2 4 | Shirts | 1 5 | Long Sleeve | 4 I've been trying to use PHP to increment ID's by: SELECT DISTINCT Category1 SELECT DISTINCT Category1,Category2 SELECT DISTINCT Category1, Category2, Category3 Code: [Select] $i='0'; while ($row = mysql_fetch_assoc($result)) { $i++; echo $i . " - ". $row['Category1'] . "<br>"; } One problem is that I can't get the parent ID that was generated in this method. Another is that Category2 and 3 are not uniquely named at all. So my question is, how do I distinctly select all three categories, and get each parent ID also? Hello everyone. I need help with the following PHP APP. I am running on (Version PHP 7.2.10) I am trying to have a page table form on table.php pass the input variable of “5-Numbers” to another page called table_results.php I want that variable string of “5-Numbers” to be compared against 4 arrays and output any duplicates found within each of those 4 lists. If nothing is found, I still want some visual output that reads “None found”.
Lets pretend I have the following example .. On table.php, I typed inside my table form the 5-Numbers .. INPUT: 2,15,37,13,28 On table_results.php, the 4 arrays to be compared against my input numbers “ 2,15,37,13,28” are ..
$array_A = array(2,6,8,11,14,18,24); $array_B = array(1,2,9,10,13,14,25,28,); $array_C = array(1,3,7,9,13,15,20,21,24); $array_D = array(4,5,12,22,23,27,28,29);
So my output should read as follows below .. OUTPUT:
TABLE COLUMN 1 COLUMN 2 ROW 1 Matches Found Results .. ROW 2 GROUP A: 2 ROW 3 GROUP B: 2,13,28 ROW 4 GROUP ? 13,15 ROW 5 GROUP ? 28 ROW 6 5#s Input: 2,15,37,13,28
Please let me know if anyone has any suggestions on how to go about it. Thanks. Edited January 1, 2019 by Jayfromsandiego Wanted to include image example Maybe somebody knows a good way to do this... I have a simple query that seasonal categories - plus one special events header. then for each header I pull all the classes in that category. Right now it just pulls and orders by id. So, regardless of year, they come out in the same order: spring, winter, fall, special events. I'm trying to see if there's a way to make them show in order of relevance to the current time. right now, the "cat" table just has two fields: cat_id, cat_name. In other words, in autumn, I want them to order: Autumn, winter, summer, spring - then special events. In summer, I want them to order: Summer, spring, autumn, winter - then special events. any thoughts on how to do this? step one, order by relevence to current date. step two, special events is always last. Code: [Select] $query1 = "select * from tbl_cat ORDER by cat_id"; $result_cats = mysql_query($query1) or die(mysql_error()); while ($row = mysql_fetch_array($result_cats)) { $query_selectall = "select *,workshop_date AS tester from tbl_workshops WHERE category={$row['cat_id']} and active_inactive = '1' ORDER by workshop_date"; $result_all = mysql_query($query_selectall) or die(mysql_error()); $catid = $row['cat_id']; $catname = $row['cat_name']; echo "<font face='georgia' size=5><b>".$catname." </b></font><br><div style='color:#fff;'>"; while ($c_row = mysql_fetch_array($result_all)){ // rest of code pulls items that match that specific category id. } As a complete newbie, I'm not sure Ive got the terminology right in my subject header. But this is what I am trying to do. I have a soccer stats site with data entered into each of numerous 'seasons', accessible via a drop-down menu, as he http://www.fleethistory.co.uk/stats/matches.php Now regardless of what season I select, the URL will stay the same as above. What I want to do is have users go direct to a particular season from a link without having to use the drop-down. How would I generate a unique URL for each of the seasons listed in the drop-down? Don't know if you need the PHP code, but here it is just in case: Code: [Select] <?php /* *************************************************************************** * tplSoccerStats * ----------------------------------------------------------------------- * Copyright: TPL Design * email: info@tpl-design.com * www: www.tpl-design.com/tplsoccerstats *************************************************************************** */ // Starts a new session or resumes the current one. session_start(); // Get db host, db username, db password, and db name from admin/user.php // (each team has its own db). include('admin/user.php'); // Establish db connection. Select appropriate team db. $connection = mysql_connect("$host", "$user", "$password") or die(mysql_error()); mysql_select_db("$txt_db_name", $connection) or die(mysql_error()); // Get preferences stored in db. $sql = "SELECT * FROM tplss_preferences WHERE ID = '0'"; $pref = mysql_query($sql, $connection) or die(mysql_error()); $pdata = mysql_fetch_array($pref); mysql_free_result($pref); // Include php preferences. include('preferences.inc'); // Use session defaults if available, otherwise set them from database values. if ((!isSet($_SESSION['defaultseasonid_tplss'])) || (!isSet($_SESSION['defaultmatchtypeid_tplss'])) || (!isSet($_SESSION['defaultlanguage_tplss']))) { $_SESSION['defaultseasonid_tplss'] = $pdata['DefaultSeasonID']; $_SESSION['defaultmatchtypeid_tplss'] = $pdata['DefaultMatchTypeID']; $_SESSION['defaultlanguage_tplss'] = $pdata['DefaultLanguage']; } $defaultseasonid = $_SESSION['defaultseasonid_tplss']; $defaultmatchtypeid = $_SESSION['defaultmatchtypeid_tplss']; $defaultlanguage = $_SESSION['defaultlanguage_tplss']; // Include language based global vars, in our case english, e.g. $txt_preview = 'Preview' include('language.inc'); // Include pafc banner and menu bar. include('header.php'); // Start an html form. echo '<form method="post" action="change.php">' . "\n"; // Print images at top of form if we have them (we don't). $image_url = "images/header.jpg"; $image_url2 = "images/header.gif"; if(file_exists($image_url) || file_exists($image_url2)) { echo '<table align="center" width="' . $tb_width . '" cellspacing="0" cellpadding="0" border="0">' . "\n"; echo "<tr>\n"; echo '<td align="center">' . "\n"; if (file_exists($image_url)) { echo '<img src="' . $image_url . '" ALT=""><br>' . "\n"; } elseif (file_exists($image_url2)) { echo '<img src="' . $image_url2 . '" ALT="">' . "\n"; } echo "</td></tr></table>\n\n"; } ?> <!-- Print change bar table --> <table align="center" width="<?php echo $tb_width ?>" cellspacing="0" cellpadding="0" border="0" bgcolor="<?php echo $border_c ?>"> <tr> <td> <table width="100%" cellspacing="1" cellpadding="5" border="0"> <tr> <td bgcolor="<?php echo $inside_c ?>" align="center"> <?= $txt_change ?>: <select name="season"> <option value="0"><?= $txt_all ?></option> <?php $sql = "SELECT * FROM tplss_seasonnames WHERE SeasonPublish = '1' ORDER BY SeasonName DESC"; $get_seasons = mysql_query($sql, $connection) or die(mysql_error()); while($data = mysql_fetch_array($get_seasons)) { if($data['SeasonID'] == $defaultseasonid) echo '<option value="' . $data['SeasonID'] . '" SELECTED>' . $data['SeasonName'] . "</option>\n"; else echo '<option value="' . $data['SeasonID'] . '">' . $data['SeasonName'] . "</option>\n"; } mysql_free_result($get_seasons); ?> </select> or Competition: <select name="matchtype"> <option value="0"><?= $txt_all ?></option> <?php $sql = "SELECT * FROM tplss_matchtypes ORDER BY MatchTypeName"; $get_types = mysql_query($sql, $connection) or die(mysql_error()); while($data = mysql_fetch_array($get_types)) { if($data['MatchTypeID'] == $defaultmatchtypeid) echo '<option value="' . $data['MatchTypeID'] . '" SELECTED>' . $data['MatchTypeName'] . "</option>\n"; else echo '<option value="' . $data['MatchTypeID'] . '">' . $data['MatchTypeName'] . "</option>\n"; } mysql_free_result($get_types); ?> </select> <input type="submit" name="submit" value="Select"> </td> </tr> </table> </td> </tr> </table> <!-- Print outer fixture tables --> <table align="center" width="<?php echo $tb_width ?>" cellspacing="0" cellpadding="0" border="0" bgcolor="<?php echo $border_c ?>"> <tr> <td> <table width="100%" cellspacing="1" cellpadding="5" border="0"> <tr> <td bgcolor="<?php echo $inside_c ?>" align="center"> <!-- Print inner fixture table --> <table width="<?= $tb2_width ?>%" cellspacing="0" cellpadding="4" border="0"> <tr> <td align="left" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Date</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>H/A</b></font> </td> <td align="left" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Opponent</b></font> </td> <td align="left" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Competition</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818" colspan="2"> <font color="#FFffff"><b>Result</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Att</b></font> </td> <td align="center" valign="middle" bgcolor="#D01818"> <font color="#FFffff"><b>Details</b></font> </td> </tr> <?php // Construct db query to get fixtures from database. $selectClause = "SELECT M.MatchID AS id, M.MatchAdditionalType AS additype, O.OpponentName AS opponent, O.OpponentID AS oppid, M.MatchGoals AS goals, M.MatchGoalsOpponent AS goals_opponent, M.MatchPenaltyGoals AS penalty_goals, M.MatchPenaltyGoalsOpponent AS penalty_goals_opponent, M.MatchOvertime AS overtime, M.MatchPenaltyShootout AS penalty_shootout, DATE_FORMAT(M.MatchDateTime, '%M %Y') AS month, DATE_FORMAT(M.MatchDateTime, '%a %e') AS date, DATE_FORMAT(M.MatchDateTime, '%H:%i') AS time, M.MatchPlaceID AS place, M.MatchAttendance AS att, M.MatchPublish AS publish, MT.MatchTypeName AS typename, P.PreviewText AS prewtext FROM ( tplss_matches M, tplss_matchtypes MT, tplss_opponents O ) LEFT OUTER JOIN tplss_previews P ON M.MatchID = P.PreviewMatchID "; if (($defaultseasonid != 00) && ($defaultmatchtypeid != 0)) { $whereClause = "WHERE M.MatchTypeID = '$defaultmatchtypeid' AND M.MatchSeasonID = '$defaultseasonid' AND M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } elseif (($defaultseasonid == 0) && ($defaultmatchtypeid != 0)) { $whereClause = "WHERE M.MatchTypeID = '$defaultmatchtypeid' AND M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } elseif (($defaultseasonid != 0) && ($defaultmatchtypeid == 0)) { $whereClause = "WHERE M.MatchSeasonID = '$defaultseasonid' AND M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } elseif (($defaultseasonid == 0) && ($defaultmatchtypeid == 0)) { $whereClause = "WHERE M.MatchTypeID = MT.MatchTypeID AND M.MatchOpponent = O.OpponentID "; } $orderByClause = "ORDER BY M.MatchDateTime"; // Execute query. $sql = $selectClause . $whereClause . $orderByClause; $get_matches = mysql_query($sql, $connection) or die(mysql_error()); // Loop round fixtures (which come back from database in date order). while($data = mysql_fetch_array($get_matches)) { // Print a month header row each time we hit a new month. if ($data['month'] <> $lastMonth) { echo "<tr>\n"; echo '<td align="left" valign="middle" bgcolor="#7c0606" colspan="9">'; echo '<font color="#FFffff"><b>' . $data['month'] . "</b></font>"; echo "</td>\n"; echo "</tr>\n\n"; $lastMonth = $data['month']; } // Assign home/away based vars. if ($data['place'] == 1) { $placeBg = $bg4; $venue = "H"; } else { $placeBg = $bg3; $venue = "A"; } // Print date and venue. echo"<tr>\n"; echo '<td align="left" valign="middle" bgcolor="' . $placeBg . '">'; echo $data['date']; echo "</td>\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">'; echo $venue; echo "</td>\n"; // Print opponent team name (as a link if possible). echo '<td align="left" valign="middle" bgcolor="' . $placeBg . '">'; if ($data['oppid'] == 1) { echo '$data[opponent]'; } else { echo '<a href="opponent.php?opp=' . $data['oppid'] . '">' . $data['opponent'] . "</a>"; } echo "</td>\n"; // Print competition type. echo '<td align="left" valign="middle" bgcolor="' . $placeBg . '">'; echo $data['typename']; if ($data['additype'] != '') { echo " / " . $data['additype']; } echo "</td>\n"; // Print result, attendance and match report. if ($data['goals'] == NULL || $data['goals_opponent'] == NULL) { // No goals recorded - match can't have been played yet - print empty fields. echo '<td bgcolor="' . $placeBg . '"> </td>' . "\n"; echo '<td bgcolor="' . $placeBg . '"> </td>' . "\n"; echo '<td bgcolor="' . $placeBg . '"> </td>' . "\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">'; if ($data['prewtext'] == '') { echo " "; } else { echo '<a href="preview.php?id=' . $data['id'] . '">' . $txt_preview . "</a>"; } echo "</td>\n"; } else { // Goals recorded - figure out result and score - print required fields. if ($data['penalty_goals'] == NULL || $data['penalty_goals_opponent'] == NULL) { if ($data['goals'] > $data['goals_opponent']) $result = '<img src="images/win.jpg">'; elseif ($data['goals'] < $data['goals_opponent']) $result = '<img src="images/lose.jpg">'; else $result = '<img src="images/draw.jpg">'; $score = $data['goals'] . " - " . $data['goals_opponent']; } else { if ($data['penalty_goals'] > $data['penalty_goals_opponent']) $result = "<b>W</b>"; else $result = "L"; $score = $data['goals'] . " - " . $data['goals_opponent'] . " (" . $data['penalty_goals'] . " - " . $data['penalty_goals_opponent'] . ")"; } echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">' . $result . "</td>\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">' . $score . "</td>\n"; echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '">' . $data['att'] . "</td>\n"; if($data['publish'] == 1) { echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '"><a href="matchdetails.php?id=' . $data['id'] . '">Yes</td></a></td>' . "\n"; } else { echo '<td align="center" valign="middle" bgcolor="' . $placeBg . '"> </td></a></td>' . "\n"; } } echo "</tr>\n\n"; } // Free resultset. mysql_free_result($get_matches); ?> </table> </td> </tr> </table> </td> </tr> </table> <?php // Print tpl soccers stats message. include('bottom.txt'); ?> </form> <?php // Finish off html. include('footer.php'); ?> I hope I can explain what is happening. I have created two forms in PHP. The first 'almost' works, i.e. it shows the data. But I have two problems - 1) the second pulldown menu is always empty and 2) $value from the first pulldown menu ALWAYS equals the last entry thus the last 'if' in the function subdomains ($domains) is always called (but still empty). The code may explain this better than me:
<!DOCTYPE html> <html> <body> <!-- processDomains.php is this file - it calls itself (for testing purposes so I can see what is happening) --> <form action="processDomains.php" method="post"> <?php // create the domains array (there are actually several entries in the array but I cut it down for testing) $domains = array (1 => 'Decommission', 'Migration'); echo "Select Domain:"; echo "<br>"; // Make the domain pull-down menu - this displays correctly echo '<select name="domain">'; foreach ($domains as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; // input doesn't matter what is 'submitted', always goes to last $value echo '<input type="submit" name="submit" value="Submit">'; // call function subdomains subdomains ($value); function subdomains ($domains) { // define values for each array - each array contains available choices for the subdomain pulldown menu $migration = array (1 => 'Application Migration', 'Application Patch', 'Application Upgrade'); $decommission = array (1 => 'Applications', 'Servers', 'Storage'); if ($domains === 'Migration') { echo "Select subdomain:"; echo "<br>"; // Make the Migration pull-down menu echo '<select name="migration">'; foreach ($migration as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; } else if ($domains === 'Decommission') { /* === * since 'Decommission' is the last entry in the 'Domains' pulldown list, $value ALWAYS equals * 'Decommission' and $domains equals $value. So this menu SHOULD work but is always * empty. Thus, two problems - the pulldown menu is always empty and $value isn't based * upon user input. */ echo "Select subdomain:"; // this prints so I know I'm in 'Decommission (I eliminated the echo "$domain" to show I'm always coming here)' echo "<br>"; // Make the 'Decommission' pull-down menu echo '<select name="decommission">'; foreach ($decommission as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit">' ) // end of 'if-else' } // end of function 'subdomain' ?> </form> </body> </html>Let me say thank you in advance and I appreciate the help! I know I'm doing something (or more than one thing) wrong and I hope someone can tell me what it is. Best Regards! Edited by mac_gyver, 19 January 2015 - 09:37 PM. code tags around posted code please Hi all, Here i have a serious problem. I want to sought it out using PHP and MySQL only. I have a form includes fields of customer id and Account type( stored in a jump menu and includes 6 different types of accounts) <style type="text/css"> <!-- body,td,th { font-size: 18px; font-weight: bold; } --> </style> <p><img src="../images/mahapitiya 1.jpg" width="1024" height="139" /></p> <form id="form1" name="form1" method="post" action=""> <label> <input type="submit" name="button" id="button" value="Logout" /> </label> </form> <p> </p> <form action="" method="post" name="form2" id="form2" onsubmit="return Validate();"> <fieldset> <legend class="cap">Create an Account</legend> <table width="75%" border="0" cellspacing="0" cellpadding="5" align="center"> <tr> <td> </td> <td class="title02"> </td> <td> </td> <td> </td> </tr> <tr height="30"> <td width="10%"> </td> <td width="25%" class="title02" align="left">Customer ID</td> <td width="55%" class="attribute1" align="left"><input type="text" name="customer_id" class="attribute1" /></td> <td width="10%"> </td> </tr> <tr height="30"> <td> </td> <td width="25%" class="title02" align="left">Account Type</td> <td width="55%" align="left" bgcolor="#FFFFFF" class="attribute1"><select name="account_type" id="jumpMenu" > <option selected="selected"></option> <option>Savings Investment</option> <option>Shakthi</option> <option>Surathal</option> <option>Abhimani Plus</option> <option>Yasasa Certificates</option> <option>Fixed Deposits</option> </select> </td> <td width="10%"> </td> </tr> </table> <p align="center"> </p> <p align="center"> <input type="submit" onclick="return Validate();" name="submit" value="Submit" class="attribute1" /> <input type="reset" name="reset" value="Reset" class="attribute1" /> <label> <input type="submit" name="button2" id="button2" value="Help" /> </label> </p> </fieldset> </td> <td width="5%"> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> <tr> <td> </td> <td><font color="red" size="1" ></font></td> <td> </td> </tr> </table> </form> <p> </p> <script language = "Javascript"> function Validate() { if (document.form2.customer_id.value == '') { alert('Please enter the valid customer id!'); return false; } else if ( document.form2.account_type.selectedIndex == '' ) { alert ( "Please select an account type!." ); return false; } return true; } </script> There are 6 different types of tables exist in my database representing 6 different types of accounts.Each and every table there is a field called "account number" which is auto incremented.When user clicks on submit button i want account number to be opened based on selected account type. How this could be done? Thanks, Heshan. Hi all, I want to create an array from the output of a table. In the table cell I have some numbers where for each number I would like to relate it to a value in another table. However using the code below I get Array ( => "26","27","28","29","30","31" ) from the print_r($arr); meaning that $range ins't being treated as an array, and hence, the second query only gives one value. Code: [Select] $showIng = mysql_query("SELECT * FROM recipe WHERE name = '$dish'") or die(mysql_error()); $rowShowIng = mysql_fetch_assoc($showIng); $range = $rowShowIng['keyno']; $arr = array($range); print_r($arr); foreach ($arr as &$value) { $getIng = mysql_query("SELECT * FROM keywords WHERE keyid = '$value'") or die(mysql_error()); $rowGetIng = mysql_fetch_assoc($getIng); echo $rowGetIng['ingredient']; } So, I want to know how I can create the array from $range Thanks Hi, I'm trying to make a dynamic html table to contain the mysql data that is generated via php. I'm trying to display a user's friends in a table of two columns and however many rows, but can't seem to figure out what is needed to make this work. Here's my code as it stands: Code: [Select] <?php //Begin mysql query $sql = "SELECT * FROM friends WHERE username = '{$_GET['username']}' AND status = 'Active' ORDER BY friends_with ASC"; $result = mysql_query($sql); $count = mysql_num_rows($result); $sql_2 = "SELECT * FROM friends WHERE friends_with = '{$_GET['username']}' AND status = 'Active' ORDER BY username ASC"; $result_2 = mysql_query($sql_2); $count_2 = mysql_num_rows($result_2); while ($row = mysql_fetch_array($result)) { echo $row["friendswith"] . "<br>"; } while ($row_2 = mysql_fetch_array($result_2)) { echo $row_2["username"] . "<br>"; } ?> The above simply outputs all records of a user's friends (their usernames) in alphabetical order. The question of how I'd generate a new row each time a certain amount of columns have been met, however, is beyond me. Anyone know of any helpful resources that may solve my problem? Thanks in advance =) Trying to write a webapp in PHP which works similar to VocalPitchMonitor app (Android) with some added features. But capturing voice and display it as wave format is possible in PHP? Is there any example script for this?
Hi all. I have the following function which auto-generates a form based on a database table. What I want to do is "cancel" the function if the table doesn't exist. The function as is... function build_form($table_name){ $sql="SELECT * FROM $table_name"; $result=mysql_query($sql); $num=mysql_num_rows($result); $i=0; echo "<form method=\"post\" action=\"/php/process_data.php\">"; echo "<input type=\"hidden\" name=\"selected_table\" value=\"" . $table_name . "\"/>"; echo "<table>"; echo "<tr><td colspan=\"2\" style=\"font:1em arial;font-weight:bold;text-align:center;\">Input Form: " . $table_name ."</td></tr>"; $field_names=array(); while ($i < mysql_num_fields($result)){ $fields=mysql_fetch_field($result,$i); echo "<tr><td>" . $fields->name . "</td><td><input type=\"text\" size=\"30\" name=\"" . $fields->name . "\" /></td></tr>"; $i++; }; echo "<tr><td colspan=\"2\" style=\"text-align:center;\"><input type=\"submit\" value=\"Submit Data\" style=\"width:75%\" /></td></tr>"; echo "</table>"; echo "</form>"; }; Would something like this work? (note lines 3-5) function build_form($table_name){ $sql="SELECT * FROM $table_name"; if(!$sql){ return; }; $result=mysql_query($sql); $num=mysql_num_rows($result); $i=0; echo "<form method=\"post\" action=\"/php/process_data.php\">"; echo "<input type=\"hidden\" name=\"selected_table\" value=\"" . $table_name . "\"/>"; echo "<table>"; echo "<tr><td colspan=\"2\" style=\"font:1em arial;font-weight:bold;text-align:center;\">Input Form: " . $table_name ."</td></tr>"; $field_names=array(); while ($i < mysql_num_fields($result)){ $fields=mysql_fetch_field($result,$i); echo "<tr><td>" . $fields->name . "</td><td><input type=\"text\" size=\"30\" name=\"" . $fields->name . "\" /></td></tr>"; $i++; }; echo "<tr><td colspan=\"2\" style=\"text-align:center;\"><input type=\"submit\" value=\"Submit Data\" style=\"width:75%\" /></td></tr>"; echo "</table>"; echo "</form>"; }; I've got. Hi
I have a form that has a drop-down with a few to choose from, unfortunately I don't get results for some due to the query involved.
Some need the AND channel LIKE '%$channel%'"; and some don't and therefore will not get desired results. So I would like to run two queries one with and one without.
$query = "SELECT * FROM asterisk_cdr WHERE calldate BETWEEN '$calldate' AND '$calldate2' AND clid LIKE '%$clid%' AND channel LIKE '%$channel%'";
Thanks
Hi, I have a simple html form. <form action="mail.php" method="POST"> <p>Name</p> <input type="text" name="name"> <p>Email</p> <input type="text" name="email"> <p>Phone</p> <input type="text" name="phone"> <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </form> I send a simple recap to e-mail through PHP. Simultaneously with this recapitulation, I would like to generate XML, which would send it in an e-mail attachment. Somehow it's not working. Would anyone help? <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message"; $recipient = "**************"; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; $doc = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $xmlRoot = $doc->createElement("xml"); $xmlRoot = $doc->appendChild($xmlRoot); $root = $doc->createElement('OrderDetails'); $root = $doc->appendChild($root); $ele1 = $doc->createElement('name'); $ele1->nodeValue=$name; $root->appendChild($ele1); $xml->saveXML(""); $mail->addStringAttachment($xml->asXML(), "xml.xml"); mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>"; ?> Thanks for any help!! Hi, This is my first post, so hopefully, you'll go easy on me. I'm a serious PHP newbie.. I have an form that calls a .php file. The php file is supposed to generate an email made up of the captured form fields and redirect the user to a 'thank you' page. The redirect works, but the email is not being generated. Here is my code: Code: [Select] <?PHP putenv("TZ=US/Central"); $time = date("M j, Y, g:i a"); $name = $_POST["name"]; $email = $_POST["email"]; $phone = $_POST["phone"]; $contact = $_POST["contact"]; $destination = $_POST["destination"]; $resort_brand = $_POST["resort_brand"]; $specific_resort = $_POST["specific_resort"]; $specialty_vacation = $_POST["specialty_vacation"]; $cruise_line = $_POST["cruise_line"]; $cruise_destination = $_POST["cruise_destination"]; $cruise_duration = $_POST["cruise_duration"]; $departDate = $_POST["departDate"]; $number_adults = $_POST["number_adults"]; $number_of_nights = $_POST["number_of_nights"]; $number_children = $_POST["number_children"]; $age1 = $_POST["age1"]; $age2 = $_POST["age2"]; $age3 = $_POST["age3"]; $age4 = $_POST["age4"]; $age5 = $_POST["age5"]; $passport = $_POST["passport"]; $handicapped = $_POST["handicapped"]; $comments = $_POST["comments"]; $recipient = "smarshall@stltoday.com, jmcginnis@post-dispatch.com, info@classictravelstl.com"; $subject = "Classic Travel quote request"; $body = "<p><b>Name:</b> $name<p><b>Email:</b> $email<p><b>Phone:</b> $phone<p><b>Contact:</b> $contact<p><b>Destination:</b> $destination<p><b>Resort Brand:</b> $resort_brand<p><b>Specific Resort:</b> $specific_resort<p><b>Specialty Vacation:</b> $specialty_vacation<p><b>Cruise Line:</b> $cruise_line<p><b>Cruise Destination:</b> $cruise_destination<p><b>Cruise Duration:</b> $cruise_duration<p><b>Departure Date:</b> $departDate<p><b>Number of Adults:</b> $number_adults<p><b>Number of Nights:</b> $number_of_nights<p><b>Number of Children:</b> $number_children<p><b>Age1:</b> $age1<p><b>Age2:</b> $age2<p><b>Age3:</b> $age3<p><b>Age4:</b> $age4<p><b>Age5:</b> $age5<p><b>Passport:</b> $passport<p><b>Handicapped:</b> $handicapped<p><b>Comments:</b> $comments"; $headers = "From: \"$name\" <$email>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "X-Mailer: Drupal\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $send = mail($recipient,$subject,$body,$headers); header( "Location: http://dmsgroup.co/classic-travel/thank_you.html" ) ; ?> The form that calls this file is he http://dmsgroup.co/classic-travel/request_info.html It was working at one point, but it's not anymore. Also, when it was working, the "specialty_vacation" field (which is a checkbox) would not pull in any data. Do I need to do something different to access checkboxes? Thanks in advance for your help! SteveMTNO Hello all, looking for some help here as I seem to be fairly stuck... this yields no results at all and I give up, I need help!
The user should be able to select an employee from a select field, and based on their selected we should be able to grab the start time and end time of that empoyee, which resides on the database.
My form:
<form action=".php" name="absence" id="absence" method="post"> Employee: <select name="empid" class="clockinputs" required> <option value=""></option> <option value='20'>Bob Jones</option> <option value='13'>Bob Phones</option> <option value='93'>Bob Lomes</option> <option value='30'>Bob Somes</option> <option value='107'>Bob Pomes</option> <option value='74'>Bob Womes</option> </select> Shift Start: <input type="text" name="startshift" id="startshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required> Shift End: <input type="text" name="endshift" id="endshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required> <input type="hidden" name="eid" value="<?php echo $row{'EID'}; ?>"> <input type="submit" value="Save"> </form>Javascript: <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('#empid').live('change', function(event) { $.ajax({ url : 'absence-get.php', type : 'POST', dataType: 'json', data : $('#absence').serialize(), success: function( data ) { for(var id in data) { $(id).val( data[id] ); } } }); }); }); </script>And absence-get.php: <?php $e = $_POST['empid']; $result = mysql_query("SELECT * FROM employees WHERE EID='$e' "); $row = mysql_fetch_array($result, MYSQL_ASSOC) $startshift = $row{'startshift'}; $endshift = $row{'endshift'}; $arr = array( 'input#startshift' => $startshift , 'input#endshift' => $endshift ); echo json_encode( $arr ); ?>Anyone spot anything? Thank you! Hi, I am trying to limit an user's input based on a text area size which is 180px. Is this even possible? There are ways to read how many linebreak's (\n) there are in a text area, but a long sentence will read as one linebreak. Any Ideaas? Hi All ,
I have a small table with 4 fields namely Day_ID, Dues, Last_Visit, Points. where Day_ID is an auto-increment field. The table would be as follows:
Day_ID -- Dues --- Last_Visit --- Points.
1 --------- 900 -------- 1/12 -------- 6
2 --------- 700 -------- 4/12 -------- 7
3 --------- 600 -------- 7/12 -------- 5
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
So this is the record of a person's visit to say a club. The last row indicates the last date of his visit to the club. His points on this date are 6. Based on this point value of 6 in the last row I want to retrieve all the previous BUT adjoining all records that have the same Points i.e. 6.
So my query should retrieve for me, based on the column value of Points of the last row (i.e. Day_ID - 6 ), as follows:
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
This problem stated above had been completely resolved, thanks to a lot of help from Guru Barand by this following query :-
$query = "SELECT cv.day_id, cv.dues, cv.last_visit, cv.points FROM clubvisit cv WHERE last_visit >= ( SELECT MAX(last_visit) FROM clubvisit WHERE points <> ( SELECT points as lastpoints FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) )";I am using this and it works perfectly except that now there is a slight change in the table because the criteria for points is now dependent on more than one column cv.points and is more like cv.points1, cv.points2, cv.points3 etc. So now I need to make a selection based on each of these cv.points columns. As of now I can still get the results by running the query multiple times for each of the cv.points columns ( seperately for cv.points1, cv.points2, cv.points3) and it works correctly. However I am wondering if there is a better way to do this in just one go. This not only makes the code repetitive but also since the queries are interconnected, involves the use of transactions which I wish to avoid if possible. The values that I require for each of the cv.point columns is 1. day_id of the previous / old day on which the cv.points value changed from the current day value, and 2. cv.points on that old/ previous day. So for example if the table is as below: Day_ID -- Dues --- Last_Visit --- Points1 --- Points2. 1 --------- 900 -------- 1/12 ----------- 9 ------------ 5 2 --------- 600 -------- 4/12 ----------- 6 ------------ 6 3 --------- 400 -------- 7/12 ----------- 4 ------------ 7 4 --------- 500 -------- 9/12 ----------- 5 ------------ 8 5 --------- 600 -------- 10/12 ---------- 6 ------------ 8 6 --------- 600 -------- 11/12 ---------- 6 ------------ 8 7 --------- 600 -------- 13/12 ---------- 6 ------------ 7 8 --------- 500 -------- 15/12 ---------- 5 ------------ 7 9 --------- 500 -------- 19/12 ---------- 5 ------------ 7 Then I need the following set of values : 1. day_id1 -- Day 7, points1 ---- 6, days_diff1 -- (9-7 = 2) . // Difference between the latest day and day_id1 2. day_id2 -- Day 6, points2 ---- 8, days_diff2 -- (9-6 = 3) 3. day_id3 -- .... and so on for other points. Thanks all ! |