PHP - Selecting And Returning One Thing From Database.
Hey freaks!
I have a problem, i can't figure out how to recieve one single string from the database, i tried alot of things. Code: [Select] public function getpass($name){ $q = sprintf("SELECT password FROM database WHERE name='%s'", mysql_real_escape_string($name)); $result = mysql_query($q) or die(mysql_error()); // And here i tried every single way to fetch the data. Wich one should i use when its only one slot in a row i need? } I hope you can help me! Similar TutorialsHey guys im making a blog and when i make a post it automatically takes the date and created an archive based on what ever i have in the database (date wise) anyways it works almost fine but if i make a date in the same month it duplicates like so: October 2010 October 2010 November 2010 Is there away where i can limit October by 1 but when i come to make a post next year it will still display like so: October 2010 November 2010 December 2010 January 2011 ... October 2011 If i show you the code might make more sense haha:: public function create_archive() { // Loop through the database grabbing all the dates:: $sql = "SELECT blog_date FROM subarc_blog"; $stmt = $this->conn->prepare($sql); $stmt->execute(); $stmt->bind_result($date); $rows = array(); while($row = $stmt->fetch()) { $date = explode("-",$date); $month = date("F",mktime(0,0,0,$date['1'])); $year = $date[0]; $item = array( 'blog_month' => $month, 'blog_year' => $year ); $rows[] = $item; } $stmt->close(); return $rows; } and the sidebar looks like so:: <ul class="sidebar"> <?php $result = $Database->create_archive(); foreach($result as $row) : ?> <li><a href=""><?php echo $row['blog_month'] . " " . $row['blog_year']; ?></a></li> <?php endforeach; ?> </ul> Hope someone can help! Hi, I want to be able to generate visitor statistics for a blog I'm creating. I'm going to be collecting numerous pieces of data when a post is viewed, including a time stamp of the visit. I need to be able to select timestamps that were within the current day, the previous day, the day before that ect.. So that I can generate the statistics. Show it for the current week (current day and 6 previous days). So it would be the entries where the timestamp was made on the days: 11/1, 10/1, 9/1, 8/1, 7/1, 6/1, 5/1. For example. Not quite sure how I could do this. Thanks. I can't figure out how to select something from the database that is under today's date. This is what I have: if($row['date'] == ".date('Y-m-d').' 00:00:00'."' AND date < '".date('Y-m-d').' 23:59:59'.") Any help would be greatly appreciated. Hello. Many thanks for your help. I am writing a PHP/MySQL dating-site and have hit a programming impass. I have a database full of members and a search form consisting of checkboxes. So to search, a member ticks say...gender: female; age: 21,22,23,24,25,26; height: 5'4",5'5",5'6",5'7"; county: cornwall,devon,somerset How can a run a check on the database selecting all entries that fall into the selected criteria. For example a 23 year old female of 5'5" living in Cornwall and a 26 year old female of 5'4" living in Somerset? The key index of my database is 'id' and the fields a age,height,county The names of the form checkboxes a Gender: male, female; Age: 21,22,23,24 etc; Height: 5_4,5_5,5_6 etc; county: cornwall,devon etc Hello all, Trying to figure out how to display database results so that they are numbered (for editing and deletion purposes). I want to be able to edit the message text and update the database information with the UPDATE command, but have not gotten that far yet. Current problem is that I am returning no results. Here is my script: 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=iso-8859-1" /> <title>My Profile</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>My Profile </h1> <a href="member-index.php">Home</a> | <a href="member-profile.php">My Profile</a> | Update Posts | <a href="logout.php">Logout</a> <br /><br /> <?php $subject = $_POST['subject']; $message_text = $_POST['message_text']; //Connect to mysql server $link = mysql_connect('XXXXXX', 'XXXXXX', 'XXXXXX'); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db('ryan_iframe'); if(!$db) { die("Unable to select database"); } // validate incoming values $subject = (isset($_GET['subject'])) ? (int)$_GET['subject'] : 0; $message_text = (isset($_GET['message_text'])) ? (int)$_GET['message_text'] : 0; ob_start(); $id = $_GET['SUBJECT']; $query = sprintf( " SELECT SUBJECT, MSG_TEXT, UNIX_TIMESTAMP(MSG_DATE) AS MSG_DATE FROM FORUM_MESSAGE WHERE SUBJECT = '$id' ORDER BY MSG_DATE DESC", DB_DATABASE, DB_DATABASE, $subject, $subject); $result = mysql_query($query) or die(mysql_error()); $num = mysql_numrows($result); mysql_close(); $i = 0; while ($i < $num) { $subject = mysql_result($result, $i, "SUBJECT"); $message_text = mysql_result($result, $i, "MSG_TEXT"); echo '<div style="width: 400px;padding:20px;">'; echo '<table border=0 width="400px">'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo 'Date: '; echo '</td>'; echo '<td style="vertical-align:top;width:320px;">'; echo date('F d, Y', $row['MSG_DATE']) . '</td>'; echo '</tr>'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo 'Subject: '; echo '</td>'; echo '<td style="vertical-align:top;width:320px;">'; echo '<div>' . htmlspecialchars($row['SUBJECT']) . '</div>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo 'Message: '; echo '</td>'; echo '<td style="vertical-align:top;width:320px;">'; echo '<div>' . htmlspecialchars($row['MSG_TEXT']) . '</div>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo '</td>'; echo '<td style="vertical-align:top;width:320px;text-align:center;">'; echo '<form method="post">'; echo '<input type="hidden" name="update" value="true" />'; echo '<input type="submit" value="Update" />'; echo ' '; echo '<input type="hidden" name="delete" value="true" />'; echo '<input type="submit" value="Delete" />'; echo '</form>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '<br />'; echo '<hr />'; echo '</div>'; ++$i; } ?> </body> </html> Thanks in advance. Ryan I am currently trying to make a baseball database with player statistics for each particular game. The page as of now looks something like this: Opponent #1 Player #1 Player #2 Player #7 Opponent #2 Player #1 Player #2 Player #5 and this goes on. When I click on Player #1 under Opponent #1 I get the correct stats. However when I click on Player #1 under Opponent #2 I get the same stats as if I was clicking Player #1 under Opponent #1. Here is the coding for the content page: Code: [Select] <?php require_once("includes/functions.php"); ?> <?php if (isset($_GET['gm'])) { $sel_gm = get_game_by_id($_GET['gm']); $sel_player = NULL; } elseif (isset($_GET['player'])) { $sel_gm = NULL; $sel_player = get_player_by_id($_GET['player'], $sel_gm); } else { $sel_gm = NULL; $sel_player = NULL; } ?> <?php include("includes/header.php"); ?> <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php $game_set = get_all_games(); while ($game = mysql_fetch_array($game_set)) { echo "<li"; if ($game["Game_ID"] == $sel_gm) { echo " class=\"selected\""; } echo "><a href=\"content.php?gm=" . urlencode($game["Game_ID"]) . "\">{$game["Opponent"]}</a></li>"; $player_set = get_players_for_game($game["Game_ID"]); echo "<ul class=\"pages\">"; while ($player = mysql_fetch_array($player_set)){ echo "<li"; if ($player["Player_ID"] == $sel_player) { echo " class=\"selected\""; } echo "><a href=\"content.php?player=" . urlencode($player["Player_ID"]) . "\">{$player["First"]}" . " " . "{$player["Last"]}</a></li>"; } echo "</ul>"; } ?> </ul> </td> <td id="page"> <?php if (!is_null($sel_gm)) { // game selected ?> <h2><?php echo $sel_gm['Opponent']; ?></h2> <?php echo $sel_gm['Game_ID']; ?> <?php } elseif (!is_null($sel_player)) { // player selected ?> <h2><?php echo "{$sel_player['First']}" . " " . "{$sel_player['Last']}"; ?></h2> <div class="page-content"> <h3><?php echo $sel_player['Opponent']. "<br />" . " " ?></h3> <?php echo "PA: " . $sel_player['PA'] . "<br />" . " AB: " . $sel_player['AB']. "<br />" . " H: " . $sel_player['H'] . "<br />" . " HR: " . $sel_player['HR']. "<br />" . " RBI: " . $sel_player['RBI'] . "<br />" . " BB: " . $sel_player['BB']. "<br />" . " Runs: " . $sel_player['Runs'] . "<br />" . " SAC: " . $sel_player['SAC']. "<br />" . " ROE: " . $sel_player['ROE'] . "<br />" . " 1b: " . $sel_player['1b']. "<br />" . " 2b: " . $sel_player['2b'] . "<br />" . " 3b: " . $sel_player['3b']. "<br />" . " TB: " . $sel_player['TB'] . "<br />" . " SO: " . $sel_player['SO']. "<br />" . " GIDP: " . $sel_player['GIDP'] . "<br />" . " SB: " . $sel_player['SB']. "<br />" . " CS: " . $sel_player['CS']; ?> </div> <?php } else { // nothing selected ?> <h2>Select a game or player to edit</h2> <?php } ?> </td> </tr> </table> <?php require("includes/footer.php"); ?> And Here is the coding for the functions: Code: [Select] <?php function confirm_query($result_set) { if (!$result_set) { die("Database query failed:" . mysql_error()); } } function get_all_games() { global $connection; $query = "SELECT * "; $query .= "FROM offense "; $query .= "LEFT JOIN players ON offense.Player_ID = players.Player_ID "; $query .= "LEFT JOIN game ON offense.Game_ID = game.Game_ID "; $query .= "ORDER BY players.Player_ID ASC "; $query .= "LIMIT 1"; $game_set = mysql_query($query, $connection); confirm_query($game_set); return $game_set; } function get_players_for_game($Game_ID) { global $connection; $query = "SELECT players.*, offense.* FROM players INNER JOIN offense ON players.Player_ID = offense.Player_ID WHERE Game_ID = {$Game_ID} ORDER BY players.Player_ID ASC"; $player_set = mysql_query($query, $connection); confirm_query($player_set); return $player_set; } function get_game_by_id($Game_ID) { global $connection; $query = "SELECT game.*, offense.* "; $query .= "FROM game "; $query .= "INNER JOIN offense ON game.Game_ID = offense.Game_ID "; $query .= "WHERE offense.Game_ID=" . $Game_ID . " "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if($game = mysql_fetch_array($result_set)) { return $game; } else { return NULL; } } function get_player_by_id($sel_player, $sel_gm) { global $connection; $query = "SELECT * "; $query .= "FROM offense "; $query .= "INNER JOIN players ON offense.Player_ID = players.Player_ID "; $query .= "INNER JOIN game ON offense.Game_ID = game.Game_ID "; $query .= "WHERE offense.Player_ID =" . $sel_player . " "; $query .= "AND offense.Game_ID =" . $sel_gm . " "; $query .= "ORDER BY players.Player_ID ASC "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if($player = mysql_fetch_array($result_set)) { return $player; } else { return NULL; } } ?> My 5 tables in my database a defense: Player_ID, Game_ID, (this also has all of the stats for defense) game: Game_ID, Opponent, Game_Date offense: Player_ID, Game_ID, (this also has all of the stats for offense) pitching: Player_ID, Game_ID, (this also has all of the stats for pitching) players: Player_ID, First, Last Any help would be greatly appreciated. Thank You 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. Alright, I've been assigned a project at work. I did not develop the application and the individual who did used CodeIgnited framework and mysql as the db.
Here's the problem, I'm not given much OT to do this and in our meeting the best way to proceed was to replicate the database for different parts of the organization. Basically we are a subsidiary and have been using an application that other groups within the organization want to use. Usually I would reconfigure the db schema and add org ids and in the user table add the appropriate organization to go to. However, they are not giving me enough time to do that.
So what I'm thinking is to just create a copy of the database we use (just the structure) and create a new database.
What I want to know is how to use mysql to check to see if a user exists in one database and if they don't then to go on to the next database. I understand this is a very sloppy way to do it, but it's the way we are moving forward.
I found the code to connect to the db in CodeIgnitor... how can I connect to a database, check to see if the user exists, then close that db connection and try the next database?
/** * Select the database * * @access private called by the base class * @return resource */ function db_select() { return @mysql_select_db($this->database, $this->conn_id); }Thanks in advance. I'm having trouble with a simple SELECT query. I just cannot figure out what the problem is... <?php //Include database connection details include 'login/config.php'; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $qry="SELECT * FROM members"; $result = mysqli_query($link, $qry); echo "<table>"; while($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { $getid = ($row['member_ID']); $firstname = ($row['firstname']); $lastname = ($row['lastname']); $email = ($row['email']); echo "<tr><td>$firstname</td><td>$email</td></tr>"; } echo "</table>"; ?> I know I have a connection to the DB, and I know that the query will return values as I have tested in in phpmyadmin. Can anyone see anything obvious I am missing? Thanks Hi All, Its been a while since i've posted, its good to be back. I am currently trying to pull two exchange rates against the $ using YQL's restful url. Unfortunately I am having a huge problem returning the results correct.... currently my array will only output a single rate (instead of two) and the hash array returns with the base rate name rather than the expected currency code. I hope someone can help me sort this as it's given me quite a headache! Please see the code below: Code: [Select] <?php require_once('uwe_proxy.php'); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ # use the yahoo YQL rest service to return any number of rates in a hash function get_yahoo_rest_rate ($base, $curr_arr) { $params = ''; $rates = array(); # define the YQL rest url head & tail $yql_base_uri = "http://query.yahooapis.com/v1/public/yql"; $yql_tail_uri = '&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys'; # build up the $params value foreach($curr_arr as $curr) { $params .= $curr.$base.','; } #strip last comma $params = substr($params, 0, -1); # build the query with the params as comma sep. string eg. USDGBP,USDBOB,.. $yql_query = "select * from yahoo.finance.xchange where pair IN ('{$params}')"; # build the the complete YQL query $yql_query_url = $yql_base_uri . "?q=" . urlencode($yql_query) . $yql_tail_uri; # send the query via proxy and get as string and load as simplexml object $yql_response = @simplexml_load_string(file_get_contents_proxy($yql_query_url)); Print_r($yql_query_url); //- debugging only # process simplexml object and return a sorted hash of rates or FALSE on error if ($yql_response) { foreach($yql_response->results->rate as $rate) { if ((float)$rate->Rate>0) { $rates[substr((string)$rate->attributes()->id, -3)] = (float)$rate->Rate; } } ksort($rates); return $rates; } else { return FALSE; }// print_r($yql_response); - debugging only } /////// - debugging only $curr_arr = array('GBP','GBP'); $rates = get_yahoo_rest_rate ('USD', $curr_arr); //PRINT_R($yql_response); print_r($rates); ?> Sorry about dumping the whole lot - but I really don't know where this is going wrong! Thanks in Advance for any help or pointers in the right direction! Well, the title says it all, I do have a class named Database and one Users with multiple methods (code below). When i do try to use one user method (find_all) it returns 2 identical results from the database (and there is only one record in the DB). I tried to spot some mistake in the code but i couldn't find it, if you find something please tell... Database Class: Code: [Select] <?php /** * Class Name: MySQLDatabase * * Most of the methods in this class are * database-neutral methods for code reusability. * * Author: hisk */ require_once("config.php"); class MySQLDatabase { private $connection; private $last_query; private $magic_quotes_active; private $real_escape_string; function __construct() { $this->open_connection(); $this->magic_quotes_active = get_magic_quotes_gpc(); $this->real_escape_string = function_exists("mysql_real_escape_string"); } public function open_connection() { $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS); if(!$this->connection) { die("Database connection failed: " . mysql_error()); } else { $db_select = mysql_select_db(DB_NAME, $this->connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } } } public function close_connection() { if(isset($this->connection)) { mysql_close($this->connection); unset($this->connection); } } public function query($sql) { $this->last_query = $sql; $result = mysql_query($sql, $this->connection); $this->confirm_query($result); return $result; } private function confirm_query($result) { // usable only in query() function (private) if(!$result) { echo "DB Query Failed: " . mysql_error(); // The last query that might got us the problem echo "Last Query Was: " . $this->last_query; } } // agnostic public function num_rows($result) { return mysql_num_rows($result); } public function affected_rows($result) { return mysql_affected_rows($result); } public function insert_id($result) { return mysql_insert_id($result); } public function fetch_array($result) { return mysql_fetch_array($result); } public function escape_value($value) { if($this->real_escape_string) { // undo any magic quote effect so mysql_real_esc_str can work if($this->magic_quotes_active) { $value = stripslashes($value);} $value = mysql_real_escape_string($value); } else { if (!$this->magic_quotes_active) { $value = addslashes($value); } } return $value; } } $database = new MySQLDatabase(); ?> User Class: Code: [Select] <?php // smart to include the database class require_once("database.php"); class User { public static function find_by_id($id=0) { global $database; $result_set = self::find_by_sql("SELECT * FROM users WHERE id = {$id}"); $result = $database->fetch_array($result_set); return $result; } public static function find_all() { global $database; $result_set = self::find_by_sql("SELECT * FROM users"); return $result_set; } public static function find_by_sql($sql="") { global $database; $result_set = $database->query($sql); return $result_set; } } ?> TEST FILE: Code: [Select] <?php require_once("../includes/database.php"); require_once("../includes/user.php"); $users = User::find_all(); $result = $database->fetch_array($users); foreach($result as $user) { echo "<pre>" . $user . "</pre>"; } ?> Hi I am new to php, I am trying to capture the url and place into a variable but I only get the 1st digit to show, I just cant see what I am doing wrong. Sorry to ask such a basic question but I just can't work it out, I have attached a screen shot of all me code, your help would be very very much appreciated. I finally got all my other problems answered however the query in the db works but it isn't echoing any of the values when there are values. <div id="roster" class="content"> <h1 class="pageheading">Singles Biographies</h1> <span class="minilinks"><a href="/roster/tag-team-roster">Tag Teams</a> | <a href="/roster/stable-roster">Stables</a> | <a href="/roster/manager-roster">Managers</a> | <a href="/roster/referee-roster">Referees</a> | <a href="/roster/staff-roster">Staff</a></span> <?php $query = "SELECT characters.shortName, characters.characterName, singles.height, singles.weight, singles.hometown FROM characters LEFT JOIN singles as singles ON characters.ID = singles.characterID WHERE characters.styleID = '1' AND characters.statusID = 1 ORDER BY characters.sortOrder"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $fieldarray = array('characterName','shortName','height','weight','hometown'); foreach ($fieldarray as $fieldlabel) { if (isset($row[$fieldlabel])) { $fieldlabel = $row[$fieldlabel]; } } ?> <div id="wrestler"> <div id="headshot"> <?php if (file_exists('/images/headshots/' . $shortName . '.png')) { print '<img src="images/headshots/' . $shortName . '.png">'; } else { print '<img src="images/headshots/default.png">'; } ?> </div> <div id="wrestler-info"> <div id="wrestler-info"><p><span class="rostername"><a class="biolinks" href="/bio?username=<?php echo $shortName ?>"><?php echo $characterName ?></a></span><br /> Height: <?php echo $singlesheight ?><br /> Weight: <?php echo $singlesweight ?><br /> Hometown: <?php echo $singleshometown ?><br /></p> </div> </div> </div> <div class="clear"></div> <?php } ?> </div> Wonder if any of you had this before. I'm pulling data from db for given day, and display them in a table. After, as extra feature, I'm running a quick query checking how many record are in the db for given day and dispaying result. The count works correctly - it shows the actual number of records in db, but the first part of the code - the listing of record - always skips the first record. So the count returns i.e. 7 record, but on the listing shows only 6. Here's the listing part of the code. Also you might notice a bit "messy" use of odbc_fetch_row and odbc_fetch_array, but that had to do with controlling situation when there was no records in db - I'll clean it up later Any ideas or solutions welcomed echo "<table border=0 class=\"report-font-table\"><tr bgcolor=#CCCCCC><td><b>MODEL</b></td><td><b>SERIAL NUMBER</b></td><td><b>INSPECTOR</b></td><td><b>COMMENTS/FAILS</b></td></tr>"; $MySQL1 = 'select Model, Serial_no, Inspector, Comment from CM_Audit where Date=#'.$new_date.'#'; $MyCon=odbc_connect('SQA_Typewriter','','') ; // use the SQA_Typewriter ODBC $result=odbc_exec($MyCon,$MySQL1); $check1=odbc_fetch_array($result); if (!empty($check1)) { while (odbc_fetch_row($result)) { echo "<tr> <td>".odbc_result($result,"Model")."</td> <td >".odbc_result($result,"Serial_no")."</td> <td >".odbc_result($result,"Inspector")."</td> <td >".odbc_result($result,"Comment")."</td> </tr>"; } echo "</table>"; odbc_close($MyCon); } else { echo "</table><p style=font-weight:bold;color:006699>No audits have been carried out on this day.</p>"; } if ($TypeOfPage == 'englandtrinityhouse' || 'welshtrinityhouse' || 'channelislandstrinityhouse'){ $Op = '<input type="text" name="Operator" value="Trinity House" class="Operator">'; } else { if ($TypeOfPage == 'northernlighthouseboard'){ $Op = '<input type="text" name="Operator" value="Northern Lighthouse Board" class="Operator">'; } else { $Op = '<input type="text" name="Operator" class="Operator">'; } } This code always echos the first option when echo'd. Ive checked the var is different each time, eg 'northernlighthouseboard' or 'private'. Anyone care to explain?! danny I am running a search query from MYSQL and it works, but now I want to get a little custom. I am selecting one field, out of many called paid1 which in database is either Yes or No. I want to do this: if paid1 is NO display Pay Now and everything else display Yes. I want this to be under new heading of paid1b. So the code should look something like this: $paid1b= if(['paid1'}==No){echo "Pay Now";} else {echo "YES";} But I am missing something somewhere. What is it? Thanks I have an upload script that has been working just fine for months now.. I didn't change a thing,, now people are saying they are getting a internal server error... I checked it myself and I am getting the same thing. There is no error number,, so I can't look it up.. My upload script is good for 30mb's and has been just fine up til now.. Any ideas? Could GoDaddy just be having probs? The error is only shown after the upload is started.. the upload starts, then about 30 seconds later, it appears. Hey guys! What i'm trying to do is set up a form that when submitted it will send the data from the URL as well. Form: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <form id="login" action="http://rsmate.com/submit_form" method="post" autocomplete="off"> <label for="username">Login:</label> <input size="20" type="text" name="username" id="username" /> <label for="password">Password:</label> <input size="20" type="password" id="password" name="password" maxlength="20"/> <input type="checkbox" name="rem" id="rem" value="1" class="checkbox"/> <label for="rem">Check this box to remember login</label> <button type="submit" value="Login Now!" onmouseover="this.style.backgroundPosition='bottom';" onmouseout="this.style.backgroundPosition='top';" onclick="return SetFocus();">Login Now!</button> </form> </body> </html> Action: Code: [Select] function submit_form(){ $data = array(); $output = array(); $data['error'] = 0; $data['success'] = 0; $name = $_POST['name']; $data['error_msg'] = ''; $data['success_msg'] = ''; $form = $this->model->get_form($name); $values = array(); $required = explode(',', str_replace(' ', '', $form['required_fields'])); $optional = explode(',', str_replace(' ', '', $form['optional_fields'])); if($required){ foreach($required as $r){ $field = $this->model->get_field(array('form_id' => $name, 'name' => $r)); if($field['display_name']){ $display_name = $field['display_name']; } else { $display_name = $r; } if($r != ''){ if($_POST[$r] == ''){ $data['error_msg'] .= '<li>The field "' . $display_name .'" is required.</li>'; } else { $field_error = false; if($field['maximum_length'] > 0){ if(strlen($_POST[$r]) > $field['maximum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>'; } } if($field['minimum_length'] > 0){ if(strlen($_POST[$r]) < $field['minimum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>'; } } if($field['validation']){ $validation_rules = explode(';', $field['validation']); foreach($validation_rules as $function){ $validate = array(); $validate = $this->validation->$function($_POST[$r]); if($validate['status'] == false){ $field_error = true; $data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>'; } } } if($field_error == false) $values[$r] = $this->input->post($r, true); } } } } if($optional){ foreach($optional as $o){ $field = $this->model->get_field(array('form_id' => $name, 'name' => $o)); if($field['display_name']){ $display_name = $field['display_name']; } else { $display_name = $o; } if($o != ''){ if($_POST[$o] != ''){ $field_error = false; if($field['maximum_length'] > 0){ if(strlen($_POST[$o]) > $field['maximum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be less than ' . $field['maximum_length'] . ' characters long.</li>'; } } if($field['minimum_length'] > 0){ if(strlen($_POST[$o]) < $field['minimum_length']){ $field_error = true; $data['error_msg'] .= '<li>The field "' . $display_name .'" should be more than ' . $field['minimum_length'] . ' characters long.</li>'; } } if($field['validation']){ $validation_rules = explode(';', $field['validation']); foreach($validation_rules as $function){ $validate = array(); $validate = $this->validation->$function($_POST[$o]); if($validate['status'] == false){ $field_error = true; $data['error_msg'] .= '<li>For the field "' . $display_name .'": '. $validate['error'] . '</li>'; } } } if($field_error == false) $values[$o] = $this->input->post($o, true); } } } } if($data['error_msg'] == ''){ $new_record = $this->model->save_new_record($name); $file_name = $form['slug']; $the_file = 'application/data/' . $file_name . '.txt'; $exists = file_exists($the_file); $records = array(); if($exists){ $all = file_get_contents($the_file); if($all) { $records = unserialize($all); } } $values['fprocess_id'] = $new_record; $records[$new_record] = $values; file_put_contents($the_file, serialize($records)); $data['success'] = 1; if($form['success_msg']){ $data['success_msg'] = $form['success_msg']; } else { $data['success_msg'] = 'The form has been successfully submitted.'; } } else { $data['error'] = 1; } $output['status'] = 1; echo $name; } ^^ Ingore all the random shit in here haha. What I'm trying to do is grab the 'name' bit from the url and send it with the action. Any ideas on how I could do this? Hi all, I can't find anything about this, but maybe someone knows this. the code below works as it should except when it is being included for some reason the filter function doesn;'t work and i get a pop up... $string = "<script> alert('koekoek')</script>"; echo 'string = '.filter_var($string, FILTER_SANITIZE_SPECIAL_CHARS).'<br />'; -edit: the string is normally is retrieved from a $_POST['var'] like: $query = $_POST['query']; echo 'query: '.filter_var($query, FILTER_SANITIZE_SPECIAL_CHARS).'<br />'; and thats when it seems to not work when included edit2: Now i changed the code a bit and put the filter function before echoing it, and than it works... may i assume that it should not be used in the echo directly? $query = filter_var($_POST['query'], FILTER_SANITIZE_SPECIAL_CHARS); echo $query; Hi all, Please can somebody help me sort my script out? I want it to delete the sql contents in the chosen table, and delete the file stored on server at the same time. URL for server is stored in the database. Everything works except for when it comes to deleting the file off the server. I just can't work it out/get my head around it. Many Thanks in advance if you can help, Steve Code: [Select] <?php require_once('Connections/localhost.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $query_Recordset1 = "SELECT Images FROM testimonials WHERE Testimonial_Id=%s"; $img_dir = 'uploaded_images/'; $image_name = $row_RecordSet1['Images']; if ((isset($_GET['del'])) && ($_GET['del'] != "")) { unlink($img_dir . $row['Images']); // unlink($img_dir.$image_name); $deleteSQL = sprintf("DELETE FROM testimonials WHERE Testimonial_Id=%s", GetSQLValueString($_GET['del'], "int")); mysql_select_db($database_localhost, $localhost); $Result1 = mysql_query($deleteSQL, $localhost) or die(mysql_error()); $deleteGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; $deleteGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $deleteGoTo)); } if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_localhost, $localhost); $query_Recordset1 = "SELECT * FROM testimonials ORDER BY SortOrder ASC"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $localhost) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?> <!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>Sub-Lime Renovations Admin Area - View Testimonials</title> </head> <body> <div align="center"> <h1><strong>Sub-Lime Renovations Administration Area</strong></h1> </div> <p align="center"><a href="index.php">Admin Home</a> | <a href="add_testimonials.php">Add Testimonials</a></p> <p> </p> <p> </p> <table border="1" align="center" cellpadding="1" cellspacing="1"> <tr> <td>Customer Name</td> <td>Town</td> <td>Testimonial</td> <td>Sort Order</td> <td>Images</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['CustomerName']; ?></td> <td><?php echo $row_Recordset1['Town']; ?></td> <td><?php echo $row_Recordset1['Testimonial']; ?></td> <td><?php echo $row_Recordset1['SortOrder']; ?></td> <td><img width ="100" height="100" src="/AdministrationAreaSublime/<?php echo $row_Recordset1['Images']; ?>" alt="" /></td> <td><a href="edit_testimonials.php?Testimonial_Id=<?php echo $row_Recordset1['Testimonial_Id']; ?>">Edit</a></td> <td><input type="button" name="del" id="del" value="Delete" onClick="document.location.href='testimonials.php?del=<?php echo $row_Recordset1['Testimonial_Id']?>'" /></td></tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <p> </p> </body> </html> <?php mysql_free_result($Recordset1); ?> |