PHP - Trouble Removing Certain Letters From Post Prior To Insert
I want to remove the HTTP:// or HTTPS:// from the insert into the DB. The Viewer may put just www, or copy the entire URL with the HTTP:// or HTTPS://
I tried using the preg-replace but couldn't seem to get it to work.
Any other recommendation?
Thanks in advance,
Mike
Similar TutorialsHey everyone, so im trying to utilize a systems OPTION command send prior to the POST command, the OPTION command will for example state that it would like to request specific headers. im trying to perform this to get the headers needed before the POST command im trying to execute, the values are required for the POST command i need to perform to get a response. The URL in question would be: https://media-entitlement.mlb.com/api/v3/jwt?os=windows&did=ffeae86c-9447-4bac-a021-caad0c02c605&appname=mlbtv_web Request method: OPTIONS (to get required headers):
Host: media-entitlement.mlb.com then a post command is performed just after which retrieves the values originally requested by the OPTIONS command prior to the POST:
Host: media-entitlement.mlb.com
Now Generally speaking, i fully understand their authorization etc. but this specific set of values seem only used in this one situation, they use bam-sdk which i understand pretty well. but needless to say this authorization bearer, and api-key value only seem generated via the initial OPTIONS grab in browser. so in summary i need to understand how these OPTIONS commands can be utilized to store the required headers as a variable which can be used in the POST command. Thanks in advance for your time and energy responding. mosb3rgler Edited June 14, 2019 by mosb3rglertypo Hi all I'm working on a form, i've gotten all the values from the form to the process.php page and it is assigning the correct variables but i can't get it to insert into the database, i know the connection info is correct as i have other page connecting and i can create a recordset on that page. i guess my sql is wrong any help much appreciated. the following is the sql from the database and attached is the process.php page. -- Table structure for table `details` -- CREATE TABLE `details` ( `id` int(6) NOT NULL auto_increment, `first_name` varchar(20) NOT NULL, `sur_name` varchar(20) NOT NULL, `sex` varchar(6) NOT NULL, `age` varchar(3) NOT NULL, `house_no` varchar(5) NOT NULL, `street` varchar(150) NOT NULL, `town` varchar(50) NOT NULL, `bro_sis_cous_friend1` varchar(50) default NULL, `bscf_name1` varchar(150) default NULL, `and` varchar(4) NOT NULL, `bro_sis_cous_friend2` varchar(50) default NULL, `bscf_name2` varchar(150) default NULL, `his_her` varchar(4) default NULL, `him_her` varchar(4) default NULL, `from_name` varchar(150) NOT NULL, `photo_link` varchar(255) default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ; [attachment deleted by admin] could someone help me with this. here is what I have: <?php require_once('dbinfo.php'); ?> <?php mysql_connect($dbaddress,$username,$password); mysql_select_db($db) or die("Cannot find database!"); /* $query = "SELECT * FROM contacts"; $result = mysql_query($query); $numRows = mysql_numrows($result); $i = 0; while ($i < $numRows) { echo mysql_result($result, $i, "first") . " " . mysql_result($result, $i, "last"); $i++; } */ $fname = 'WrdScramble()'; $ftype = 'DAO'; $fdesc = 'Randomly rearranges the characters in a string or word.'; $fcode = ''; $query = "INSERT INTO functions VALUES ('','$fname','$fcode','$ftype','$fdesc')"; mysql_query($query); print($query); //$query = "SELECT fcode FROM contacts WHERE first = 'code'"; //$result = mysql_query($query); //$numRows = mysql_numrows($result); //$fcode = mysql_result($result, 0, "fcode"); ?> <? //close connection mysql_close(); ?> It is not inserting the data into the database, and if I use: mysql_error() and print it out, I get nothing with that either. I am not sure where to go! I also have used this: (fid, fname, fcode, ftype, fdesc) preceeding the 'VALUES' word in the statement just to see if it would take. No luck! Do I not see the obvious? Any help appreciated! thanks! (I have checked my field types and max length in PHPmyadmin and they are not an issue.) when i remove the action from the form it submits the post correctly if not it goes to the action url withoutposting Code: [Select] <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="_top" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="wwww"> <?php <input type="hidden" name="item_name" id="item_name" value="<?php echo $md5c;?>"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Submit Form"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> <?php if(isset($_POST['submit_x']) || isset($_POST['submit_x'])) { //$Subscription_id = mysql_real_escape_string($md5c); $PropertyID = mysql_real_escape_string($rowData['ID']); $User_ID = mysql_real_escape_string($rowData['User_ID']); $item_name=mysql_real_escape_string($_POST['item_name']); //$query = 'INSERT INTO SP_subscriptions(id,) values("'.$item_name.'")'; $query = 'INSERT INTO SP_subscriptions(id,PropertyID,User_ID) values("'.$item_name.'","'.$PropertyID.'","'.$User_ID.'")'; $success = mysql_query($query); echo $query; } else echo 'POST nada'; var_dump($_POST); var_dump($query); ?> I am trying to create a query to insert data into a table in my Access database. I have the following query:
INSERT INTO Issues (DateRequested, CustomerID, ComputerID, Issue, ItemsIncl, ImageName) VALUES (#1/14/2015#, 1, 1, "Computer freezes while I'm on the internet.", "AC Adapter", "none.gif")which should be performed from within my PHP page. However, when I check the database afterward, the new record isn't there. I then tried performing the query directly in Access and it worked fine. Why would it work in Access, but not when I run the same query in PHP? Chris Hi - I have an HTML form which is dynamically produced using CodeIgniter / PHP and presents products a customer has ordered. When the customer has finished changing his quantities they must now submit the form. My problem is that my form will contain many of the same named fields for example, 'Product ID', or 'Product Name' or 'quantity'. So now when it gets processed a typical post array like product id could look like this: Code: [Select] Array ( [0] => 28 [1] => 24 [2] => 101 [3] => 23 [4] => 17 ) Of course I get an error: Quote Severity: Notice Message: Array to string conversion Filename: mysql/mysql_driver.php I really need some advice on how I should pre-process the various POST arrays so I can get them into my DB. A very grateful student of PHP ! Thanks Ok .I tried to look for the problem for about 1 hour but I can't see what's wrong whit the following code: In firebug the post values appear correctly like so:id=116&usern=asdawe&com=qweqw&page=116&submit=submit and the inserc() function works correctly because i tried it whit a array of data created by my; Code: [Select] <?php if(isset($_POST['submit'])) { $comment = new comment; $comment->storeform($_POST); $comment->insertc(); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<?php echo $result['article']->id ?>"/> <ul> <li> <input type="text" name="usern" id="usern" /> </li> <li> <textarea name="com" id="com" COLS=40 ROWS=6></textarea> </li> <input type="hidden" name="page" value="<?php echo $result['article']->id ?>" /> <input type="submit" name="submit" value="submit" /> </ul> </form> Code: [Select] <?php class comment{ public $id = null; public $usern = null; public $com = null; public $page = null; public function __construct($data=array() ) { if( isset($data['id']) ) $this->id= (int)$data['id']; if( isset($data['usern']) ) $this->usern= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['usern'] ); if( isset($data['com']) ) $this->com= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['com'] ); if( isset($data['page']) ) $this->page= (int)$data['page']; } public function storeform ( $params ) { // Store all the parameters $this->__construct( $params ); } public function insertc() { $con = new PDO(DBN,DB_USER,DB_PASS); $sql = "INSERT INTO comments (usern,com,page) VALUES (:usern,:com,:page)"; $st =$con->prepare($sql); $st->bindValue( ":usern", $this->usern, PDO::PARAM_STR ); $st->bindValue( ":com", $this->com, PDO::PARAM_STR ); $st->bindValue( ":page", $this->page, PDO::PARAM_INT ); $st->execute(); $this->id = $con->lastInsertId(); $con = null; } } ?> I'm trying to create a script to use PDO prepared statements to enter data from a post form using functions to perform the PDO required statements. But, it's not working. When I execute it, it enters null in all the fields. I'm hoping someone can tell me why this is not working. I think the functions output what PDO is looking for. I'm not sure how to do this otherwise without writing a lot of code like $site_name= $_POST['site_name']; and entering all of that in the PDO statments. It seemed like it made sense to create the statements from the post array. My code is included below and after that is some output I used to monitor what is going on that shows the output of the functions in the script. Am I doing this all wrong. Is another approach that I haven't discovered? Thanks --Kenoli <?php if(isset($_POST['submit'])){ /** Establish DB connection. Not real data, of course. */ $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); /** Remove empty $_POST elements. */ $insert_array = array_filter($_POST); /** Whitelists input to identify columns to which changes are allowed */ $whitelist = array('site_name' =>'', 'site_address' =>'', 'description' =>'', 'surface' =>'', 'tio_contact' =>'', 'site_contact' =>'', 'contact_phone' =>'', 'contact_email' =>'', 'contact_date' =>'', 'comments' =>''); $insert_array = array_intersect_key($insert_array,$whitelist); /************/ /** Create query from $insert_array. */ foreach($insert_array as $key => $value) { $col .= $key . ', '; $val .= ':' .$key . ', '; } /** Remove ', " from end of each array. */ /* For use with update actions to prevent deleting data from fields that contain data. */ $col = substr_replace($col ,"",-2); $val = substr_replace($val ,"",-2); $sql = "INSERT INTO Sites ($col) VALUES ($val)"; /* The result is: INSERT INTO Sites (site_name, site_address, description, contact_phone) VALUES (:site_name, :site_address, :description, :contact_phone)*/ /************/ /** Prepared statement functions */ $stmt = $conn->prepare($sql); foreach($insert_array as $key => $value) { $param = ':' . $key; $stmt->bindParam($param, $$value); echo '$' . "stmt->bindParam($param, $$key)<br>"; // Monitor output } foreach($insert_array as $key => $value) { $$key = $value; echo "$$key = $value<br>"; // Monitor output } $stmt->execute(); // Execute insert ?> The result with dummy data: $insert_array
(
$stmt->bindParam(:site_name, $site_name)
$site_name = asdfasdf Everything looks right but NULLs are inserted in all fields.
When i click my submit button i am posting the following. Array ( [submitStaffOrder] => [staffMember] => Array ( [0] => 2 [1] => ANYCHEF1 ) [date] => Array ( [0] => 2020-02-18 [1] => 2020-02-18 ) [startTime] => Array ( [0] => 11:01 [1] => 10:10 ) [finishTime] => Array ( [0] => 11:01 [1] => 10:01 ) [delExisting] => Array ( [0] => [1] => toDel ) ) I would like to update/insert if delExisting is blank and delete if it has toDel in there. I have the following but i am pretty sure the if is not working. $date = $_POST['date']; $stime = $_POST['startTime']; $ftime = $_POST['finishTime']; $del = $_POST['delExisting']; $staff = $_POST['staffMember']; $stmt = $conn -> prepare(" INSERT IGNORE INTO ssm_staff_order (job_id, staff_id, staff_start_time, staff_finish_time, staff_start_date, staff_finish_date) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE staff_start_time = VALUES(staff_start_time), staff_finish_time = VALUES(staff_finish_time); "); $delstmt = $conn -> prepare(" DELETE FROM ssm_staff_order WHERE staff_id = ? AND job_id = ? AND staff_start_date = ? "); foreach ($staff as $key => $staffId) { if ($del == '') { $start = $date[$key].' '.$stime[$key]; $finish = $date[$key].' '.$ftime[$key]; $stmt -> bind_param('isssss', $jid, $staffId, $start, $finish, $date[$key], $date[$key]); $stmt -> execute(); } if ($del == 'toDel') { $delstmt -> bind_param('sis', $staffId, $jid, $date[$key]); $delstmt -> execute(); } } } Can i do what i am trying to do or am i way off here?
I struggle with arrays Edited February 24, 2020 by Adamhumbughi ..
hit little snag Ive got html <form name="formx" method="POST" action="connect.php" class='ajaxform'> and about 4 varibles in that form .. now how to properly
query table users so i can find out which prefix correspond with that user
Insert into table "upis" in this case that prefix with 3 variables..
everything in single,.. in this case connect.php file
I know how to do QUERY and INSERT INTO but i don't know how to connect with 2 different tbl or db and do the query and input of data.. every time I put 2 of them together .. never works out..
this is example.. i dont know is this right way to do it .. Hi Folks,
Firstly I am new, I have read several topics here and learned a lot, I would class myself as 'slightly better than basic', but my knowledge is mostly gained from reading code.
I am making a simple POST form for work, the data gets inserted into MySQL, nice and easy, I can make it work if I write out the statement completely, BUT I need to make a new form, it will have HUNDREDS of input fields, I really don't want to write the code, and I figured programmatically is a good way to go anyway as forms change and new forms may be required, so I set about building a function to completely handle my post data, bind it to a statement and insert it into a table, I have scrapped it a half dozen times already because something fundamentally doesn't work, but I am very close! The function can write the statement, but I need to bind the POST values before I can insert, something going wrong here and I would appreciate some help, I have a feeling it's a problem with an array, but anyway I will show you what I have, give you some comments as to my reasoning, and hopefully you can help me with the last bit
public function getColumnNames($table){ $sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :table"; try { $stmt = $this->dbh->prepare($sql); $stmt->bindValue(':table', $table, PDO::PARAM_STR); $stmt->execute(); $output = array(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $output[] = $row['COLUMN_NAME']; } $all = array($output); $a1 = array_slice($output, 1); // I don't want column 1, it contains the ID, its auto incremented. $a2 = array_slice($a1, 0, -3); // I don't want the last 3 columns as they have default values $selected = array($a2); // contains all the columns except those excluded by array_slice, columns now match all of the input fields on the form foreach ($selected as $row){ $fields = "`" . implode('`, `', $row) . "`"; // I'm making `fields` here, $bind = ":" . implode(', :', $row); // And making :values here } return array ( "raw" => $all, "fields" => $fields, "bind" => $bind ); } catch(PDOException $pe) { trigger_error('Could not connect to MySQL database. ' . $pe->getMessage() , E_USER_ERROR); } } public function addRecord(){ $col = array(); $col = $this->getColumnNames("table"); $raw = array($col['raw']); $fields = array($col['fields']); $bind = array($col['bind']); $columnList = implode('`, `', $fields); $paramList = implode(', ', $bind); $sql = "INSERT INTO `{$this->dbtable}` ($columnList) VALUES ($paramList)"; return $sql; // this returns something like: INSERT INTO `table` (`field1`, `field2`, `field3`) VALUES (:field1, :field2, :field3)";perfect I thought, now I just need to bind the values from $_POST... then I get stuck. Edited by luke3, 08 January 2015 - 12:10 PM. OK, since today is the 31st, I guess I figured out that strtotime("-1 Month') really only goes back 30 days, so where I think it should be September, its registering October 1st. Is there a fix for this? Code: [Select] $month = date('F Y', strtotime("-1 month")); $month1 = date('F Y', strtotime("-2 month")); $month2 = date('F Y', strtotime("-3 month")); $month3 = date('F Y', strtotime("-4 month")); $month4 = date('F Y', strtotime("-5 month")); $month5 = date('F Y', strtotime("-6 month")); I have 2 dropdowns, both default to 'select'. The query seemed to work ok before I added validation that both dropdowns need to have a value other than 'select' before the query will be run (i.e., "please select a value for both dropdowns"). For one of the dropdowns, the value just prior to that evaluation has a value/year selected, but within that IF evaluation it echos as 'select'. --right before IF--year:2010 post year:2010 year end:2011 owner:C WAGNER ------while in IF--year:select post year:2010 year end:2011 owner:C WAGNER the code is up at brewhas.org/team_history.php any ideas as to why that value seems to change within the IF? Code: [Select] <?php $url_owner = $_GET['owner']; $url_year = $_GET['year']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Brewhas Keeper League Fantasy Baseball - Team Transaction History</title> <link rel="stylesheet" type="text/css" href="style/bklstyle.css" /> <link rel="stylesheet" type="text/css" href="style/mm_travel2.css" /> <link rel="shortcut icon" href="http://www.brewhas.org/images/favicon.ico"> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr bgcolor="#003300"> <td rowspan="2" nowrap="nowrap" bgcolor="#003300"> </td> <td width="59" rowspan="2" nowrap="nowrap" bgcolor="#003300"><img src="http://www.brewhas.org/images/BKL.jpg" alt="BKLLogo" width="59" height="66"/></td> <td width="608" height="49" align="center" valign="bottom" nowrap="nowrap" bgcolor="#003300" id="logo"><span class="style1">BREWHAS KEEPER LEAGUE </span></td> <td width="415" align="center" valign="bottom" nowrap="nowrap" bgcolor="#003300" id="logo"> </td> <td width="5" rowspan="2" bgcolor="#003300"> </td> </tr> <tr bgcolor="#003300"> <td height="24" align="center" valign="top" bgcolor="#003300" id="tagline"><span class="style2">fantasy baseball</span></td> <td height="24" align="center" valign="top" bgcolor="#003300" id="tagline"> </td> </tr> <tr> <td colspan="6" bgcolor="#003300"><img src="images/mm_spacer.gif" alt="" width="1" height="1" border="0" /></td> </tr> <tr bgcolor="#CCC999"> <td height="15" colspan="5" bgcolor="#CCC999"> <div class="container"> <div style="clear: both; display: block; padding-bottom: 2px;"></div> <ul id="topnav"> <li><a href="http://www.brewhas.org/index.html">Home</a></li> <li><a href="#">Team Pages</a> <span> <a href="http://www.brewhas.org/team_pages/boothby.html">Boothby</a> | <a href="http://www.brewhas.org/team_pages/bradt.html">Bradt</a> | <a href="http://www.brewhas.org/team_pages/jcurry.html">J Curry</a> | <a href="http://www.brewhas.org/team_pages/pcurry.html">P Curry</a> | <a href="http://www.brewhas.org/team_pages/hurlebaus.html">Hurlebaus</a> | <a href="http://www.brewhas.org/team_pages/jankowski.html">Jankowski</a> | <a href="http://www.brewhas.org/team_pages/oneil.html">O'Neil</a> | <a href="http://www.brewhas.org/team_pages/shimizu.html">Shimizu</a> | <a href="http://www.brewhas.org/team_pages/cwagner.html">C Wagner</a> | <a href="http://www.brewhas.org/team_pages/jwagner.html">J Wagner</a> </span> </li> <li><a href="http://www.brewhas.org/rules.html">League Rules</a></li> <li><a href="http://www.brewhas.org/payout_picks.html">Payouts & Draft Order</a></li> <li><a href="http://www.brewhas.org/standings/2010_standings.html">Standings</a> <span> <a href="http://www.brewhas.org/standings/2010_standings.html">2010</a> | <a href="http://www.brewhas.org/standings/2009_standings.html">2009</a> | <a href="http://www.brewhas.org/standings/2008_standings.html">2008</a> | <a href="http://www.brewhas.org/standings/2007_standings.html">2007</a> | <a href="http://www.brewhas.org/standings/2006_standings.html">2006</a> | <a href="http://www.brewhas.org/standings/2005_standings.html">2005</a> | <a href="http://www.brewhas.org/standings/2004_standings.html">2004</a> | <a href="http://www.brewhas.org/standings/2003_standings.html">2003</a> | <a href="http://www.brewhas.org/standings/2002_standings.html">2002</a> | <a href="http://www.brewhas.org/standings/2001_standings.html">2001</a> </span> </li> <li><a href="http://www.brewhas.org/drafts/2011_draft.html">Drafts</a> <span> <a href="http://www.brewhas.org/drafts/2011_draft.html">2011</a> | <a href="http://www.brewhas.org/drafts/2010_draft.html">2010</a> | <a href="http://www.brewhas.org/drafts/2009_draft.html">2009</a> | <a href="http://www.brewhas.org/drafts/2008_draft.html">2008</a> | <a href="http://www.brewhas.org/drafts/2007_draft.html">2007</a> | <a href="http://www.brewhas.org/drafts/2006_draft.html">2006</a> | <a href="http://www.brewhas.org/drafts/2005_draft.html">2005</a> | <a href="http://www.brewhas.org/drafts/2004_draft.html">2004</a> | <a href="http://www.brewhas.org/drafts/2003_draft.html">2003</a> | <a href="http://www.brewhas.org/drafts/2002_draft.html">2002</a> | <a href="http://www.brewhas.org/drafts/2001_draft.html">2001</a> </span> </li> <li><a href="http://www.brewhas.org/excelfiles/alltimeaverages.xls">Records</a></li> <li><a href="http://www.brewhas.org/excelfiles/transactions.xls">Transactions</a></li> </ul> </div> </td> </tr> <tr> <td width="164" bgcolor="#FFFFFF"> </td> <td width="59" bgcolor="#FFFFFF"> </td> <td colspan="4" valign="top" bgcolor="#FFFFFF"> <table border="0" cellspacing="0" cellpadding="2" width="835"> <div align="center"> <tr> <td width="831" height="31" class="pageName"> <div align="left"></div> </td> </tr> </div> </table> </td> </tr> </table> <div id="header"></div> <div id="leftcol_long"></div> <div id="content_long"> <h2>Transaction Search - Team History</h2> <table border="0" cellspacing="0" cellpadding="1" width="95%" align=center> <tr> <td bgcolor="#ffffff" height="35" valign="top" rowspan="2"> <form name="form1" method="post" action="http://brewhas.org/team_history.php"> <table border="0" align=left> <tr> <td>Year: <select name='year'> <option value='select'>SELECT</option> <option value='2011' <?php if($_POST['year'] == '2011') echo "selected"?>>2011</option> <option value='2010' <?php if($_POST['year'] == '2010') echo "selected"?>>2010</option> <option value='2009' <?php if($_POST['year'] == '2009') echo "selected"?>>2009</option> <option value='2008' <?php if($_POST['year'] == '2008') echo "selected"?>>2008</option> <option value='2007' <?php if($_POST['year'] == '2007') echo "selected"?>>2007</option> <option value='2006' <?php if($_POST['year'] == '2006') echo "selected"?>>2006</option> <option value='2005' <?php if($_POST['year'] == '2005') echo "selected"?>>2005</option> <option value='2004' <?php if($_POST['year'] == '2004') echo "selected"?>>2004</option> <option value='2003' <?php if($_POST['year'] == '2003') echo "selected"?>>2003</option> <option value='2002' <?php if($_POST['year'] == '2002') echo "selected"?>>2002</option> <option value='2001' <?php if($_POST['year'] == '2001') echo "selected"?>>2001</option> </select> Owner: <select name='owner'> <option value='select'>SELECT</option> <option value='J BOOTHBY'<?php if($_POST['owner'] == 'J BOOTHBY') echo "selected"?>>J BOOTHBY</option> <option value='K BRADT' <?php if($_POST['owner'] == 'K BRADT') echo "selected"?>>K BRADT</option> <option value='J CURRY' <?php if($_POST['owner'] == 'J CURRY') echo "selected"?>>J CURRY</option> <option value='P CURRY' <?php if($_POST['owner'] == 'P CURRY') echo "selected"?>>P CURRY</option> <option value='R HURLEBAUS' <?php if($_POST['owner'] == 'R HURLEBAUS') echo "selected"?>>R HURLEBAUS</option> <option value='M JANKOWSKI' <?php if($_POST['owner'] == 'M JANKOWSKI') echo "selected"?>>M JANKOWSKI</option> <option value='T ONEIL' <?php if($_POST['owner'] == 'T ONEIL') echo "selected"?>>T ONEIL</option> <option value='C WAGNER' <?php if($_POST['owner'] == 'C WAGNER') echo "selected"?>>C WAGNER</option> <option value='J WAGNER' <?php if($_POST['owner'] == 'J WAGNER') echo "selected"?>>J WAGNER</option> <option value='J BADER' <?php if($_POST['owner'] == 'J BADER') echo "selected"?>>J BADER</option> <option value='M SUH' <?php if($_POST['owner'] == 'M SUH') echo "selected"?>>M SUH</option> </select> </td> <td nowrap class="row1" width="40"><input type="submit" value="Submit" name="submit"></td> <td nowrap class="row1" width="60"></td> <td><p><img src="images/baseball.jpg" alt="baseball" width="8""height=8"" /><span class="style7"> Note: For the 2001 season, only the draft transactions are available.</span></p></td> </tr> </table> </form> </td> </tr> </table> <?php include 'config.php'; include 'opendb.php'; //Include the PS_Pagination class include('ps_pagination.php'); if((isset($url_year))&&(isset($url_owner))) { //If a year and owner appear in the URL, meaning we're past page 1 --> get the year and owner from the URL parms $year_search = $url_year; $owner_search = $url_owner; } else //If a year and owner have not been entered and do not appear in the URL (first time thru) --> get them from the form { $year_search = $_POST['year']; $owner_search = $_POST['owner']; } switch ($year_search) { case "2011": $year_end="2012"; break; case "2010": $year_end="2011"; break; case "2009": $year_end="2010"; break; case "2008": $year_end="2009"; break; case "2007": $year_end="2008"; break; case "2006": $year_end="2007"; break; case "2005": $year_end="2006"; break; case "2004": $year_end="2005"; break; case "2003": $year_end="2004"; break; case "2002": $year_end="2003"; break; case "2001": $year_end="2002"; break; } echo "--right before IF--"; echo "year:".$year_search." "; echo "post year:".$_POST['year']." "; echo "year end:".$year_end." "; echo "owner:".$owner_search." "; //This checks to see if both the year and the owner have been selected. if(($year_search="select")||($owner_search="select")) { echo "<BR>"."------while in IF--"; echo "year:".$year_search." "; echo "post year:".$_POST['year']." "; echo "year end:".$year_end." "; echo "owner:".$owner_search; echo "<p class='style7'>Please select both a year and a team owner.</p>"; exit; } else //sets the query to get the number of rows { $sql = "SELECT * FROM `BKL_TRANSACTIONS` WHERE (((TO_OWNER='$owner_search')OR(FROM_OWNER='$owner_search')) and (TRANS_DT >='$year_search') AND (TRANS_DT <='$year_end'))"; } $count = mysql_query($sql) or die ("Could not execute the query"); //executes the query to count the number of matching rows //Count the number of results $numrows=mysql_num_rows($count); echo "<p class='style7'>Your search: "".$year_search." ".$owner_search."" returned <b>".$numrows."</b> results.</p>"; //Count the number of results /* * Create a PS_Pagination object * * $conn = MySQL connection object (defined in opendb.php) * $sql = SQl Query to paginate * 50 = Number of rows per page * 5 = Number of links * "year=valu1&owner=value2" = Append name parameters ($year_search and $owner_search) to paginations links */ $pager = new PS_Pagination($conn, $sql, 50, 5, "year=$year_search&owner=$owner_search"); /* * The paginate() function returns a mysql result set * or false if no rows are returned by the query */ $rs = $pager->paginate(); //executes the query if(!$rs) die(mysql_error()); if ($numrows == 0) //if no matches, don't display the table exit; else //build the table and insert rows { echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=left bordercolor=#666666>"; echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>"; echo "<th width='10%' class='style5'>Action</th>"; echo "<th width='12%' class='style5'>From</th>"; echo "<th width='12%' class='style5'>To</th>"; echo "<th width='5%' class='style5'>Pos</th>"; echo "<th width='18%' class='style5'>Name</th>"; echo "<th width='5%' class='style5'>Round</th></tr>"; while ($row = mysql_fetch_array($rs)) { echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>"; echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>"; echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>"; echo "<td width='12%' class='style6'>".$row['TO_OWNER']."</td>"; echo "<td width='5%' class='style6'>".$row['POSITION']."</td>"; echo "<td width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>"; echo "<td width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>"; } //Display the navigation if ($numrows > 50) { echo "<p class='style7'>".$pager->renderFullNav()."</p>"; } echo "</table>"; } ?> </div> <div id="rightcol_long"></div> <div id="footer"><p align="center" class="style8">Brewhas Keeper League - <img src="images/icon_mlb.gif" alt="mlb" width=36 height=18> - Established 2001</p></div> <p></p> </body> </html> Hi
I'm have a PHP form that submits to a MYSQL database and I'm trying to make it so when any form input field is empty the user gets a message below that field and the data isn't submitted. I can't seem to get it work though?
<?php // submit data to database if (isset($_POST['submit'])) { // assign variable names to name attributes from the form $firstname = $_POST['first-name']; $email = $_POST['email']; // This is the attempted validation code if(empty($firstname)) { $error= "<br>- Please enter your firstname"; } if(empty($email)) { $error="<br>- Please enter your email"; } if ($error) { $result="<p class='alert error'>There is an error. Please correct the following: {$error}</p>"; } else { // This is when the data is submitted $query = "INSERT INTO users(firstname, email) VALUES(?,?)"; $stmt = $connection->prepare($query); $stmt->bind_param("ss", $f, $e); $f = $firstname; $e = $email; $stmt->execute(); $stmt->close(); $connection->close(); header("Location: index.php"); // makes page refresh after query so new records show in HTML table } } ?>
Hi all, I am trying to figure out how to calculate 5 working days prior to a given date. I have done some googling but can only see examples of how to add 5 working days onto a date, such as this: Code: [Select] $holidayList = array(); $j = $i = 1; while($i <= 5) { $day = strftime("%A",strtotime("+$j day")); $tmp = strftime("%d-%m-%Y",strtotime("+$j day")); if($day != "Sunday" and $day != "Saturday" and !in_array($tmp, $holidayList)) { $i = $i + 1; $j = $j + 1; } else $j = $j + 1; } $j = $j -1; echo strftime("%A, %d-%m-%Y",strtotime("+$j day")); Does anyone know how to calculate 5 working days prior to a date? Many thanks, Greens85 Hello my mysql db got row pageurl pageurl http://www.google.gr http://www.yahoo.com http://www.phpfreaks.com i whant to echo 11,12,13 letter only ***********goo****** but i whant to show and count the ******* how can i do this? any idea? Hi Guys
I have a regex conundrum that at first I thought would be very easy but then appears to be quite hard :/
I want to match a string with a regex where the regex can only pass if it contains letters and numbers (nothing else) and it has to contain at least one of each.
I've been trying out lookaheads but just can't get it right.
Any help is appreciated.
Drongo
How in php using the preg_replace php function can i allow only the basic english a-z letters, numbers 0-9 and unicode code letters and remove anything else? I'm looking for a function that will check a string for letters and spaces...boolean preferibly Hello, I have a script coded in PHP and alot of JavaScript and I have problems with languages like Arabic and Hebrew ( non Latin characters) .. It is showed as question marks in the website like this ( ?????????) and in the database .. I converted the SQL Database from Latin Swedish to UTF-8 in phpmyadmin and now the database is correct but the website is still in question marks . In every HTML code you can see this : ........... content="text/html; charset=utf-8"/> and I tried changing the same php pages to UTF-8 using text editors but nothing happened . any help will be great. thanks. |