PHP - Weird Problem Drives Me Crazy
I'm trying to get a remote html page but I'm having a really weird problem.
I'm using curl for that and I'm getting the page url from an rss item using simpelpie. Code: [Select] $url = $item->get_permalink();//simplepie function echo "<p>Getting $url. </p>"; $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_ENCODING => "", // handle all encodings CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; if($err != 0) echo " $err : $errmsg</p>"; echo $header['content']; My problem is that although the page is loading fine ( no curl errors ) , some tags are missing (and particularly the tags that containing the article content of that page). When I'm hardcoding the url then everything is fine. I tried to print the url that simpepie gets from rss and it's identical with the one that I'm harcoding. So, Code: [Select] $url = $item->get_permalink(); not working Code: [Select] $url = "http://www.the_same_url.com" working. Any help whould be really appreciated. Thanks in advance. Similar TutorialsDoes somebody know, where the issue is when the external hard drives respond very slow to a point where one can not copy over a small sized file?
I have this issue with different types of external hard drives.
I am using Windows 8.
Edited by glassfish, 01 December 2014 - 09:36 AM. Okay here's the simple thing I'm trying to do. I have a time in a db on my server .. let's say its March 1st 2011 at 12:00AM. This time is dynamically set by the server, so it's on server time. Now, lets say today is Feb 28th 2011 at 12:00AM on the server. I'm trying to write a dynamic script that will count down that time .. in this case I would want to show 23:59:59. Every count down script i've found online gives me an option to use local time (browser) or server time. Each time i plug in server time it is always set to my browse time ... I echo everything out and I basically get this: Server time: Feb 28th 2011 at 12:00AM My browser time: Feb 28th 2011 at 2:00AM Script time remaining: 21:59:59 So why does this keep happening? When I echo the date() from the server it's always 2 hours ahead of my time but the script never adjusts. Any ideas or does anyone know of a good working script? I'm on eastern time and the server is on pacific. Here's my last try, you'll see I place the php date into this towards the bottom but I've also tried jquery and SSI methods too. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <script language="JavaScript"> TargetDate = "2/1/2011 12:00 AM"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; FinishMessage = "It is finally here!"; </script> <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"> */ function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return "<b>" + s + "</b>"; } function CountBack(secs) { if (secs < 0) { document.getElementById("cntdwn").innerHTML = FinishMessage; return; } DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60)); document.getElementById("cntdwn").innerHTML = DisplayStr; if (CountActive) setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod); } function putspan(backcolor, forecolor) { document.write("<span id='cntdwn' style='background-color:" + backcolor + "; color:" + forecolor + "'></span>"); } if (typeof(BackColor)=="undefined") BackColor = "white"; if (typeof(ForeColor)=="undefined") ForeColor= "black"; if (typeof(TargetDate)=="undefined") TargetDate = "12/31/2020 5:00 AM"; if (typeof(DisplayFormat)=="undefined") DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; if (typeof(CountActive)=="undefined") CountActive = true; if (typeof(FinishMessage)=="undefined") FinishMessage = ""; if (typeof(CountStepper)!="number") CountStepper = -1; if (typeof(LeadingZero)=="undefined") LeadingZero = true; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; putspan(BackColor, ForeColor); var dthen = new Date(TargetDate); var dnow = new Date("<!--config timefmt='%c' --><!--echo var='DATE_LOCAL' -->"); if(CountStepper>0) ddiff = new Date(dnow-dthen); else ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(gsecs); </script> <br /> <?php $now = new DateTime(); echo $now->format("M j, Y H:i:s O")."\n"; ?> </body> </html> I am having a problem I have encounted like no other. I am running a MySQL query from PHP and for some bizarre reason, its just not working... Ok, that sounds really general. lol To start off, here is my database: http://i56.tinypic.com/2hh0up1.png I am writing my own user interface with HTML/PHP/MySQL for every day catalog management: http://i54.tinypic.com/axxsb7.png To catalog a product is done from here (this page works): http://i51.tinypic.com/2e0qs7s.png ETC ... <FORM action="result.html" enctype="multipart/form-data" method="post"> ... ETC ETC ... Name: <INPUT name="name" type="text"> <BR> Brand: <INPUT name="brand" type="text"> <BR> Country of origin: <INPUT name="country" type="text"> <BR> Material: <INPUT name="material" type="text"> <BR> Primary colour: <INPUT name="primarycolour" type="text"> ... ETC result.html: ETC ... $query = "INSERT INTO products(name, brand, country, material, primarycolour) VALUES('".$_POST['name']."', '".$_POST['brand']."', '".$_POST['country']."', '".$_POST['material']."', '".$_POST['primarycolour']."')"; ... ETC To alter a product, you enter in a product ID: http://i56.tinypic.com/2lcsqch.png Code: [Select] <FORM action="dataentry.html" method="post"> <DIV class="drop">Alter product ID: <INPUT name="id" type="text">    <INPUT type="submit" value="Submit"></DIV> The data entry page pulls all the values from the MySQL database and populates them into the INPUT fields, so the user does not have to write them all again: http://i56.tinypic.com/2zh0hgn.png ... ETC echo '<FORM action="result.html" enctype="multipart/form-data" method="post">'; ETC ... ... ETC echo 'Name:'; $query = "select name from products where id=".$_POST['id'].""; $result = mysql_query($query); $row = mysql_fetch_array($result); echo ' <INPUT name="name" type="text" value="'.$row['name'].'">'; echo $query; ETC ... I will now change the value of "Name" from 'a' to 'c' and submit the changes: http://i55.tinypic.com/dzi9hc.png http://i54.tinypic.com/ab5lyg.png Now, you would think the result has been inserted into my database yeah? It failed... but when I enter the same command directly into MySQL. Success! http://i51.tinypic.com/29z5y5x.png Why the F is this happening?! Okay, so basically my news-like site is supposed to print out article data saved in the database. It does that quite alright, except on the 3rd article (number 2 in SQL rows or columns. whichever it is. I have my counter subtract 1 from the start article to compensate for MySQL) My code: Code: [Select] <?php print "<div class = 'menu' align='center'>Newest Stories</div>"; if (isset($_REQUEST['mstart'])) { $start=$_REQUEST['mstart']; } else { $start=1; } if ($start) { $start=1; } $start--; $end=$start+5; $stories = mysql_query("SELECT * FROM stories ORDER BY id DESC LIMIT $start, $end") or die(mysql_error()); $num = mysql_num_rows($stories); $start++; if ($num > 0) { if ($num<$end) { $end = $end-(5-$num); } print "<b><i>Showing stories $start to $end</i></b>"; for ($count=0; $count<$num; $count++) { print "<hr>"; $story = mysql_fetch_array($stories,$count); $id = $story['id']; $headline = $story['headline']; $author = $story['author']; $desc = $story['description']; $content = $story['content']; print "COUNT: $count OF $num ($id)<br>"; print "<a href='index.php?request=story&mstart=$start&story=$id' class='headlinelink'>$headline</a><br>"; print "<div class='author'>Posted by: <a href='index.php?request=author&mstart=$start&author=$author' class='author'>$author</a>.</div>"; print "<div class='desc'>$desc</div><br>"; } } else { print "Error. No stories found. :("; } ?> Output: (The COUNT x OF y was to help me figure out what is wrong. In the () by it is the id number of the corresponding MySQL row/column. I even deleted one of the articles to see if it was a specific article error. No luck.) Quote Newest Stories Showing stories 1 to 5 ---------------- COUNT: 0 OF 5 (6) Y U NO STAY Posted by: craigory83. GRRR ---------------- COUNT: 1 OF 5 (5) h-l! Posted by: craigory83. desc ---------------- Notice: Undefined index: id in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dba\menu.php on line 37 Notice: Undefined index: headline in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dba\menu.php on line 38 Notice: Undefined index: author in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dba\menu.php on line 39 Notice: Undefined index: description in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dba\menu.php on line 40 Notice: Undefined index: content in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dba\menu.php on line 41 COUNT: 2 OF 5 () Posted by: . ---------------- COUNT: 3 OF 5 (2) This is the second story! Posted by: TDWP83. See, I fuckin told you so! Warning: mysql_fetch_array() [function.mysql-fetch-array]: The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dba\menu.php on line 36 ---------------- COUNT: 4 OF 5 (1) This is the mother fucking headline! Posted by: craigory83. stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff I have an array from the database like so Array (2) ( | ['0'] => Array (4) | ( | | ['f_fid'] = String(1) "1" | | ['0'] = String(1) "1" | | ['f_names'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | | ['1'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | ) | ['1'] => Array (4) | ( | | ['f_fid'] = String(1) "2" | | ['0'] = String(1) "2" | | ['f_names'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | | ['1'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | ) ) So i use a foreach loop to turn the serialized value into an array foreach($fields as $key => $val) { $fields[$key]['f_names'] = unserialize($val['f_names']); } But for some reason the last f_names is false Array (2) ( | ['0'] => Array (4) | ( | | ['f_fid'] = String(1) "1" | | ['0'] = String(1) "1" | | ['f_names'] => Array (4) | | ( | | | ['0'] = String(18) "register_user_name" | | | ['1'] = String(5) "r_u_n" | | | ['2'] = String(10) "user_alias" | | | ['3'] = String(12) "nickusername" | | ) | | ['1'] = String(99) "a:4:{i:0;s:18:"register_user_name";i:1;s:5:"r_u_n";i:2;s:10:"user_alias";i:3;s:12:"nickusername";} " | ) | ['1'] => Array (4) | ( | | ['f_fid'] = String(1) "2" | | ['0'] = String(1) "2" | | ['f_names'] = Boolean(0) FALSE | | ['1'] = String(104) "a:4:{i:0;s:18:"register_password";i:1;s:5:"r_pass_word";i:2;s:10:"user_pass";i:3;s:12:"reg-pass-word";} " | ) ) Anyone have any idea why? Thanks I have a function that contains 2 UPDATE commands. One updates a table whenever the function is ran. The second updates only if a condition is met. When the page loads the function is ran. For some reason the table is updated twice. So my table looks like this: Initially Viewed: 0 Replies: 0 Navigate to page: Viewed:2 Replies:0 Enter a reply and submit: Veiwed:4 Replies:1 No matter where I move the "viewed +1" code, it fires twice per page impression. Is this a glitch? Do functions run twice for some reason? If so why doesn't "reply +1" fire twice? //page loads as forum.php?goto=innertopic function connectForum(){ //connects DB if($_GET['goto'] == "innertopic"){ detailTopic(); } } function detailTopic(){ if(isset($_POST['content']{ //if there is a reply to a post mysql_query("UPDATE topics SET Replies=Replies+1") //works fine } else{ //no reply, just show all posts mysql_query("UPDATE topics SET Views=Views+1") //fires 2 times per page load .. ?!?!? //show posts //show reply window, posts to forum.php?goto=innertopic&&content=whateverTheUserTyped } } //html of page if($_GET['goto'] == "innertopic"){ connectForum(); } I have an array that displays the following information with the print_r function: Array ( => Array ( => 2206.235 [1] => 3.9 [2] => 0.48 [3] => 0.477 [4] => 0.477 [5] => 0.475 [215] => 0.434 [216] => 0.436 [217] => 0.435 [218] => 0.434 [219] => 0.435 [220] => 0.435 ) ) Array ( => Array ( => 2206.235 [1] => 3.9 [2] => 0.48 [3] => 0.48 [4] => 0.435 [5] => 0.435 ) ) I would like to save the last row to my database which in this case is 220 but the last row could vary from time to time as the array is created from an email attachment so l wanted a code that would find the number of rows in the array. When l echo out the row like this: echo $matches[0][210] it retrieves the correct information so l wanted to implement this code instead to cater for an unknown amount of array rows so that the highest row was always returned: $i = count($matches[0]); echo $matches[0][$i]; but this does not work as when echoing $i the result is 2216 instead of 220 which l find odd or l am doing something wrong. Any ideas? thanks Callum I have a very odd cookie problem that's hard to explain so please bare with me... The first piece of code found below is the login process, where the login is checked and the cookie is created or not, the second piece of code below is a library which is called to display the login menu and get the connection to the database. The problem I'm having is I cant put these 2 files in the same folder. The cookie gets created if i put the process login into a directory and the library into a sub directory called inc ... then i "include("inc/library.php");" in the login process. I then point the form for the login to http://www.alcaeos.com/blog/loginProcess.php... If I do these 2 things then the cookie is created but if I place both files in the inc folder (The code below is the example of when both files are IN the inc folder) then the cookie does not get created. the login system still works and tells the user if they successfully logged in or not, it just wont create the cookie... It's an odd problem I think. Has anybody got any ideas... Thanks Code: [Select] <?php include("library.php"); connectToDatabase(); $username = $_GET['username']; $password = $_GET['password']; $sql = "SELECT * FROM theUsers WHERE user = '$username' AND pass = '$password';"; $result = mysql_query($sql) or die(mysql_error()); if ($obj = mysql_fetch_object($result)) { $expire=time()+60*60*24*30; setcookie("shopusername",$username,$expire); echo "<A HREF='http://www.alcaeos.com/blog/test.php'>You are logged in</A>"; } else { loginScreen(); echo "You are NOT Logged In"; } $db->close(); ?> Code: [Select] <?php function loginScreen() { $output = <<<LOGIN <FORM method ="GET" action="http://www.alcaeos.com/blog/loginProcess.php"> <table> <tr> <td>Username: </td> <td><INPUT TYPE = "text" NAME = "username"></td> </tr> <tr> <td>Password: </td> <td><INPUT TYPE = "password" NAME = "password"></td> </tr> </table> <INPUT TYPE="submit"> </FORM> LOGIN; echo $output; } function connectToDatabase() { $dbhost = 'mysql*******'; $dbuser = 'kem*******'; $dbpass = 'ya****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname = 'ke********'; mysql_select_db($dbname); } Hey guys! Well this is actually kind of a weird problem I have been having, and not too sure why I'm getting this problem. I've tried a lot of stuff, and it doesnt seem like I've been able to find a solution. I've been trying for about a month. Anyways, I have a website created with some OOP. Well, once I write an include statement to include a file, which then includes all my classes, it messes up my font, moves my website content down, and well.. it just does weird stuff. However, once I comment the include out, the website looks normal again. so basically, I can comment out the file itself and everything is just fine. But it only happens when I include my class files. Any ideas or suggestions would be amazing! Thank you! has just solved it, can be deleted. Hello there, I am making a function to execute every time with a new demand no. in the while loop below. Every thing goes fine for the first time when the page loads, all the taxes come perfectly and each record is being read with the function calculateTaxes($demandno). But, when I press the search button with blank entries... All the entries come with only the first record. Means, the calculateTaxes function is not being loaded again and again with the loop when the press the search button. Please help. Please have a look in the below given code: Code: [Select] <?php function renderform($wardno, $demandno, $name) { include_once $_SERVER['DOCUMENT_ROOT'].'/npms/header.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/config/config.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/functions.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/connect-db.php'; extract($GLOBALS); if ($demandno == '' && $wardno == '' && $name == '') // all empty. { $result = mysql_query("SELECT * FROM sform where paid=false order by wardno, id, demandno limit 0,$maxrecords") or die(mysql_error()); } if ($demandno != '' && $wardno != '' && $name != '') // all full. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' and (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno == '' && $name == '') // demand full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and paid=false order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno != '' && $name == '') // demand and ward full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' and paid=false order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno != '' && $name == '') // ward full else empty. { $result = mysql_query("SELECT * FROM sform where wardno='$wardno' and paid=false order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno != '' && $name != '') // ward and name full else empty. { $result = mysql_query("SELECT * FROM sform where wardno='$wardno' and (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error()); } if ($demandno == '' && $wardno == '' && $name != '') // name full else empty. { $result = mysql_query("SELECT * FROM sform where (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error()); } if ($demandno != '' && $wardno == '' && $name != '') // demand and name full else empty. { $result = mysql_query("SELECT * FROM sform where demandno='$demandno' and (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error()); } usleep(200000); // wait for 2 seconds ?> <link rel=stylesheet HREF="/npms/css/sp.css" type="text/css" media="screen"> <div id="content"> <div id="labelopt"></div> <h2>okMZokj ukxfjdksa dh lwph</h2> <div id="list"> <form name="spsearchform" action="" method="post"> <table border="1" cellpadding="2px"> <tr> <td id="labelmust" width="10%">fM- dz- %</td> <td><input class="english" type="text" size="15%" name="demandno" maxlength="40" value="<?php echo $demandno; ?>" /></td> <td id="labelmust" width="10%">okMZ dz- %</td> <td><input class="english" size="20%" type="text" size="15%" name="wardno" maxlength="3" value="<?php echo $wardno; ?>"/></td> <td id="labelmust" width="10%">uke %</td> <td><input class="hindi" size="30%" type="text" name="name" maxlength="100" value="<?php echo $name; ?>"/></td> <td><input type="submit" value="Search" name="btnsearch" /></td> </tr> </table> </form> <div style="color: red;"><small><cite>List is limited to <? echo $maxrecords; ?> records. For precise searching, use the search options above.</small></cite></div> <table border="1" cellpadding="2px"> <tr> <td colspan="8" id="english"><div style="float: right; color: red; text-align: right; margin-right: 10px;"><small><cite><strong><? echo mysql_num_rows($result); ?> records</strong> dumped.</cite></small></div></td> </tr> <tr> <td id="labelcenter">okMZ dz-</td> <td id="labelcenter">fMeka.M dzekad</td> <td id="labelcenter">uke</td> <td id="labelcenter">irk</td> <td id="labelcenter">'kq} dj</td> <td id="labelcenter">dj fooj.k</td> <td id="labelcenter">fu;kstu</td> <td id="labelcenter">feVk;sa</td> </tr> <?php if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_array( $result )) { echo "<tr>"; echo "<td id='english'><center>" . $row['wardno'] . "</center></td>"; echo "<td id='english'><center>" . $row['demandno'] . "</center></td>"; echo "<td id='hindi'>" . $row['name'] . "</td>"; echo "<td id='hindi'>" . $row['address'] . "</td>"; $taxes = calculateTaxes($row['demandno']); echo "<td id='english' align='right'>" . number_format($taxes['grosstax'],2) . "</td>"; echo '<td><center><a href="payments/taxreport.php?demandno=' . $row['demandno'] . '"><img src="../images/payment.jpeg" width="15" height="15" /></center></a></td>'; echo '<td><center><a href="spedit.php?demandno=' . $row['demandno'] . '"><img src="../images/edit.gif" width="15" height="15" /></center></a></td>'; echo '<td><center><a href="spdelete.php?demandno=' . $row['demandno'] . '"><img src="../images/delete.jpeg" width="15" height="15" /></center></a></td>'; } } else { echo "<tr>"; echo "<td colspan='7' align='center'><blink><strong>lwph miyC/k ugha gS A</strong></blink></td>"; echo "</tr>"; } ?> </tr> </table> </div> <div id="menu"> <table> <tr> <td> <input type="button" value="New" name="btnnew" onclick="location.href='spnew.php';" /> <input type="button" value="Back" name="btnspback" onclick="location.href='../sp.php';" /> </td> </tr> </table> </div> </div> <?php include_once $_SERVER['DOCUMENT_ROOT'].'/npms/footer.php'; } include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/connect-db.php'; include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/functions.php'; if(isset($_POST['btnsearch'])) { $wardno = mysql_real_escape_string(htmlspecialchars($_POST['wardno'])); $name = mysql_real_escape_string(htmlspecialchars($_POST['name'])); $demandno = mysql_real_escape_string(htmlspecialchars($_POST['demandno'])); renderform($demandno, $wardno, $name); } else { renderform('', '', ''); } ?> Hello i am writing a html form but i have problem with reading array. Here is html form: Code: [Select] <tr style="background-color: rgb(254, 242, 99);"><td>dghhf <input name="id[]" value="<?php echo $row['id']" type="hidden"> <input name="dbcheck[]" value="IF_THERE_IS_RECORD_TYPE 1 OR TYPE 0" type="hidden"></td> <td align="center"><input name="chk1[]" checked="checked" type="checkbox">chk1 <input name="chk2[]" type="checkbox">chk2 <input name="chk3[]" type="checkbox">chk3</td> <td align="center"> <select name="StartHour[]"> <option value=""></option> <option value="00">00</option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05" selected="selected">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option> </select>:<select name="StartMin[]"><option value=""></option><option value="00">00</option> <option value="30" selected="selected">30</option></select> ~ <select name="EndHour[]"> <option value=""></option><option value="00">00</option><option value="01">01</option><option value="02">02</option><option value="03">03</option><option value="04">04</option><option value="05">05</option><option value="06">06</option><option value="07">07</option><option value="08">08</option><option value="09">09</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20" selected="selected">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option> </select>:<select name="StartMin[]"><option value=""></option><option value="00" selected="selected">00</option> <option value="30">30</option></select></td></tr> Above HTML works great and no problem however my php code always take first record. Here is php section: Code: [Select] <?php $TODAY = strtotime($_GET['d']); if(isset($_POST['WorkEntry'])) { for($ii=0; $ii<count($_POST['girl_id']); $ii++) { if(isset($_POST['chk2'][$ii])){ $To = ""; $From = "ASK"; } else{ $To = $_POST['StartMin'][$ii]; $From = $_POST['StartHour'][$ii]; } if(isset($_POST['chk3'][$ii])) $ei = 1; else $ei = 0; if($_POST['dbcheck'][$ii] == 1) { echo $_POST['dbcheck'][$ii]; } else { if(isset($_POST['chk1'][$ii])) { $DELETE = "DELETE FROM time_table WHERE _id = '" .$_POST['_id'][$ii]. "' AND w_date = '" .$TODAY. "'"; } } echo $ei ."<BR>"; } } ?> I am simple using include to include a file within the webpage. include $file; $file does exist and is a string. This works fine locally but when testing on my live server it isnt included and nothing below the include is executed, not even plain html. The error log shows nothing, and there are no errors on screen even when using E_ALL. So i decided to make $file point to the file on the server to see if it was picking it up and it does. So why doesnt the live server want to include this file? The file consists of php and html but there arent any errors. It wouldnt work locally if there were. Any ideas? Hi! To calculate my real time hours worked for/at a client I've made 3scripts, 1 to start the time, 1 to show the running time and 1 for stopping it. The first and last are put into my hosted DB. I'm accessing them through SSH so that I don't need my laptop all the time. Now here's the problem, when I start the time and I look into my DB I see the actual correct time and date (timestamp), but when I execute the script for stopping it the start time changes, so for example I started at 9:00, that time will be changed to for example 11:00 when I stop it... very strange, here are my scripts: start: <?php date_default_timezone_set('Europe/Brussels'); $timestamp = date('Y-m-d H:i:s'); $conn = mysql_connect('server' 'user', 'pw') or die(mysql_error()); mysql_select_db('hystudi_timesheets', $conn) or die(mysql_error()); mysql_query("INSERT INTO timesheet (t_start_timestamp) VALUES ('$timestamp')", $conn) or die(mysql_error()); ?> stop: <?php date_default_timezone_set('Europe/Brussels'); $timestamp = date('Y-m-d H:i:s'); $conn = mysql_connect('server', 'user', 'pw') or die(mysql_error()); mysql_select_db('hystudi_timesheets', $conn) or die(mysql_error()); $records = mysql_query("SELECT id, t_start_timestamp FROM timesheet ORDER BY id DESC LIMIT 1"); while ($row = mysql_fetch_array($records)) { $id = $row['id']; $start_timestamp = date("U", strtotime($row['t_start_timestamp'])); } $duration = (date("U", strtotime($timestamp)) - $start_timestamp) / 3600; // duration mysql_query("UPDATE timesheet SET t_end_timestamp = '$timestamp', t_calculated_time = '".round($duration,2)."' WHERE id = $id", $conn) or die(mysql_error()); ?> Anyone sees what I'm doing wrong here? Or could it be my server? It's a shared host I use my desktop (Windows) to make websites and then once it's completed transfer to my Linux server but I've come across a weird issue. On Windows the file location is like this: C:\Server\Apache\htdocs\RSCEmulation On Linux the file location is like this: /home/rscemulation/public_html Now in those folders I have a folder called 'include', in that I have 2 files: header.php, functions.php In the base folder I have index.php. I then include header.php by using: include "include/header.php"; Then I include functions.php (from header.php) by using: include "functions.php"; Now on Linux this chucks an error, even with "./functions.php" -- I have to use include "include/functions.php" even though I'm already in that directory from the file I'm calling it from, although admittedly the file is being included from the directory below but this works fine on Windows with a base PHP install. This Linux box was given to me and I'm not sure if any PHP settings have been changed or not. I also have a config.php that I keep below the public directory (htdocs or public_html) but it won't let me include it on the Linux server by using "../../config.php" (I've tried all levels ranging from 0-5 with no luck) Can anyone shed some light on this please? I need it to work the same both on the Windows and Linux boxes as I copy and paste the files regularly and it's annoying changing them! Cheers. Hello guys, this is so weird, very weird indded! PHP is generating some strange problem here over with me. Below are a short context of code that I have used to make a registration script. At the first inititial stage of code testing, everything goes well so smooth according to the plans. Then, I insert the Quote exit; function at the end of each Quote If() functions so as to curtail off completely from further execution of the script below and thereafter. Then, suddenly all the !ISSET values stop to functions. I then removed exit(); function off from my code and restore back to the last known good working stage of my code. But it seems like the ISSET function accompanied with the !(stop operator) cease to fucntion any more ever since then even though the script exhibit the same code when it was working normally good. It makes me wonder and now i'm totally frustrated, Please help!!! Now even all the operator values like ==, !=, <, > doesnt work anymore!!! P.S. I know someone would suggest me to write Quote if(!isset($_POST['Name'])) ......... in this format instead of Quote $Name but as i mentioned it earlier, i'm able to execute the script using the later one as desired in accordance to what is planned. Quote <?php $IP=$_SERVER['REMOTE_ADDR']; $Date=date('d/m/Y'); $proID=$_GET['proID']; $ref=$_GET['ref']; $Name=$_POST['Name']; $Email=$_POST['Email']; $Country=$_POST['Country']; $Username=$_POST['Username']; $Password=$_POST['Password']; $Con_Password=$_POST['Con_Password']; if(!isset($Name)) { header ('Location: reenter.php'); exit(); } if(!isset($Email)) { header ('Location: reenter.php'); exit(); } if(!isset($Country)) Hi guys, I am currently working on one of my assignments that requires PHP and think of myself as a beginner programmer, only having knowledge of Python and JavaScript. So I have a page that allows me to upload files to the server(no problem here), then I created a drop down menu that shows list of these and depending on which is selected can be viewed after clicking on a submit button(again no problem here). The problem occurs that after clicking submit to save the changes, it refreshes variable containing which file is the target and doesn't save the changes. Tried using sessions, but with no success and I am going absolutely crazy with this. I have been trying to resolve the issue for 5 hours straight. Here is the code if anyone is keen to help me out: <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>P2</title> <style> .uploadbox { background-color: skyblue; border: 1px, solid black; margin: 10px; padding: 5px; width: 20%; height: 10%; line-height: 50px; } .selectbox { background-color: skyblue; border: 1px, solid black; margin: 10px; padding: 5px; width: 25%; max-height: 50%; } </style> </head> <body> <h1>File Upload</h1> <form class="uploadbox" action="upload.php" method="post" enctype="multipart/form-data"> Select to upload: <input type="file" name="fileUpload1" id="fileUpload1"> <input type="submit" value="Upload file" name="submit"> </form> <br> <?php session_start(); $dirpath="uploads/"; $filenames=""; if(is_dir($dirpath)) { $files=opendir($dirpath); if($files) { while(($filename=readdir($files))!=false) if($filename!="." && $filename!="..") { $filenames=$filenames."<option>$filename</option>"; } } } $url = 'index.php'; $_SESSION['Open'] = htmlEntities($_POST['Open']); $file="uploads/".$_SESSION['Open']; // check if form has been submitted if (isset($_POST['text'])) { // save the text contents $newcontent = $_POST['text']; file_put_contents($file, $newcontent); // redirect to form again //header(sprintf('Location: %s', $url)); //printf(htmlspecialchars($url)); // exit(); } // read the textfile $text = file_get_contents($file); echo($newcontent); echo($file); echo($_SESSION['Open']); ?> <div class="selectbox"> <form action="" method="post"> <select name="Open"><?php echo $filenames; ?></select> <input type="submit" value="Open"/> </form> <form action="" method="post"> <textarea style="width:90%; height:20%;" name="text"><?php echo htmlspecialchars($text) ?></textarea> <br> <input type="submit" value="Save"/> </form> </div> </body> </html>
Need another set of eyes... I am getting: Quote Warning: Invalid argument supplied for foreach() in ... on line 83 $dup = array(); // Create an array to store the duplicate entries. foreach($fileList as $filename) { if (($handle = fopen(UPLOAD_PATH.$filename, "r")) != FALSE) { // Create the input array while(($data = fgetcsv($handle, 0, ",")) != FALSE) { $sql = "SELECT id FROM leads.prospect WHERE (email='{$data[3]}' OR phone='" . $format->stripPhoneChars($data[2]) . "') LIMIT 1"; $result = $db->query($sql); if (mysql_num_rows($result) == 0) { $sql = "INSERT IGNORE INTO leads.prospect (email, phone, ip, firstName, lastName, resort) VALUES ('" . trim($data[3]) . "', '" . $format->mysqlSafe($data[2]) . "', '" . $format->mysqlSafe($data[5]) . "', '" . $format->mysqlSafe($data[0]) . "', '" . $format->mysqlSafe($data[1]) . "', '" . $format->mysqlSafe($data[4]) . "')"; $result = $db->query($sql); $added++; } else { $dup = array_push($dup, array($data[0], $data[1])); } } fclose($handle); // Close the file } else { echo "<p>Could not load file $filename</p>"; } } echo "$added records added."; // Show me the duplicate data! echo "<h2>This is the data that would be dumped into the duplicate CSV file:</h2> <h3>" . count($dup)." Duplicates:</h3><ol>"; print_r($dup); echo $dup; foreach($dup as $d) { // <-------------------------------------- LINE 83 echo "<li>$d[0] $d[1] $d[2] $d[3]</li>"; } echo "</ol>"; For some reason both admin and home return home's contents but everything else returns it's own contents... <?php if(!isset($_GET['p'])) { $result = mysql_query("SELECT * FROM body WHERE name='home'"); ?> <script type="text/javascript">alert("home");</script> <?php } else{ $result = mysql_query("SELECT * FROM body WHERE name='" . $_GET['p'] . "'"); ?> <script type="text/javascript">alert("SELECT * FROM body WHERE name='<?php echo $_GET['p']; ?>'");</script> <?php } $row = mysql_fetch_array($result); function changeStuff($str) { $str = str_replace("[link=","<a href='",$str); $str = str_replace("[/link]","</a>",$str); $str = str_replace("[img]http://","<img src='",$str); $str = str_replace("[/img]","' />",$str); $str = str_replace("[b]","<b>",$str); $str = str_replace("[/b]","</b>",$str); return $str; } ?> if(!isset($_GET['p'])) { include("home.php"); } else{ include($_GET['p'] . ".php"); } echo changeStuff($row['content']); ?> There are three rows in my body table. They are as follows 1) (name) = home (content) = this is home page 2) (name) = admin (content) = this is admin page 3) (name) = eq (content) = this is equipment page When $_GET['p'] = home It displays this is home page When $_GET['p'] = admin It displays this is home page When $_GET['p'] = eq It displays this is equipment page The javascript alerts are all displaying the correct information so i don't understand what is fudging it up... Okay, real simple issue, hopefully someone has a simple solution. I have a single web page that needs to connect to TWO different databases. I've written everything in OO, and I'm getting a crazy situation where vars seem to be bleeding into each other. The problem goes like follows: I declare two SEPARATE database instances like so: require_once '/blah/classes/db/class.DBCMS.php'; require_once '/blah/classes/db/class.DBC.php'; $db1 = new DBC(); $db2 = new DBCMS(); I then pass in the $db(n) variables to a separate class to be used to process data like so: $publisher = new htmlCreator1($db1); $publisher = new htmlCreator2($db2); My problem is thus: INSIDE the respective different classes, my references to the $db vars seem to be colliding between instances. So $this->db->connection from db2 is referencing db1. The objects are defined like so: class htmlCreator1 { var $db; function __construct($db) { $this->db = $db; } } Shouldn't the respective $this->db's maintain their own namespace without extra work? I'm getting errors saying that tables in db2 aren't in db1 because of this collision as per the internal db instance vars. I have experimented with renaming all respective vars to unique names and still get the error. I'm crazy aren't I? Any help would be greatly appreciated. thanks, Dr. |