PHP - Script Interpretation Not Making Complete Sense. Please Help.
I am doing more practice, and I am trying to interpret the WHY on some certain aspects of this script. I can get it to work and it works as expected, but I am not sure what it works (got most of it sorted it).. Here is my first question:
Question 0. About 3/4 down the script: ($i = 0; $i < $cols; $i++) - cannot understand why $i < $cols is less operator? Shouldn't it be >= cause if it's less won't it miss a record? Question 1. About 3/4 down the script: echo $x = ($i * $rows) + $j; I do not understand what purpose this serves. I echoed the results and it's just scattered multiplication large numbers! You'll see that im echoing out all kinds of data, just so I can see what's going on. <?php $host = "localhost"; $user = "root"; $pass = ""; $db = "simple_mysql"; $cxn = mysqli_connect($host, $user, $pass, $db) or die("Could not connect to the server."); $query = "SELECT * FROM all_illinois"; $result = mysqli_query($cxn, $query) or die(mysqli_error()); $results = array(); while ($row = mysqli_fetch_assoc($result)) $results[] = $row; // output: Array echo $results . "<br />"; $cols = 3; // output: 3 echo $cols . "<br />"; $rows = ceil(count($results) / $cols); // output: 1300 echo(count($results)) . "<br />"; // output: 3 echo $cols . "<br />"; // output: 434 echo $rows . "<br />"; echo '<table style="text-align:left;margin-left:0px;width:500px;">' . "\n"; for ($j = 0; $j < $rows; $j++) { echo " <tr>\n"; for ($i = 0; $i < $cols; $i++) { echo $x = ($i * $rows) + $j; echo $i . "<br />"; if (isset($results[$x])) { $row = $results[$x]; echo $row . "<br />"; echo ' <td><a href="' . $row['state_id'] . '/' . $row['city_name'] . '">' . $row['city_name'] . "</a></td>\n"; } else { echo " <td></td>\n"; } } echo " </tr>\n"; } echo '</table>'; ?> Here is a smaller portion of table dump if it helps at all: -- -- Table structure for table `all_illinois` -- CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `all_illinois` -- INSERT INTO `all_illinois` (`state_id`, `city_name`) VALUES ('135', 'Abingdon'), ('135', 'Adair'), ('135', 'Addieville'), ('135', 'Addison'), ('135', 'Adrian'), ('135', 'Akin'), ('135', 'Albany'), ('135', 'Albers'), ('135', 'Albion'), ('135', 'Alden'), ('135', 'Aledo'), ('135', 'Alexander'), ('135', 'Alexis'), ('135', 'Algonquin'), ('135', 'Alhambra'), ('135', 'Allendale'), ('135', 'Allerton'), ('135', 'Alma'), ('135', 'Alpha'), ('135', 'Alsey'), ('135', 'Alsip'), ('135', 'Altamont'), ('135', 'Alto Pass'), ('135', 'Alton'), ('135', 'Altona'), ('135', 'Alvin'), ('135', 'Amboy'), ('135', 'Anchor'), ('135', 'Ancona'), ('135', 'Andalusia'), ('135', 'Andover'), ('135', 'Anna'), ('135', 'Annapolis'), ('135', 'Annawan'), ('135', 'Antioch'), ('135', 'Apple River'), ('135', 'Arcola'), ('135', 'Arenzville'), ('135', 'Argenta'), ('135', 'Arlington'), ('135', 'Arlington Heights'), ('135', 'Armington'), ('135', 'Armstrong'), ('135', 'Aroma Park'), ('135', 'Arrowsmith'), ('135', 'Arthur'), ('135', 'Ashkum'), ('135', 'Ashland'), ('135', 'Ashley'), ('135', 'Ashmore'), ('135', 'Ashton'), ('135', 'Assumption'), ('135', 'Astoria'), ('135', 'Athens'), ('135', 'Atkinson'), ('135', 'Atlanta'), ('135', 'Atwater'), ('135', 'Atwood'), ('135', 'Auburn'), ('135', 'Augusta'), ('135', 'Aurora'), ('135', 'Ava'), ('135', 'Aviston'), ('135', 'Avon'), ('135', 'Baileyville'), ('135', 'Baldwin'), ('135', 'Bardolph'), ('135', 'Barnhill'), ('135', 'Barrington'), ('135', 'Barry'), ('135', 'Barstow'), ('135', 'Bartelso'), ('135', 'Bartlett'), ('135', 'Basco'), ('135', 'Batavia'), ('135', 'Batchtown'), ('135', 'Bath'), ('135', 'Baylis'), ('135', 'Beardstown'), ('135', 'Beason'), ('135', 'Beaverville'), ('135', 'Beckemeyer'), ('135', 'Bedford Park'), ('135', 'Beecher'), ('135', 'Beecher City'), ('135', 'Belknap'), ('135', 'Belle Rive'), ('135', 'Belleview'), ('135', 'Belleville'), ('135', 'Bellflower'), ('135', 'Bellmont'), ('135', 'Bellwood'), ('135', 'Belvidere'), ('135', 'Bement'), ('135', 'Benld'), ('135', 'Bensenville'), ('135', 'Benson'), ('135', 'Benton'), ('135', 'Berkeley'), ('135', 'Berwick'); Similar TutorialsThis topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358619.0 Hi, I am trying to write an input form for a table that the fields contains codes of records from other tables. Is there a way that after each field I can retrieve (validate) the value of the fields that contain a code from a table and display them on the screen when the use move to the next field? The table is a customers order and I want to validate and display the customer name after they key in the customer code and the same for the product's code. Thank! James I would be needing different picture sizes on different pages on my site but saving different sizes of a single pic is space consuming. I've heard that it's possible to automatically adjust the size of the picture and found a script that ought to make that possible. Unfortunately, it did not work for me. Article: PHP Thumbnail Script Using GD http://www.rainbodesign.com/pub/thumbnails/ Here's the code: Code: [Select] <? // Rainbo Design PHP Thumbnail Maker // Copyright (C) 2005-2010 by Richard L. Trethewey - rick@rainbo.net // All Rights Reserved // If you use this script, I'd appreciate a link! // http://www.rainbodesign.com/pub/ // Defaults $thumbsize = 150; // Default thumbnail width. $imagesource = 'images/default_img.jpg'; // Default image file name. // Set to empty string for no image output on failure. $error = ''; if (isset($_GET['width'])) { $thumbsize = $_GET['width']; } if (isset($_GET['src'])) { $imagesource = $_GET['src']; } $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if (file_exists($imagesource)) { if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); $imagewidth = imagesx($image); $imageheight = imagesy($image); if ($imagewidth >= $thumbsize) { $thumbwidth = $thumbsize; $factor = $thumbsize / $imagewidth; $thumbheight = floor($imageheight * $factor); } else { $thumbwidth = $imagewidth; $thumbheight = $imageheight; $factor = 1; } // Create a thumbnail-sized GD Image object $thumb = @imagecreatetruecolor($thumbwidth,$thumbheight); // bool imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h ) imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight); // Send output to user as a jpeg type, regardless of original type header("Content-type:image/jpeg;"); imagejpeg($thumb); imagedestroy($image); imagedestroy($thumb); } else { $error = "File $imagesource Not Found"; } // endif file_exists if ($error != '') { header('Content-type:text/plain;'); echo($error); exit; } // endif $error ?> And here's a little instruction (which I have followed as well). Quote All it takes is replacing the "src" parameter in the <img> tag with the URL for the PHP script, including the parameters "src" which contains the path to the original image file, and "color" to select the color for the font. The script also supports a "width" parameter to specify the width of your thumbnail image. Using that script to display the above image as a thumbnail by setting the "src" attribute to "makeThumb.php?src=slides/slide1.jpg", we get the resulting image shown on the right. Can anyone please help me with this script or something similar? Thanks in advance. ^_^ Edit: The problem is that the image is not showing. It appears as if it cannot locate the file source. i need help on this one. i am aiming to make my own smaller version of tineye.com or something similar i do have a function that will compare 2 images in GD. all i have to figure out now is how to spider the default image off of major networking sites like facebook,myspace etc. and list all the results found and the similarity of each picture. the function is something like compare_imgs($path,$source_pic,$comparison_pic) { } How can I make my PHP script non accessible to users? I am wanting to cron the script and don't want anybody to spam the script as it would cause performance issues if it was constantly spammed by a user. Can I put the PHP file anywhere that only the server can run it?
Thanks any info would be awesome.
I have two scripts in question here one is getjob.php <-- here you enter an IPaddress and click connect and it takes you too npchome.php what I don't understand is if I go striaght to npchome.php it pulls up the page, however if I get there but clicking submit in getjob.php it brings up nothing just white page but the address bar tells me i'm at npchome.php I don't understand why? getjob.php <?php session_start(); if (!isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href='index.php'>GO BACK</a> and try again"; exit(); } ?> <style type="text/css"> <!-- .style2 { font-size: xx-large; font-style: italic; font-weight: bold; } .style3 { font-size: 18px; color: #FFFFFF; } <p style="font-size:.5px"> .style4 {color: #FFFFFF} .style4 {color: #FFFFFF} .tabledata th, td{color: #FFFFFF;} --> </style> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td width="100%" height="79" valign="top" bgcolor="#000000"><div align="center"> <p class="style2 style3 style4">HEAVENSHACKERS - JOB BOARD v1.0 </p> <p class="style2 style3 style4">"once your job has been completed return here and hand in"</p> </div></td> </tr> <tr> <td height="31" valign="top"><div align="center"> <form action="npchome.php" method="POST"> <p> <input type="text" name="npcip" size='22'> <input type="submit" name="submit" value="CONNECT" /> </p> <p><img src='images/accept.png' /> <span class="style4">= Accept Job</span> | <img src='images/handin.png' /> <span class="style4">= Hand In Job</span></p> </form> </div></td> </tr> <tr> <td height="315" valign="top"> <div align="center"> <?php $userlevel = $_SESSION['userlevel']; //include connect include('connect_live.php'); // include('connect_local.php'); $query = mysql_query("SELECT * FROM site_jobs WHERE level_required ='$userlevel'") or die ("Could Not query npc Database"); echo "<table width='750' border='1' class='tabledata'><tr><th><font size='1'>NPC NAME</font></th><th><font size='1'>JOB DESCRIPTION</font></th><th><font size='1'>LEVEL</font></th><th><font size='1'>EXPERIENCE</font></th><th><font size='1'>CASH</font></th><th><font size='1'>ACTION</font></th></tr>"; while ($row = mysql_fetch_array($query)) { //set varibles from query $npc_name = $row['npc_name']; $level_required = $row['level_required']; $job_title = $row['job_title']; $expr_offered = $row['expr_offered']; $cash_offered = $row['cash_offered']; $job_status = $row['job_status']; $longmsg = $row['longmsg']; $welcomemsg = $row['welcomemsg']; $npclogfile = $row['npclogfile']; //set session varibles $_SESSION['npcip'] = $npcip; $_SESSION['welcomemsg'] = $welcomemsg; $_SESSION['longmsg'] = $longmsg; $_SESSION['npclogfile'] = $npclogfile; //end getting varibles echo "<tr align='center'><td>$npc_name</td><td align='left'>$job_title</td><td>$level_required</td><td>$expr_offered</td><td>$cash_offered</td><td><a href='accept.php'><img border='0' src='images/accept.png'></a> <a href='handin.php'><img border='0' src='images/handin.png'></a></td></tr>"; } ?></div></td> </tr> </table> npchome.php <?php session_start(); if (!isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href='index.php'>GO BACK</a> and try again"; exit(); } else { if ($_SESSION['username']) { $player = $_SESSION['username']; $userlevel = $_SESSION['userlevel']; $cracker = $_SESSION['cracker']; $systemkey = $_SESSION['systemkey']; $IP_snooper=$_SESSION['IP_snooper']; // check for submit $submit = $_POST['submit']; // $npcip = ip2long($_POST['npcip']); //database format for compare $npcip =$_POST['npcip']; $_SESSION['npcip'] = $npcip; } } //start connection with server to check if IP is valid include('connect_live.php'); $sql2 = mysql_query ("SELECT * FROM site_jobs WHERE IPaddress='$npcip'"); $query = mysql_fetch_array($sql2) or die (mysql_error()); // $welcomemsg = $sql2['welcomemsg']; $rows = mysql_num_rows($sql2); //we have the result of the row count we want that if it's 0 to echo no service found at address; else if more than 0 bring up that account ?> <!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>Heavens Hackers : Virtual Online Hacking Simulation</title> </head> <body alink="#FFFFFF" vlink="#FFFFFF" link="#FFFFFF"> <table width="650" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td width="10" height="36"> </td> <td width="630"> </td> <td width="10"> </td> </tr> <tr> <td height="39"></td> <td align="center" valign="center"><form action="npchome.php" method="post"> <a href="getjob.php"><img src="images/home.png" width="26" height="26" border="0" /></a> <input type="text" name="npcip" size="60" /> <input type="submit" name="submit" value="CONNECT" /> </form></td> <td></td> </tr> <tr> <td height="195" colspan="3" valign="top"><table background="images/u2uimg.jpg" width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="13" height="18"></td> <td width="624"></td> <td width="13"></td> </tr> <tr> <td height="58"></td> <td valign="top"><div align="center"> <?php if ($rows==0) { echo "<font color='#ffffff'>No Service Found At<br /></font><font color='#ffffff'>" .long2ip($npcip)."</font><br />"; echo "<a href='getjob.php'>Please go back and try again</a>"; exit(); } else { //display information to crack said IP address echo "<font size ='medium' color='#ffffff'>You were able to ping<br /></font><font color='#ffffff'>" .long2ip($npcip)."</font>"; } ?> </div></td> <td></td> </tr> <tr> <td height="34"> </td> <td> </td> <td></td> </tr> <tr> <td height="85" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="219" height="66" valign="top"><div align="center"><?php echo "<font color='#ffffff'><br /><a href='cracknpc.php'>".$cracker."</a></font>"; ?> </div></td> <td width="215" valign="top"><div align="center"><?php echo "<font color='#ffffff'><br /><a href='crack_ipsnppoernpc.php'>".$IP_snooper."</a></font>"; ?> </div></td> <td width="216" valign="top"><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height="19"> </td> <td> </td> <td> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td align="center" height="92" colspan="3" valign="top"><img src="images/u2uimg2.jpg" width="650" height="92" /></td> </tr> <tr> <td height="270" colspan="3" align="center" valign="top"> <?php //welcome message for IP connected to echo $welcomemsg; ?> </tr> </table> </body> </html> Hello community, I am working on a database of specialties in the hospital I work. The doctor's referral requests are sent to a mySQL database and I have, with the help of online guidance, produced a working php script that displays the information I need it to. However, I need it a little bit more specific. I intend to make multiple copies of this file for each specialty, so that when they open the file they only have the requests for that particular specialty. My question is, with reference to my code below, can I make echo information so that online, for instance, if 'specialty1 = gastroenterology' (as in, that particular specialty that that referral request is for), then only the rows on the database that have that particular text are displayed only? Hope that makes sense. Code below for your reference and assistance is highly appreciated. <!DOCTYPE html> <html> <head> <title>Specialty Referral Form</title> <style> table { border-collapse: collapse; width: 100%; color: #000000; font-family: arial; font-size: 10px; text-align: center; } th { background-color: #588c7e; color: white; } tr:nth-child(even) {background-color: #f2f2f2} </style> </head> <body> <table> <tr> <th>Patient Details</th> <th>Hospital Number</th> <th>Date of Birth</th> <th>Referred by:</th> <th>New/Repeat Visit to Patient</th> <th>Specialty</th> <th>Admission Date</th> <th>Too Ill for Clinic?</th> <th>Diagnosis Aware?</th> <th>Question</th> <th>History</th> <th>Medications</th> <th>Examination</th> <th>Results</th> <th>WorkingDiagnosis</th> <th>Investigation(s) Requested</th> </tr> <?php $conn = mysqli_connect("localhost", "view", "", "referral"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT patientdetails, hospitalnumber, DoB, referral, admission, specialty1, admissiondate, illness, awareness, question, history, medications, examination, results, workingdiagnosis, investigations FROM referralform"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while ($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["patientdetails"]. "</td><td>" . $row["hospitalnumber"] . "</td><td>" . $row["DoB"] . "</td><td>" . $row["referral"] . "</td><td>" . $row["admission"] . "</td><td>" . $row["specialty1"] . "</td><td>" . $row["admissiondate"] . "</td><td>" . $row["illness"] . "</td><td>" . $row["awareness"] . "</td><td>" . $row["question"] . "</td><td>" . $row["history"] . "</td><td>" . $row["medications"] . "</td><td>" . $row["examination"] . "</td><td>" . $row["results"] . "</td><td>" . $row["workingdiagnosis"] . "</td><td>" . $row["investigations"]. "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> </html> I guess what I am looking for is something like echo specialty1 IF it writes a particular specialty and only that specialty. Thank you. Edited April 2, 2020 by samanjThis code was extracted from phpwebsockets server from google:
All I am trying to do is grab the USERS IP ADDRESS. The php code won`t redirect to user/member.php need some help <?php session_start(); include 'includes/database.php'; if(isset($_POST['login'])) { $username = trim(addslashes($_POST['username'])); $password = md5(trim($_POST['password'])); $query = mysql_query("SELECT * FROM Users WHERE Username = '$username' AND Password = '$password' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_array($query); if(mysql_num_rows($query) > 0) { if($row['Activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; header("Location: user/member.php"); } else { echo "You have to activate your account!"; } } } else { echo "You have to fill out the login form!"; } ?>
I am testing some new code, trying to learn me some OOP. I know the SQL works because I tested it in phpmyadmin. There is something wrong and I cannot fathom why, <? $site= '15'; Class Dbh { private $user='xxx'; private $pass='xxx'; private $db='xxx'; private $host='localhost'; private $charset = 'utf8mb4'; protected function connect() { $dsn = 'mysql:host='.$this->host.'; dbname='.$this->db.';charset='.$this->charset; $pdo = new PDO($dsn, $this->user, $this->pass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); return $pdo; } } Class GetData extends Dbh { public function gettable($site) { $sql = "SELECT table_cats.tablec_name, tables.table_question, tables.table_answer FROM table_cats INNER JOIN tables ON table_cats.tablec_id = tables.table_cat WHERE table_cats.tablec_site = ? ORDER BY table_cats.tablec_name"; $stmt = $this->connect()->prepare($sql); $stmt->execute($site); $fcid = $stmt->fetchAll(); foreach ($table as $table) { echo $table["tablec_name"]."<br /><br />"; echo $fquest = $table["table_question"]."<br /><br />"; echo $table["table_answer"]."<br /><br />"; } } } $tableob = new getData(); $tableob->gettable($site); The error messages I am getting are as follows [24-Feb-2021 06:02:34 UTC] PHP Warning: PDOStatement::execute() expects parameter 1 to be array, string given in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 32 [24-Feb-2021 06:02:34 UTC] PHP Notice: Undefined variable: faq in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 35 [24-Feb-2021 06:02:34 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/imagimediaco/public_html/entrepreneur.za.bz/faq.php on line 35
Line 32 is this line. $stmt->execute($site); I suspect the faq variable is undefined because it's not being populated because it expects $site to be an array, Why is an array expected for $site? Please explain to me in simple terms, I can be a little stupid. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349030.0 Hi everyone. I'm completely new to PHP. I've been trying to teach myself to code with it and learn as much as I can for the past few days because it'll definitely come in handy. So far, everything I've learned is just from articles and videos.
Anyway, let's skip the boring stuff.
For literally the whole day today, I've been trying to figure out what the heck is wrong with a script I'm working with. I didn't code it myself. I'm pretty much just modifying it to fit my needs from the generic "template" it comes in.
So here's the issue:
The script is basically used to run a website with user generated content. Users can upload images and write about them. One file of the script deals with the page where the user writes and submits his/her content. Before, I had no issues. I could write a title, a few sentences, upload an image and submit it to the server. Now, seemingly out of nowhere, I'm getting problems everywhere.
Here are the issues:
1. After I fill out the form and hit submit, the page doesn't redirect to my content.
2. As soon as I hit the submit button, the page goes blank (white screen) and gets stuck on mydomain.com/submit (which is the same page where I filled out the form)
3. Along with the white screen, I'm getting the following error on top of it:
Notice: Undefined index: name in .../public_html/include/p-page-ask.php on line 126
I've spent the last 12 hours trying to fix this. For issue 3, I've read that you can use the "isset" function to fix it. But I have no idea how to code that into it. I tried different variations, but none worked to make it go away. For issue 2, I'm guessing this is a fatal php error? I have no idea what's causing it. If I view source, I just get a blank page. For issue 1, I'm guessing this has to do with issue 2 halting the page from redirecting? I'm pretty sure 2 and 3 are different errors because I've read that even if 3 occurs, the page still loads.
I've turned on all the error reporting and display functions in my php.ini file. I made sure that the server is using that particular file with phpinfo(). (Although I didn't restart my server. I have no idea how to. I'm on a shared environment). After making these changes, I still don't see any additional errors, just the notice on a blank page.
I've looked through the code for syntax errors, but couldn't find any.
I've even installed xampp and made a test environment. I read through the documentation and watched tutorials on YouTube to set it up. (I've had absolutely 0 experience with this kind of stuff). I downloaded all the exact files from my online server into my localhost environment. Funny enough, it works just fine on my machine. It doesn't even throw errors locally. However, it doesn't work online. What the heck is going on?
The only differences I can think of between the two environments are the php versions and sql database versions (xampp is newer)...but I don't know if that really makes a difference because the script USED to work on my server, so it must be compatible with the set versions.
I've been editing the files in the script for quite a while now. I know when I first started, the uploads would work just fine. Then I didn't upload for a while because I already tested it out and knew it worked, so I just continued working on the script. I may have modified something that's now causing the errors. But then wouldn't that cause the localhost environment to fail too? If the files are exactly the same, how could one fail to work? That makes no sense at all. I'm looking at this code lost and hopeless. I'm getting sad.
If ANYONE has any suggestions on fixing this, PLEASE let me know. I don't know what to do anymore.
If you need me to upload any of the other files, just ask.
Here are the error logs from the server:
PHP Notice: Undefined index: name in .../public_html/include/p-page-ask.php on line 126, referer:mydomain.com/submit
...public_html/submit: No such file or directory WARNING: .../public_html/submit: Can't access file Here's the code for the page with the notice: <?php if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser header('Location: ../'); exit; } require_once QA_INCLUDE_DIR.'p-app-format.php'; require_once QA_INCLUDE_DIR.'p-app-limits.php'; require_once QA_INCLUDE_DIR.'p-db-selects.php'; require_once QA_INCLUDE_DIR.'p-util-sort.php'; // Check whether this is a follow-on question and get some info we need from the database $in=array(); $followpostid=qa_get('follow'); $in['categoryid']=qa_get_category_field_value('category'); if (!isset($in['categoryid'])) $in['categoryid']=qa_get('cat'); $userid=qa_get_logged_in_userid(); list($categories, $followanswer, $completetags)=qa_db_select_with_pending( qa_db_category_nav_selectspec($in['categoryid'], true), isset($followpostid) ? qa_db_full_post_selectspec($userid, $followpostid) : null, qa_db_popular_tags_selectspec(0, QA_DB_RETRIEVE_COMPLETE_TAGS) ); if (!isset($categories[$in['categoryid']])) $in['categoryid']=null; if (@$followanswer['basetype']!='A') $followanswer=null; // Check for permission error $permiterror=qa_user_maximum_permit_error('permit_post_q', QA_LIMIT_QUESTIONS); if ($permiterror) { $qa_content=qa_content_prepare(); // The 'approve', 'login', 'confirm', 'limit', 'userblock', 'ipblock' permission errors are reported to the user here // The other option ('level') prevents the menu option being shown, in qa_content_prepare(...) switch ($permiterror) { case 'login': $qa_content['error']=qa_insert_login_links(qa_lang_html('question/ask_must_login'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null); break; case 'confirm': $qa_content['error']=qa_insert_login_links(qa_lang_html('question/ask_must_confirm'), qa_request(), isset($followpostid) ? array('follow' => $followpostid) : null); break; case 'limit': $qa_content['error']=qa_lang_html('question/ask_limit'); break; case 'approve': $qa_content['error']=qa_lang_html('question/ask_must_be_approved'); break; default: $qa_content['error']=qa_lang_html('users/no_permission'); break; } return $qa_content; } // Process input $captchareason=qa_user_captcha_reason(); $in['title']=qa_post_text('title'); // allow title and tags to be posted by an external form $in['extra']=qa_opt('extra_field_active') ? qa_post_text('extra') : null; $in['tags']=qa_get_tags_field_value('tags'); if (qa_clicked('doask')) { require_once QA_INCLUDE_DIR.'p-app-post-create.php'; require_once QA_INCLUDE_DIR.'p-util-string.php'; $categoryids=array_keys(qa_category_path($categories, @$in['categoryid'])); $userlevel=qa_user_level_for_categories($categoryids); $in['notify']=qa_post_text('notify') ? true : false; $in['email']=qa_post_text('email'); $in['queued']=qa_user_moderation_reason($userlevel) ? true : false; qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']); $errors=array(); if (!qa_check_form_security_code('ask', qa_post_text('code'))) $errors['page']=qa_lang_html('misc/form_security_again'); else { $filtermodules=qa_load_modules_with('filter', 'filter_question'); foreach ($filtermodules as $filtermodule) { $oldin=$in; $filtermodule->filter_question($in, $errors, null); qa_update_post_text($in, $oldin); } if (qa_using_categories() && count($categories) && (!qa_opt('allow_no_category')) && !isset($in['categoryid'])) $errors['categoryid']=qa_lang_html('question/category_required'); // check this here because we need to know count($categories) elseif (qa_user_permit_error('permit_post_q', null, $userlevel)) $errors['categoryid']=qa_lang_html('question/category_ask_not_allowed'); if ($captchareason) { require_once 'p-app-captcha.php'; qa_captcha_validate_post($errors); } if (empty($errors)) { $cookieid=isset($userid) ? qa_cookie_get() : qa_cookie_get_create(); // create a new cookie if necessary $questionid=qa_question_create($followanswer, $userid, qa_get_logged_in_handle(), $cookieid, $in['title'], $in['content'], $in['format'], $in['text'], qa_tags_to_tagstring($in['tags']), $in['notify'], $in['email'], $in['categoryid'], $in['extra'], $in['queued'], $in['name']); qa_redirect(qa_q_request($questionid, $in['title'])); // our work is done here } } } // Prepare content for theme $qa_content=qa_content_prepare(false, array_keys(qa_category_path($categories, @$in['categoryid']))); $qa_content['title']=qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title'); $qa_content['error']=@$errors['page']; $editorname=isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs'); $editor=qa_load_editor(@$in['content'], @$in['format'], $editorname); $field=qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'content', 12, false); $field['label']=qa_lang_html('question/q_content_label'); $field['error']=qa_html(@$errors['content']); $custom=qa_opt('show_custom_ask') ? trim(qa_opt('custom_ask')) : ''; $qa_content['form']=array( 'tags' => 'name="ask" method="post" action="'.qa_self_html().'"', 'style' => 'tall', 'fields' => array( 'custom' => array( 'type' => 'custom', 'note' => $custom, ), 'title' => array( 'label' => qa_lang_html('question/q_title_label'), 'tags' => 'name="title" id="title" autocomplete="off"', 'value' => qa_html(@$in['title']), 'error' => qa_html(@$errors['title']), ), 'similar' => array( 'type' => 'custom', 'html' => '<span id="similar"></span>', ), 'content' => array( 'tags' => 'name="content" id="content" autocomplete="off" class="hide"', 'value' => qa_html(@$in['content']), 'error' => qa_html(@$errors['content']), ), 'imgupload' => array( 'type' => 'custom', 'html' => '<label class="imguploadbtn" for="checkbox-menu3">Upload image</label>', ), 'imgprev' => array( 'type' => 'custom', 'html' => '<div class="imgprev"><img id="imgprev" />or</div>', ), 'imgurl' => array( 'type' => 'custom', 'html' => '<input id="imgurl" placeholder="image url" type="text" autocomplete="off" ><input type="checkbox" name="check1" id="imgurlc" class="hide" onclick="copyTextValue();"/> <label class="imgurlb" for="imgurlc">Add</label><script>$("#imgurl").on({ keydown: function(e) { if (e.which === 32) return false; }, change: function() { this.value = this.value.replace(/\s/g, ""); } });</script>', ), ), 'buttons' => array( 'ask' => array( 'tags' => 'onclick="qa_show_waiting_after(this, false); '. (method_exists($editor, 'update_script') ? $editor->update_script('content') : '').'"', 'label' => qa_lang_html('question/ask_button'), ), ), 'hidden' => array( 'editor' => qa_html($editorname), 'code' => qa_get_form_security_code('ask'), 'doask' => '1', ), ); if (!strlen($custom)) unset($qa_content['form']['fields']['custom']); if (qa_opt('do_ask_check_qs') || qa_opt('do_example_tags')) { $qa_content['script_rel'][]='p-content/p-ask.js?'.QA_VERSION; $qa_content['form']['fields']['title']['tags'].=' onchange="qa_title_change(this.value);"'; if (strlen(@$in['title'])) $qa_content['script_onloads'][]='qa_title_change('.qa_js($in['title']).');'; } if (isset($followanswer)) { $viewer=qa_load_viewer($followanswer['content'], $followanswer['format']); $field=array( 'type' => 'static', 'label' => qa_lang_html('question/ask_follow_from_a'), 'value' => $viewer->get_html($followanswer['content'], $followanswer['format'], array('blockwordspreg' => qa_get_block_words_preg())), ); qa_array_insert($qa_content['form']['fields'], 'title', array('follows' => $field)); } if (qa_using_categories() && count($categories)) { $field=array( 'label' => qa_lang_html('question/q_category_label'), 'error' => qa_html(@$errors['categoryid']), ); qa_set_up_category_field($qa_content, $field, 'category', $categories, $in['categoryid'], true, qa_opt('allow_no_sub_category')); if (!qa_opt('allow_no_category')) // don't auto-select a category even though one is required $field['options']['']=''; qa_array_insert($qa_content['form']['fields'], 'content', array('category' => $field)); } $field=array( 'label' => qa_html(qa_opt('extra_field_prompt')), 'tags' => 'name="extra" placeholder="image url" id="extra" class="hide"', 'value' => qa_html(@$in['extra']), 'error' => qa_html(@$errors['extra']), ); qa_array_insert($qa_content['form']['fields'], null, array('extra' => $field)); if (qa_using_tags()) { $field=array( 'error' => qa_html(@$errors['tags']), ); qa_set_up_tag_field($qa_content, $field, 'tags', isset($in['tags']) ? $in['tags'] : array(), array(), qa_opt('do_complete_tags') ? array_keys($completetags) : array(), qa_opt('page_size_ask_tags')); qa_array_insert($qa_content['form']['fields'], null, array('tags' => $field)); } if (!isset($userid)) qa_set_up_name_field($qa_content, $qa_content['form']['fields'], @$in['name']); if ($captchareason) { require_once 'p-app-captcha.php'; qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors, qa_captcha_reason_note($captchareason)); } $qa_content['focusid']='title'; return $qa_content; /* Omit PHP closing tag to help avoid accidental output */ Hi guys, I'm working on a project that handles a lot of inserts into a database and uploads files to FTP. Lets say this is the order: - Step 1: Insert row into database - Step 2: Upload files to FTP - Step 3: Email user to confirm complete If the user closes the browser soon after Step 1 has complete Step 2 and 3 will not run. I would prefer if all 3 steps were complete or none at all. What can I do? Thanks in advance. can anybody tell me how i can complete this function in php? // $page = html source file define("LIST_OF_SCHOOLS", "Piarsaigh,Phiarsaigh,Vincents"); $schoolList = explode(',', LIST_OF_SCHOOLS); function checkForSchool($page, $schoolList) { preg_match('|Goes to \\\u003ca href=\\\\"http:\\\/\\\/www.facebook.com\\\/pages\\\/[a-zA-Z-]*\\\/\d*\\\\" data-hovercard=\\\\"\\\/ajax\\\/hovercard\\\/page.php\?[a-zA-Z=0-9]*\\\\">([a-zA-Z\s]*)\\\u003c\\\/a>|', $page, $match); if($match && count($match)>0) { echo "Match Found"; // if any of the words in the schoolList array is found in the match from the preg_match function let the // checkForSchool function return true // other wise return false } } } Hi. I'm currently taking a class in PhP and I'm having issues getting my code to work. I "borrowed" part of the code from elsewhere (but I fully understand each line - which is really the point of learning) I'm hoping a second set of eyes might help on what's wrong: I'm running Wamp Server v2.0 on my local PC to test the scripts... I'm sure I'm probably going to have more then just this error with the script, but it's hard to move forward when you're stuck spinning your wheels. Any help would be greatly appreciated... and any suggestions as to a better way to approach this would be welcome as well. I am here to learn after all Here's the error I'm getting: Notice: Undefined variable: fname in C:\Web Server\wamp\www\daystoxmas.php on line 8 Please return to the main page and enter your First Name. Here's the HTML Code: <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Days to Christmas Form</title> </head> <body> <div><p><h1>Days to Christmas Form</h1></p> <p>- Programmed by: Michael Custance</p> <form action="daystoxmas.php" method="post"> <p>First Name: </select><input type="text" name="fname" size="20" /></p> <p>Last Name: </select><input type="text" name="lname" size="20" /></p> <p>E-mail Address: <input type="text" name="email" size=20 /></p> For Christmas gift ideas, click here! <input type="submit" name="Submit" value="Christmas Gift Page" /> </form> </body> </html> And here's the PhP Form: <HTML> <HEAD> <TITLE>daystoxmas.php</TITLE></HEAD> <BODY> <?php if ($fname) { print ("Good "); if (date("A") == "AM") { print ("morning, "); } elseif ( (date("H") >= 12 ) and (date("H") < 18) ) { print ("afternoon, "); } else { print ("evening, "); } print ("$FirstName<P>"); $Christmas = mktime(0, 0, 0, 12, 25, date('Y')); $today = mktime(); $seconds_to_christmas = $Christmas - $today; $days_to_christmas = $seconds_to_christmas / 86400; $days_to_christmas = floor($days_to_christmas); $temp_remainder = $seconds_to_christmas - ($days_to_christmas * 86400); $hours = floor($temp_remainder / 3600); $temp_remainder = $temp_remainder - ($hours * 3600); $minutes = round($temp_remainder / 60, 0); echo '<p>There is ' . $days_to_christmas . ' days and ' . $hours . ' hours and ' . $minutes . ' minutes until Christmas</p>'; } else { print ("Please return to the main page and enter your First Name."); } ?> </BODY> </HTML> Hi, Basically I just downloaded wamp and got php and mysql etc. I created a database for my "new social network to-be site" which I am trying to develop.. now I want to create a registration page and am trying to follow a guide on another website.. it lets you download a zip with all the php files required. So now, I am totally confused. Here is the guide: http://www.html-form-guide.com/php-form/php-registration-form.html But I dont know what to do with any file or where to put it.. any basic help.. Just to confirm I want to make a login/registration/user database type thing Browser HTTP client makes a request to a HTTP web server which makes a HTTP cURL request to a HTTP REST API which initiates a ReactPHP socket client to make a request to a socket server, and the socket server script eventually execute the following method: public function executeSpecificRequestCommand(array $data):bool { $status = $this->doSomething($data); return $status; //{success: $status} will be returned to the socket client } All is good until doSomething() takes a lot of time and results in a cURL error between the HTTP web server and HTTP REST API. For this particular case, the task isn't meant to provide immediate feedback to the user, but to do some work and update the database, and as such, my desire is to return true status and then perform the work instead of extending the cURL timeout. One option is to ran some process in the background and return status, but I don't think doing so is really right. Using a queue seems excessive as I am already decoupled via the socket. As such, I will probably just add some logic between the initial $string->on('data') and this executeSpecificRequestCommand() method to determine whether the success message should be returned before or after the method is complete. Before doing so, however, I would like to know if there is a more appropriate approach to this scenario. It appears that maybe a child process or a deferred might be appropriate, but am not sure whether I am going down the wrong path. 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 Hi guys, Please can anyone help me with a simple bit of PHP. I'm just starting out, so its all a bit confussing to me. Basically I need a bit of code that does something like this: My end user types in a password on a form on the html page. The pasword is checked by the php page. If pasword is correct the user gets sent to another page within my site. If pasword is incorrect the user gets sent to an error page within my site. I know this is real simple stuff, but as i said i'm realy new to this, hope some one can help. Cheers People. |