PHP - Okay, I've Been Looking At This Far Too Long... Please Help!
Hi All,
I am trying to call a javascript pop-up window via a link by echoing out the html via php but keep getting parse errors: Parse error: syntax error, unexpected ')', expecting ',' or ';' Here is the code in question: Code: [Select] echo "<td class=\"today\"> <a href=\"javascript:statusWindow('status.php?month=".$month."&day=".$day."&year=$year');\">"$day_num</a> </td>\n"; And here is the javascript function: Code: [Select] <script type="text/javascript"> function statusWindow(url){ status_popupWin = window.open(url, 'status', 'resizable=yes, scrollbars=yes, toolbar=no,width=400,height=400'); status_popupWin.opener = self; } </script> Any help is appreciated. Thanks, kaiman Similar TutorialsI would like to apply some addition functionality to a form which add news records into the database. Basicaly what i want is similar to what this forum does with the [ code ] [ /code ] but what i want for the user to be able to add [ quote ] [ /quote ] and when the post is viewed then that specific area of the acticle body will be formated diffrently. I hope this makes sence. Hey Folks This is a major long shot but is their a way that i can use php to upload one mp3 file and one doc file, then get the php script to place the mp3 file in one folder but also copy the mp3 file and make it into a zip file and place it into another folder as well as also make another copy of the mp3 file pair it with the doc file and make it into another zip file in yet another folder mp3->---------------------------->--mp3----------------->----mp3 into zip-------->--mp3 + doc into zip &---- > --Uploaded via php----->--placed in folder a--->----placed in folder b--->--placed in folder c doc-->---------------------------->--copied--------------->----mp3 copied--------->-- But thier is a catch the host i am using didn't activate ZipArchive() function so need a diferent way to make the zip file. Any Ideas people? because i have been pulling my hair out at this one please help Phil If I break up this long line of code will it still work correctly? Original... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Desired... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Or maybe... Code: [Select] define('WEB_ROOT', ENVIRONMENT === 'dev' ? 'http://localhost/example.org/' : 'http://example.org/'); Debbie Hello , I've this code its skip the weekend ,and I've a table for special events has field datetime. What I need when its come across this datetime skip it like it does with the weekend. there's the code Code: [Select] <?php$database_date = '2011-08-12, 07:00:00'; //this comes from your database, $updated_time = strtotime('+' . hoursLeft($database_date,7,16,24) . ' hours',strtotime($database_date)); //Handle the date:$new_date = date('m-d-Y, H:i:s',$updated_time); //this is when the email should be sent.echo date('m-d-Y, H:i:s',strtotime($database_date)) . '<br />' . $new_date . '<-- you should be emailing at this time!'; //just echo's it to the screen.function hoursLeft($time,$work_starts,$work_ends,$time_to_email,$skip_weekends = true) { //this function handles the count of how many hours you need to fulfill your task. $parts = explode(' ',$time); //split the time off of the date. list($hour, $minute, $second) = explode(':',$parts[1]); //get the hours, minutes, seconds. if($minute == 0) { //if the minutes is over 0, then return a full hour for it $hours = $work_ends - $hour; } else { //otherwise, take into account that this isn't a full hour. $hours = ($work_ends - 1) - $hour; } $day_count = 0; //original day count is 0; for($i = $work_ends,$count = $hours; $count <= $time_to_email; $i++) { //Start the increment at 16, the count at the current hours, keep the count below 25, increment on each loop. if($i > 24) { //if the increment is over 24, reset it to 0. $i = 0; ++$day_count; //increment day_count when i goes over 24 hour limit. if($skip_weekends == true) { //if you want to skip weekends $day = date('l',strtotime("+ {$day_count} days",strtotime($time))); //get the full text of the current day the hours are pointing to. if(in_array($day, array('Saturday','Sunday'))) { //and current day is in the weekend. $hours += 24; //add 24 hours to the count. continue; //restart loop, before any counting takes place. } } } if($i > $work_starts && $i <= $work_ends) { //if the increment is between 7 and 16, add to the count, which will break the loop at 24. $count += 1; } $hours += 1; //add to the hours, the loop breaks at a count of 24, which will give us the total hours to add to the updated_time above. } return $hours; //return hours}?> OUTPUT: Code: [Select] 08-12-2011, 07:00:0008-16-2011, 14:00:00<-- you should be emailing at this time!9 hours for Friday:9 hours for Monday:7 hours for Tuesday:= 24 hours. I'm waiting for your replys.. I'm working on a site that provides database results. To get to the final report, I'm going through a few pages where the user selects specific options. This builds up arrays that need to be passed from one page to another. As a result the final page has a pretty lengthy variable list. Since I want to provide a link to certain customers where they don't have to go through all the option select stuff, I'm using the GET method on the final page. Due to all the arrays I need to pass, I'm hitting hyperlink address character limitations, and I fear I will eventually hit browser URL length limits. Is there any way to provide links to customers without using the GET method so I could keep the URL length down? I try to get how long my message was sent with this... $Now = strtotime ("now"); $dateEnvoi = $fetchDiscussion['dateEnvoi']; //my date from my DB $timeEnvoi = mktime($dateEnvoi); $TempsEnvoi = $dateNow - $dateEnvoi; and it try to get how long it was post ... same thing as on facebook... like the 26 minutes ago from FB how can i do it ? Hi I'm trying to figure out how to calculate how long since a datevariable I have stored is from whenever the page is loaded.. I currently have a stored datevariable in the format: YYYY-MM-DD H:m:s ... So basically what I wish to accomplish is figuring out whenever i load the page which has stored this variable, how much time has passed. I want it to show up as for example : '10 minutes ago'.. '1 hour 25minutes ago' if it's the same day.. if its more than 1 day old it's enough to show only the number of days.....'1week 3 days ago' etc etc I keep getting this error, because people can track their support tickets by using a MD5 encrypted code upon submitting, and I'm wondering if maybe it's too long? Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'by FROM replies WHERE replyto = 'c8c3455c5efadc80b05316c412ab61e6' ORDER BY id D' at line 1 Query: Code: [Select] $replies = mysql_query("SELECT message,by FROM replies WHERE replyto = '$id' ORDER BY id DESC") or die(mysql_error()); is it possible to get an ajax call to execute a php script that will continue running even if the user leaves my site? i have used cron jobs and tokens to do in past but this can result in 1 min delay. I've written a script thats going to take a really long time to execute... Whats the best way to do this as far as the server not timing out? My script is calculating some statistics based on other tables in the database and then storing them in another table. The results are going to be hundreds of thousands or maybe even millions of rows. I have the following code on a page Code: [Select] <?PHP session_start();?> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=windows-1252"> <TITLE>Running Test Cricket</TITLE> </HEAD> <BODY> <?PHP echo "Time at start ".$_SERVER['REQUEST_TIME']; #This is our hourly updates for teams if it is due - it is set off by the variable 'teamUpdateTime' echo "<BR>1"; $updateTime=time(); #Get the current time and put it into the variable $teams = mysql_query("SELECT * FROM teams WHERE teamUpdateTime<'$updateTime'"); //Go through all the teams while($team = mysql_fetch_array($teams)) { echo "<BR>UPDATING - hourly - ".$team['name']; #Show the team we are updating include("../updates/hourly_update_team.php"); #Update all the teams that are due to be updated } echo "<BR>2"; mysql_close($sqldb); //Close the database echo "<BR>Time at end ".$_SERVER['REQUEST_TIME']; ?> </BODY></HTML>While the code is crude it is not for the public to see - it is for updating teams in an online game I am creating. What my problem is that the REQUEST_TIME at the start and end of the code are always outputted the same; the code is there to see how long the page takes to do. I sit there and count how long the page takes to activate (load, whatever the terminology is) and it can take up to 40 seconds - but the REQUEST_TIME tells me it takes 0 seconds so obviously something is wrong. My question is simple - how do I get this code to output the REQUEST_TIME when the code starts and when it finished, thus showing me how long it took for the page to load. I wish to do this to try and speed it up. James Guys, why the following mysql stored procedure taking much more time comparing with firebird one?
1. MySQL stored procedure
CREATE DEFINER=`lxc`@`::1` PROCEDURE `insertData`(IN it INT) BEGIN declare i int Default 0; declare str char(4); declare p_hash int; myloop: loop set p_hash = round(rand() * 999); set str='book'; insert into test.users (name,password) VALUES (concat(str,'_',i+1),PASSWORD(p_hash)); set i = i+1; if (i = it) then leave myloop; end if; end loop myloop; endObject info: Table: users Columns: id int(10) UN PK AI name varchar(45) password char(41)Time: mysql> call insertData(10000); Query OK, 1 row affected (9 min 38.22 sec)2. Firebird Stored Procedure SET TERM ^ ; CREATE PROCEDURE INSERDATA ( IT integer ) --iteration number AS DECLARE VARIABLE i integer; BEGIN i = 0; while ( i < it ) do begin INSERT INTO PRODUCT( CODE,NAME,PASS) VALUES(:i, 'jazz_' || :i, fb_hash(round(rand() * 999))); i = i + 1; end END^ SET TERM ; ^ COMMIT;Object Info: Table: product columns CODE integer, NAME varchar(45), PASS CHAR(41)Time: ( for 10 000 records it takes less than 1 sec for execution) Executing statement... Statement executed (elapsed time: 0.063s). 31464 fetches, 11084 marks, 0 reads, 0 writes. 10000 inserts, 0 updates, 0 deletes, 5 index, 0 seq. Delta memory: 24264 bytes. PRODUCT: 10000 inserts. 0 rows affected directly. Total execution time: 0.151s Script execution finished.Do you see something wrong in mysql stored procedure code? jazz. Edited by jazzman1, 31 July 2014 - 03:21 PM. Php programmers, I am getting this error: Fatal error: Uncaught mysqli_sql_exception: No index used in query/prepared statement (null) in C:\xampp\htdocs\test\select_adv.php:70 Stack trace: #0 C:\xampp\htdocs\test\select_adv.php(70): mysqli_stmt_execute(Object(mysqli_stmt)) #1 {main} thrown in C:\xampp\htdocs\test\select_adv.php on line 70
Line 70 is:
if(mysqli_stmt_execute($stmt) === FALSE)
Context:
if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$_SESSION['search_column']); if(mysqli_stmt_execute($stmt) === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); }
This removes the error:
if($stmt) === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); }
I still want to know why this works:
if($stmt) === FALSE) {
but this doesn't work:
if(mysqli_stmt_execute($stmt) === FALSE) {
Let me know.
Full Code in case you're wondering just what on earth is going on ....
<?php //include('error_reporting.php'); error_reporting(E_ALL); ini_set('error_reporting',E_ALL);//Same as: error_reporting(E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); require('conn.php'); echo __LINE__; ?> <form name = "search" method = "POST" action=""> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <label for="search_column">Search in ... ?</label> <select name="search_column" id="search_column"> <option value="page_url">Page Url</option> <option value="link_anchor_text">Link Anchor Text</option> <option value="page_description">Page Description</option> <option value="keyphrases">Keyphrase</option> <option value="keywords">Keywords</option> </select> <br> <label for="tos_agreement">Agree to TOS or not ? *</label> <select name="tos_agreement" id="tos_agreement" required> <option value="Yes">Yes</option> <option value="No">No</option> </select> <br> <button type="submit">Submit</button><br> <button type="submit" value="submit">Submit</button><br> <input type="submit" value="submit"><br> <button name=submit value=" ">Submit</button><br> <br> <input type="reset"> <br> </form> <?php session_start(); echo __LINE__; if($_SERVER['REQUEST_METHOD'] === 'POST') { echo __LINE__; if(ISSET($_POST['submit'])) { echo __LINE__; if(ISSET($_POST['search_column'])) { $_SESSION['search_column'] = $_POST['search_column']; echo $_SESSION['search_column']; echo __LINE__; } //Re-write the following 4 lines ... mysqli_report(MYSQLI_REPORT_ALL|MYSQLI_REPORT_STRICT); $conn = mysqli_connect("localhost","root","","test"); $conn->set_charset("utf8mb4"); //$query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE $_SESSION['search_column'] = ?"; $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE {$_SESSION['search_column']} = ?"; //$query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE " . $_SESSION['search_column'] . " = ?"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$_SESSION['search_column']); if(mysqli_stmt_execute($stmt) === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); } $result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); mysqli_stmt_fetch($stmt); while(mysqli_stmt_fetch($stmt)) { echo "url"; echo "<br>"; echo "anchor_text"; echo "<br>"; echo "description"; echo "<br>"; echo "keyphrases"; echo "<br>"; echo "keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { echo "1. QUERY failed!"; } if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'sssss',$_POST['page_url'],$_POST['link_anchor_text'],$_POST['page_description'],$_POST['keyphrases'],$_POST['keywords']); if(mysqli_stmt_execute($stmt) === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); } $result = mysqli_stmt_get_result($stmt); while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { $page_url = $row['page_url']; echo $page_url; echo "<br>"; $link_anchor_text = $row['link_anchor_text']; echo $link_anchor_text; echo "<br>"; $page_description = $row['page_description']; echo $page_description; echo "<br>"; $keyphrases = $row['keyphrases']; echo $keyphrases; echo "<br>"; $keywords = $row['keywords']; echo $keywords; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("2. QUERY failed!"); } echo '<pre>' . print_r($_POST, 1) . '</pre>'; echo $_SESSION['search_column']; } } echo __LINE__; ?>
hi i need the following done for my site, and i have no idea how cause i suck at php i have a toplist site and i want users to only be able to vote once in 24 hrs, and i want to put a recapcha, i know i need public and private keys i have them also could you please give me a snippet of the finished code instead of explaining it, i tend to learn from from editing code then reading so hers the 2 vote files the first one is where they type the name and click vote, 2nd performs the vote first: Code: [Select] <center><form action="voted.php" method="post"> <table border="0" bordercolor="" style="background-color:" width="400" cellpadding="3" cellspacing="3"> <tr> <td>Site name:</td> <td><input type="text" name="title" /></td> </tr> </table> <input type="submit" value="Vote" ></input></center> </form> and 2nd code: Code: [Select] <?php include("config.php"); mysql_query("UPDATE sites SET votes = votes + 1 WHERE title = '$_POST[title]'"); echo "Voted!"; mysql_close($con); ?> ok i would also like a better control panel, instead of having just site name: password: description: [edit] if it where possible id like to have a cpanel that has site name: password: then redirects to another page where you can edit it, if you can't/wont do this for any reason i will settle for just a peie of code to say "invalid username or password" if details are incorrect so heres my code Code: [Select] <?php include("config.php"); mysql_query("UPDATE sites SET content = '$_POST[content]' WHERE title = '$_POST[title]' AND password = '$_POST[password]'"); mysql_query("UPDATE sites SET link = '$_POST[link]' WHERE title = '$_POST[title]' AND password = '$_POST[password]'"); echo "Site Updated"; mysql_close($con); ?> and the html bit Code: [Select] <center><form action="edit.php" method="post"> <table border="0" bordercolor="" style="background-color:" width="400" cellpadding="3" cellspacing="3"> <tr> <td>Site name:</td> <td><input type="text" name="title" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" /></td> </tr> <tr> <td>Link to site:</td> <td><input type="text" name="link" /></td> </tr> <tr> <td>Description:</td> <td><textarea name="content" ></textarea></td> </tr> </table> <input type="submit" value="Edit Site" ></input></center> </form> </body> </html> ok i hope you can help, ill try to make this have the best punctuation i can, and please dont tell me how insecure these codes are i have been informed plenty of times I'm working on a website that displays data based on when a file is created. The page keeps checking to see whether or not a file exists. As long as the file doesn't exist, the page keeps reloading and checking to see whether or not the file exists until the file finally does exist. Once the file exists, the page goes to another page that displays the contents of the file that it was waiting for. This design works, but I've noticed that it takes a long time for the page to recognize that the file exists. Once the file exists, the page keeps checking and reloading, several times -- even though the file exists. After many reloads, it finally "sees" the file and goes on to the next page. Why does it take so long for my page to recognize the existence of the file? Here's a sample of how the reloading page (the page that keeps checking for the existence of the file) works. <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past session_set_cookie_params(0); session_start(); ?> <html> <head> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='expires' content='0'> <meta http-equiv='pragma' content='no-cache'> </head> <body> <p>Processing...</p> <script> myFunction(); function myFunction() { setInterval(function(){ location.reload(); <?php clearstatcache(); if(file_exists($_SESSION['filename'])) { $existance = true; } else { $existance = false; } ?> if("<?php echo $existance ?>") { window.open("done.php","_self"); } else { } }, 5000); } </script> </body> </html> As you can see, I use the "clearstatcache();" statement in order to make sure that the server's information is current before checking the existence of the file. I have also used meta tags, in the HTML, and php headers in order to make sure that nothing is being cached. This is all in an attempt to make sure that it's not looking at old data when it checks to see if the file exists. Despite all of this, the browser keeps reloading, over and over again, usually about ten times, even after the file exists. Any ideas why this is happening? Edited by Maq, 10 July 2014 - 03:52 PM. Hello Guys, I need some help here.. I am trying to extract the lat and long from a json query from google. Here is what I receive back from json { "name": "795PollardBlvdSW,Atlanta,GA", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "Atlanta, GA, USA", "AddressDetails": { "Accuracy" : 4, "Country" : { "AdministrativeArea" : { "AdministrativeAreaName" : "GA", "SubAdministrativeArea" : { "Locality" : { "LocalityName" : "Atlanta" }, "SubAdministrativeAreaName" : "Fulton" } }, "CountryName" : "USA", "CountryNameCode" : "US" } }, "ExtendedData": { "LatLonBox": { "north": 33.8231844, "south": 33.6747422, "east": -84.2599230, "west": -84.5160418 } }, "Point": { "coordinates": [ -84.3879824, 33.7489954, 0 ] } } ] } Here is the code I am using $geocode=file_get_contents('http://maps.google.com/maps/geo?output=json&q=795PollardBlvdSW,Atlanta,GA'); $output= json_decode($geocode); $lat = $output->results[0]->geometry->location->lat; $long = $output->results[0]->geometry->location->lng; echo $lat; echo $long; Just not sure how to pull the lat and long out of a json into vars.. Please advise.. Dan I have several registration systems that were designed some time ago running mysql. How long do I have until I have to competely move to mysqli? I am working on recoding them, but it is taking some time. Does anyone know when it will become an issue?
Hi Professionals
I am currently going through the process of grading my website in MOZ tools and getting over 2000 URLs to crawl errors
The url I have is currently
www.myurl.com.au/hotel_details.php?hotel_id=358705¤cy_code=AUD&q=%27%3A%2F%2Fwww.travelnow.com%2Ftemplates%2F451536%2Fhotels%2F358705%2Foverview%3Flang%3Den%26amp%3Bcurrency%3DAUD%26amp%3BstandardCheckin%3D12%2F17%2F2014%26amp%3BstandardCheckout%3D12%2F18%2F2014%26amp%3BroomsCount%3D1%26amp%3Brooms[0].adultsCount%3D2%27&price=149&totlday=1 How or where would I go about re-writing this I am not a professional with PHP and I have never done anything like this beforeThanks in advance heya all this is my first post, Basically, I have a script that I want it to execute a certain loop that will go on for days or several hours. The delay in execution is intentional and is implemented using the sleep() function. If entered the path to the script in the URL bar and executed it, after I close the tab, would it be still executing in the server? And how do I check it's progress (Like should I implement it to write its progress to a separate text file that I check daily for example)?? Thanks in advance. |