PHP - Script Went Crazy This Morning
Code: [Select]
<?php // Declare variables // $debug = false; //$url = "http://www.mto.gov.on.ca/english/traveller/conditions/rdclosure.htm"; $url = "http://www.mto.gov.on.ca/english/traveller/trip/road_closures.shtml"; //$url = "./road_closures.html"; $email_recip = ""; #$email_recip = "t"; $email_from = "s"; $email_from_addr = "t"; $message_header = ""; $message_footer = ""; $arfield1 = array("summary","highway","direction","fromat","to","lanesaffected","trafficimpact","reason","others","eventstart","eventend"); $cntarfield1 = count($arfield1); $timenow = date("Y-m-d H:i:s"); // Connect to database $dbname = "mevents"; $dbuser = ""; $dbpass = ""; $link = mysql_connect('localhost',$dbuser,$dbpass); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname); // DON'T EDIT PAST HERE UNLESS YOU KNOW WHAT YOU'RE DOING // // MAIN PROGRAM /// $webpage = read_web($url); $content = find_data($webpage, "<!-- MIDDLE COLUMN", "</html>"); $content = find_data($content, "</div><a ", "</html>"); $curr_events = read_html_table($content,true); // Parse the events HTML table if ($curr_events["totalevents"]>0) { $sql = "update mEvents set eventid = 'xRoadInfo' where eventid like 'RoadInfo%'"; $result = mysql_query($sql); } for ($curr_event_num = 1; $curr_event_num <= $curr_events["totalevents"]; $curr_event_num++) { $send_email = false; // Flag used to see if an email should be sent for new closure events $event_message = $message_header; $curr_event_found = false; if ($curr_events[$curr_event_num]["unscheduledevents"]==0) { $sql = "select * from mEvents where eventid = '".($curr_events[$curr_event_num]["eventid"])."' limit 1"; } else { $unscd = explode("\n",$curr_events[$curr_event_num]["others"]["data"]); $sql = "select * from mEvents where eventid='xRoadInfo' and highway='".$curr_events[$curr_event_num]["highway"]["data"]."' and direction='".$curr_events[$curr_event_num]["direction"]["data"]."' and fromat='".$curr_events[$curr_event_num]["fromat"]["data"]."'"; if ($unscd[0]!="") $sql .= " and others like '".$unscd[0]."%'"; } $result = mysql_query($sql); if (mysql_num_rows($result)>0) $curr_event_found = true; if (!$curr_event_found) { // Add the not found current event to the message $send_email = true; if ($curr_events[$curr_event_num]["eventend"]["data"]=="") { $event_message .= "*-NEW-*\n"; } else { $event_message .= "-CLEARED-\n"; } if ($debug) $event_message .= $curr_events[$curr_event_num]["eventid"]; $sqlquery = "insert into mEvents (eventid,date_insert"; $sqlval = "('".$curr_events[$curr_event_num]["eventid"]."','".$timenow."'"; for ($a=0;$a<$cntarfield1;$a++) { $sqlquery .= ",`".$arfield1[$a]."`"; $sqlval .= ",'".addslashes($curr_events[$curr_event_num][$arfield1[$a]]["data"])."'"; if ($curr_events[$curr_event_num][$arfield1[$a]]["data"]!="") { $event_message .= $curr_events[$curr_event_num][$arfield1[$a]]["field"]."".$curr_events[$curr_event_num][$arfield1[$a]]["data"]."\n"; } if ($debug) $event_message .= "<br/>"; } $sqlquery .= ") values".$sqlval.")"; mysql_query($sqlquery); $event_message .= "====END====\n"; $email_subject = "*-NEW-* "; $email_subject .= $curr_events[$curr_event_num]["summary"]["data"]; } else { $row = mysql_fetch_array($result); if ($row["eventend"]=="") { if ($curr_events[$curr_event_num]["unscheduledevents"]==0) { if ($curr_events[$curr_event_num]["eventend"]["data"]!="") { $send_email = true; $event_message .= "-CLEARED-\n"; if ($debug) $event_message .= $curr_events[$curr_event_num]["eventid"]; $sqlquery = "update mEvents set date_update='$timenow'"; for ($a=0;$a<$cntarfield1;$a++) { $sqlquery .= ",`".$arfield1[$a]."`='".addslashes($curr_events[$curr_event_num][$arfield1[$a]]["data"])."'"; if ($curr_events[$curr_event_num][$arfield1[$a]]["data"]!="") { $event_message .= $curr_events[$curr_event_num][$arfield1[$a]]["field"]."".$curr_events[$curr_event_num][$arfield1[$a]]["data"]."\n"; } if ($debug) $event_message .= "<br/>"; } $sqlquery .= " where eventid='".$curr_events[$curr_event_num]["eventid"]."'"; mysql_query($sqlquery); $event_message .= "====END====\n"; $email_subject = "*-CLR-* "; $email_subject .= $curr_events[$curr_event_num]["summary"]["data"]; } } else { $sqlquery = "update mEvents set eventid='".$curr_events[$curr_event_num]["eventid"]."' where id=".$row["id"]; mysql_query($sqlquery); } } } $event_message .= $message_footer; //Send an email if there is a new/resolved event if ($send_email) { if ($debug) print ("Sending the message below to " . $email_recip . ", from \"" . $email_from . "\" <" .$email_from_addr . ">.\n" . $event_message . "\n"); else mail ($email_recip, $email_subject, $event_message, "From: \"" . $email_from . "\" <" .$email_from_addr . ">"); } } // FOUR LINES BELOW COMMENTED OUT TO STOP REPEATING MESSAGE //if ($curr_events["totalevents"]>0) //{ // $sql = "delete from mEvents where eventid = 'xRoadInfo'"; //$result = mysql_query($sql); //} mysql_close(); // Functions // //read_web - Read the web page // $strURL ==> URL of the webpage function read_web($strURL) { global $debug; $buffer = ""; if($debug){ print("Reading \"$strURL\".\n"); } $fh = fopen($strURL, "rb"); if ($fh === false) { return ""; } while (!feof($fh)) { $buffer .= fread($fh, 1024); } fclose($fh); return $buffer; } // end function read_web // find)data - Gets a substring of the webpage by scraping the data // $strFile ==> text of the webpage // $strStart_Pattern ==> start of the substring // $strEnd_Pattern ==> end of the substring function find_data($strFile,$strStart_Pattern,$strEnd_Pattern, $intStart_Position = 0) { global $debug; if($debug){ print("Searching for \"$strStart_Pattern\"...\"$strEnd_Pattern\".\n<!-- //-->"); } $first_match = strpos($strFile,$strStart_Pattern, $intStart_Position); if ($first_match) { # find the begining of the tag for ($i = $first_match; $i>0;$i--) { $char = $strFile[$i]; if ($char == "<" ) { $first_match = $i; //record the location of the tag break; } } $partialbuffer = substr($strFile,$first_match,strlen($strFile) - $first_match); # find the end of the sub string $second_match = strpos($partialbuffer,$strEnd_Pattern); return substr($partialbuffer,0,$second_match + strlen($strEnd_Pattern)); } else { return(false); } } //end function find_data // read_html_table - Read the contents of an HTML table and return the array(s) // strHTMLTable ==> HTML table text // boolSkipFirstRow ==> Skip the first row if it contains column titles (true/false) function read_html_table($strHTMLTable, $boolSkipFirstRow) { global $debug,$arfield1,$cntarfield1; $arrevents = array(); preg_match_all('/<a name="Event.+<\/table>/Us',$strHTMLTable,$dataevents); $dataevents = $dataevents[0]; $countdataevents = count($dataevents); $j = 0; for($i=0; $i<$countdataevents; $i++) { preg_match('/<a name="Event(.+)" id/', $dataevents[$i], $matches); $eventid = $matches[1]; //if ($eventid>0) { $j++; $arrevents[$j]["eventid"] = $eventid; preg_match('/summary="(.+)" style/', $dataevents[$i], $matches); $arrevents[$j]["summary"]["field"] = ""; $arrevents[$j]["summary"]["data"] = $matches[1]; preg_match_all('/<tr>.+<\/tr>/Us',$dataevents[$i],$tr); $tr = $tr[0]; $counttr = count($tr); for ($k=1;$k<$cntarfield1;$k++) { $arrevents[$j][$arfield1[$k]]["field"] = ""; $arrevents[$j][$arfield1[$k]]["data"] = ""; } if ($eventid>0) $arrevents[$j]["unscheduledevents"] = 0; else $arrevents[$j]["unscheduledevents"] = 1; for ($k=1;$k<$counttr;$k++) { preg_match_all('/<td.+<\/td>/Us',$tr[$k],$td); $td = $td[0]; $td1 = cleandatafield(cleandata($td[0])); if (checkdatafield($td1)==1) { $arrevents[$j][$td1]["field"] = cleandata($td[0])." "; $arrevents[$j][$td1]["data"] = cleandata($td[1]); } else { if (cleandata($td[1])!="") { $arrevents[$j]["others"]["field"] = ""; $arrevents[$j]["others"]["data"] .= cleandata($td[0])." ".cleandata($td[1])."\n"; } } } } } echo "<br/>\ntotal ".$j; $arrevents["totalevents"] = $j; return $arrevents; } //end function readhtmltable function cleandata($x) { $y = $x; $y = preg_replace('/<td.+>/U',"",$y); $y = str_replace("</td>","",$y); $y = str_replace("<strong>","",$y); $y = str_replace("</strong>","",$y); $y = str_replace("/r/n","",$y); $y = trim($y); return $y; } function cleandatafield($x) { $y = $x; $y = str_replace("/","",$y); $y = str_replace(":","",$y); $y = str_replace(" ","",$y); $y = strtolower($y); return $y; } function checkdatafield($x) { global $debug,$arfield1,$cntarfield1; $found = 0; for ($i=0;$i<$cntarfield1;$i++) { if ($x==$arfield1[$i]) $found = 1; } return $found; } print ("ClosedRoadScript"); print date(" G:i:s"); ?> I have the above script that reads this website http://www.mto.gov.on.ca/english/traveller/trip/road_closures.shtml and emails out the changes. Up until this morning it has been working fine but then it started repeating the same one over and over. It didn't put the normal line in the database it would for any other event which would explain why the same email got sent over and over but I am trying to figure out why the database was empty for this event. The only idea I have is something to do with this line and the script not liking it "VASEY ROAD (WAVERLEY)/SIMCOE ROAD 27/SIMCOE ROAD 23" or that it's too long for database. Someone on this site has been helping me with this for the last couple of years but he has since passed away. I've been making small adjustments myself with my limited php know how but this one has me stumped. Similar TutorialsHi 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>"; 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. ok this works fine and everything but when here when i try to let the admin changes stuff and goes to change the venue a list show appear and it does but when it save it save it as RBB FIELD <option value="RED BULL ARENA">RED BULL ARENA</option><option value="RBB FIELD ">RBB FIELD </option><option value="RED BULL ARENA">RED BULL ARENA</option> why does it do that?? HElp ANYONE Code Code: [Select] <?php if (isset($_GET['eid'])){ $newid = $_GET['eid']; $sqlCommand = "SELECT * FROM events WHERE id='$newid' LIMIT 1"; $out = mysql_query($sqlCommand); $row = mysql_fetch_assoc($out); $eventid = $row["id"]; $eventname = $row["eventname"]; $eventtype = $row["typeevent"]; $eventinfo = $row["eventinfo"]; $date = $row["date"]; $time = $row["time"]; $livetickets = $row["sale"]; $numtickets = $row["numtickets"]; $pricestudents = $row["studentsprice"]; $priceseniors = $row["seniorsprice"]; $priceadults = $row["adultsprice"]; $venues = $row["venue"]; $category = $row["category"]; $query = mysql_query("SELECT venuename FROM venue"); while ($row = mysql_fetch_array($query)){ $venues .= '<option value="' . $row['venuename'] . '">' . $row['venuename'] . '</option>'; } $form = "<form action='eevent.php' method='post' enctype='multipart/form-data'> <table> <tr> <td>REQUIRED FIELDS *</td> <td></td> </tr> <tr> <td>Event Name*</td> <td><textarea cols='17' rows='1' name='eventname' />$eventname</textarea></td> </tr> <tr> <td>Type of event*</td> <td><textarea cols='17' rows='1' name='typeevent' />$eventtype</textarea></td> </tr> <tr> <td>Event Inforamtion*</td> <td><textarea name='eventinfo' cols='40' rows='5'>$eventinfo</textarea></td> </tr> <tr> <td>Date</td> <td><input type='text' size='10' name='date' value='$date' /></td> </tr> <tr> <td>Time</td> <td><input type='text' size='10' name='time' value='$time' /></td> </tr> <tr> <td>When tickets go on sale</td> <td><input type='text' size='10' name='sale' value='$livetickets' /></td> </tr> <tr> <td>Number of Tickets Available </td> <td><input type='text' size='5' name='numtickets' value='$numtickets' /></td> </tr> <tr> <td><h4>Ticket Prices</h4></td> </tr> <tr> <td>STUDENTS</td> <td>$<input type='text' size='3' name='studentsprice' value='$pricestudents'/></td> </tr> <tr> <td>SENIORS</td> <td>$<input type='text' size='3' name='seniorsprice' value='$priceseniors'/></td> </tr> <tr> <td>ADULTS</td> <td>$<input type='text' size='3' name='adultsprice' value='$priceadults' /></td> </tr> <tr> <td>SELECT VENUE</td> <td> <select name='venue'> <option value='$venues'>$venues</option> </select> </td> </tr> <tr> <td>SELECT CATEGORY</td> <td> <select name='category'> <option value='$category'>$category</option> <option>FOOTBALL</option> <option>BASKETBALL</option> <option>HOCKEY</option> <option>DRAMA</option> <option>MUSIC</option> <option>DANCE</option> <option>VISUAL ARTS</option> </select> </td> </tr> <tr> <td></td> <td><input type='hidden' name='saveevent' value='$newid'/></td> <td><input type='submit' name='savechanges' value='Save Changes'/></td> </tr> </table> </form>"; echo "$form"; } if ($_POST['saveevent']){ $newid = mysql_real_escape_string($_POST['saveevent']); $eventname = mysql_real_escape_string($_POST['eventname']); $eventtype = mysql_real_escape_string($_POST['typeevent']); $eventinfo = mysql_real_escape_string($_POST['eventinfo']); $date = mysql_real_escape_string($_POST['date']); $time = mysql_real_escape_string($_POST['time']); $livetickets = mysql_real_escape_string($_POST['sale']); $numtickets = mysql_real_escape_string($_POST['numtickets']); $pricestudents = mysql_real_escape_string($_POST['studentsprice']); $priceseniors = mysql_real_escape_string($_POST['seniorsprice']); $priceadults = mysql_real_escape_string($_POST['adultsprice']); $venues = mysql_real_escape_string($_POST['venue']); $categorys = mysql_real_escape_string($_POST['category']); $sqlCommand = "UPDATE events SET eventname='$eventname', typeevent='$eventtype', eventinfo='$eventinfo', date='$date', time='$time', sale='$livetickets', numtickets='$numtickets', studentsprice='$pricestudents', seniorsprice='$priceseniors', adultsprice='$priceadults', venue='$venues', category='$categorys' WHERE id='$newid'"; $out = mysql_query($sqlCommand); echo "SAVE CHANGES COMPLETED!"; } ?> I'm trying to setup my database class so that by default it will create all of the tables and triggers required for my application to run. I've got everything working except for it adding the trigger. Here's the relevant code (slightly obfuscated for security reasons): private function check_consistency() { $database_query = <<<QUERY CREATE TABLE IF NOT EXISTS d2b_users ( id INT NOT NULL AUTO_INCREMENT, obfuscated INT NOT NULL, obfuscated VARCHAR(50) NOT NULL, obfuscated VARCHAR(32) NOT NULL, obfuscated VARCHAR(32) NOT NULL, obfuscated VARCHAR(32) NOT NULL, obfuscated BOOL NOT NULL DEFAULT '1', UNIQUE KEY(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; CREATE TABLE IF NOT EXISTS d2b_statistics ( id INT NOT NULL, obfuscated BIGINT NOT NULL DEFAULT '0', UNIQUE KEY(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; delimiter | CREATE TRIGGER d2b_auto_statistics AFTER INSERT ON d2b_users FOR EACH ROW BEGIN INSERT INTO d2b_statistics SET id = NEW.id; END; | delimiter ; QUERY; if(!$consistency = $this->link->multi_query($database_query)) { die("Failed to create/verify the default database tables."); } return true; } I've also tried removing the delimiter and the colon after the INSERT line in the trigger and I still can't get it to add properly. What's annoying is that I'm able to take the code for the trigger from above and go into phpmyadmin and paste it into the SQL and it will add and work correctly. However, I'm trying to get my class to do that automatically so the php application automatically installs itself on other servers. What am I doing wrong? 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... Why is it when a save a youtube video on my db it gives me this <iframe width="220" height="240" src="http://www.youtube.com/embed/DCZ2l1BbWyY?wmode=opaque" frameborder="0" allowfullscreen></iframe><br> i have to save it twice so it can be view why if you want to see my edit videos page i will add it here hey, thanks in advance if someone can help me x y auto 1 2 a 5 3 b 4 6 c 1 2 d 7 7 e 4 6 f 5 3 b 9 4 h 4 6 f I need query to get from table auto_history(x, y, auto) only these cars, that are in the same place with other cars The result must be : a - because (it has x=1 and y=2 AND d has also x=1 and y=2), so they are in the same place d - because (it has x=1 and y=2 and a has also x=1 and y=2), so they are in the same place .... so, that's what my sql result must give a, c, d, f Okay, so I'm a relative newbie to PHP. I've been learning for a few months now, and while I get some bits and can fix most of my errors (with a little help from google occasionally), this one's something I can't explain. Basically, I've been building an admin panel so I can edit various content on a website, as you'd gather. It was all going pretty well, until something I did meant that my forms now do nothing. When I press update on the edit forms or add on the...well..add forms, they go back to the prefilled in content. Here is my add form: <?php include('/home/charioti/public_html/andalasia/admin/skin/header.php'); //form not yet submitted //display initial form if (!$_POST['submit']) { ?> <h1>Add Content</h1><div class="cont"> <table align="center"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td>Title:</td><td><input type="text" name="title" id="title"></td></tr> <tr><td>Content:</td><td><textarea name="content">text here</textarea></td></tr> <tr><td></td><td><input type="submit" name="submit" value="add"></td></tr></table></form> <?php } else { include('/home/charioti/public_html/andalasia/admin/conf.php'); //set up error list array $errorList = array(); $title = $_POST['title']; $content = $_POST['content']; //validation if(trim($_POST['title']) == '') { $errorList[] = 'Invalid entry: activity name'; } if(trim($_POST['content']) == '') { $errorList[] = 'Invalid entry: answer'; } //check for errors if(sizeof($errorList) == 0) { //db connect $connection = mysql_connect($host, $user, $pass) or die('Unable to connect!'); //db select mysql_select_db($db) or die('Unable to select database!'); //generate and execute query $query = "INSERT INTO info(title, content, date) VALUES('$title', '$content', NOW())"; $result = mysql_query($query) or die("Error in query: $query . " . mysql_error()); // print result echo 'content added! <a href=/admin/index1.php>home</a>'; //close database connection mysql_close($connection); } else { //errors found // print as list echo ' The following errors were encountered:'; echo '<br>'; echo '<ul>'; for($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul>'; } } include('/home/charioti/public_html/andalasia/admin/skin/footer.php'); ?> My header file, incase I've messed something the <? session_start(); if(!session_is_registered(username)){ header("location:/admin/index.php"); } ?> <HTML> <HEAD> <TITLE>Andalasia ~ admin: <?php echo basename($_SERVER["PHP_SELF"]); ?></TITLE> <LINK REL="STYLESHEET" HREF="/admin/skin/style.css" TYPE="TEXT/CSS"> </HEAD> <BODY> <TABLE CLASS="CON"> <TR> <TD> <IMG SRC="/admin/skin/adpo.png" style="border-top:0px solid #A10543"> </TD> </TR> <TR> <TD> <TABLE style="font:8pt arial"> <TR> <TD CLASS="nav" style="width:200px"> <DIV CLASS="navi"> <p class="header">navigation</p> <a href="" target="__blank">Guild HQ</a> <a href="/" target="__blank">Web HQ</a> <a href="/admin/index1.php">Admin HQ</a> <a href="/admin/logout.php">logout</a></DIV> <DIV CLASS="navi"> <p class="header">points</p> <?php include('/home/charioti/public_html/andalasia/admin/points.php')?> </DIV> <DIV CLASS="navi"> <P CLASS="header">update posts</p> <?php include('/home/charioti/public_html/andalasia/admin/news/list.php')?> <a href="/admin/news/add.php">Add a post</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">information posts</p> <?php include('/home/charioti/public_html/andalasia/admin/info/list.php')?> <a href="/admin/info/add.php">Add a post</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">activities</p> <a href="/admin/activities/onsite.php">Onsite activities</a> <a href="/admin/activities/offsite.php">Web-hosted activities</a> <a href="/admin/activities/creative.php">Creative web activities</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">Graphics</p> <h2>Guild layouts</h2> <?php include('/home/charioti/public_html/andalasia/admin/layouts/layl.php')?> <a href="/admin/layouts/add.php">Add layout</a> <h2>Userlookups</h2> <?php include('/home/charioti/public_html/andalasia/admin/lookups/list.php')?> <a href="/admin/lookups/add.php">Add lookup</a> <h2>Banners</h2> <a href="/admin/banners/banners.php">Banners</a> <h2>Fonts</h2> <?php include('/home/charioti/public_html/andalasia/admin/fonts/list.php')?> <a href="/admin/fonts/add.php">Add font</a></DIV> <DIV CLASS="navi"> <P CLASS="header">Members</p> <?php include('/home/charioti/public_html/andalasia/admin/users/list.php')?> <a href="/admin/users/add.php">Add user</a> </DIV> <DIV CLASS="navi"> <!-- BEGIN CBOX - www.cbox.ws - v001 --> <div id="cboxdiv" style="text-align: center; line-height: 0"> <div><iframe frameborder="0" width="200" height="305" src="http://www2.cbox.ws/box/?boxid=2184566&boxtag=evz64m&sec=main" marginheight="2" marginwidth="2" scrolling="auto" allowtransparency="yes" name="cboxmain" style="border:#11011A 1px solid;" id="cboxmain"></iframe></div> <div><iframe frameborder="0" width="200" height="75" src="http://www2.cbox.ws/box/?boxid=2184566&boxtag=evz64m&sec=form" marginheight="2" marginwidth="2" scrolling="no" allowtransparency="yes" name="cboxform" style="border:#11011A 1px solid;border-top:0px" id="cboxform"></iframe></div> </div> <!-- END CBOX --> </DIV> </TD> <TD CLASS="c" VALIGN="TOP" style="width:600px"> And my edit file: <? // edit.php - edit a layout ?> <!-- page header - snip --> <? // includes include("/home/charioti/public_html/andalasia/admin/skin/header.php"); include("/home/charioti/public_html/andalasia/admin/conf.php"); // form not yet submitted // display initial form with values pre-filled if (!isset($_POST['submit'])) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $id = mysql_escape_string($_GET['id']); $query = "SELECT title, content, id FROM info WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if a result is returned if (mysql_num_rows($result) > 0) { // turn it into an object $row = mysql_fetch_object($result); // print form with values pre-filled ?> <h1>Update post - ID <? echo $id; ?></h1> <div class=cont> <table class=view align=center> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<? echo $id; ?>"> <tr> <td valign="top"><b>Title</b></td> <td><input size="50" maxlength="250" type="text" name="title" value="<? echo $row->title; ?>"></td> </tr> <tr> <td valign="top"><b>Content:</b></td> <td><textarea name=content><? echo $row->content; ?></textarea></td> </tr> <tr> <td colspan=2><input type="Submit" name="submit" value="Update"></td> </tr> </form> </table> </div> <? } // no result returned // print graceful error message else { echo "<h1>Error!</h1><div class=cont>That post could not be located in our database.</div>"; } } else { // form submitted // start processing it // set up error list array $errorList = array(); $count = 0; // validate text input fields $title = mysql_escape_string($_POST['title']); $content = mysql_escape_string($_POST['content']); $id = mysql_escape_string($_POST['id']); if (!$title) { $errorList[$count] = "Invalid entry: title"; $count++; } if (!$content) { $errorList[$count] = "Invalid entry: content"; $count++; } // check for errors // if none found... if (sizeof($errorList) == 0) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $query = "UPDATE info SET title = '$title', content = '$content' WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // print result echo "<h1>Success!</h1><div class=cont>Update successful. <a href=/admin/index1.php>Go back to the main menu</a>.</font></div>"; // close database connection mysql_close($connection); } else { // errors occurred // print as list echo "<h1>Errors:</h1><div class=cont><font size=-1>The following errors were encountered: <br>"; echo "<ul>"; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo "</ul></font></div>"; } } include('/home/charioti/public_html/andalasia/admin/skin/footer.php'); ?> I started off working with templates from my book and from various sources, so I've tried reseting my pages to those and reworking them, and I've deduced that it's probably something to do with my header file, I just can't work out what or whereabouts the problem is. Any help you can offer would be greatly appreciated. (: Code: [Select] $winning_numbers = explode("|", "8|18|3,8|18|3"); while($ticket = $DB->fetch_row($query)) { $correct_numbers = 0; $correct = 0; $numbers_chosen = @explode("|","8|18|3,8|18|3"); $your_numbers = array(); $array1 = array_count_values($numbers_chosen); $array2 = array_count_values($winning_numbers); foreach($array1 as $number1 => $count1) { foreach($array2 as $number2 => $count2) { if($number2 == $number1 and $count2==$count1) $correct_numbers += $count2; } } $use = 0; echo $correct_numbers; echo "<br>"; As you can see, my $correct_numbers variable will spit out "3" because it matches 3 each INDIVIDUAL numbers from $numbers_chosen in the arrays. Now my problem is. This code wasn't supposed to take in a "," to. So essentially This should display "6" because I want it to read through each , as a new Array/Group if you will. So let's say if I changed it to: $winning_numbers = explode("|", "2|18|3,8|18|2"); $numbers_chosen = @explode("|","8|18|3,8|18|3"); It would echo out "4" As it only matches 4 of them. Once I know how to do this, I will have a full functioning lottery System on my site, I am very anxious for replies, Hope you can Help. Thank you. TLDR??: I want $correct_numbers to beable to count arrays with the comma's to Please help. I have tried to condense the following code to make it easier for someone to shed insight. The results make totally no sense to me.
I have the following two lines of code: require_once('/var/www/bidjunction/application/classes_3rd/htmlpurifier/library/HTMLPurifier.auto.php'); $config = HTMLPurifier_Conf::createDefault();Let me explain what happens in these two lines of code. First.... require_once('/var/www/bidjunction/application/classes_3rd/htmlpurifier/library/HTMLPurifier.auto.php'):HTMLPurifier.auto.php is shown below: <?php /** * This is a stub include that automatically configures the include path. */ set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); require_once 'HTMLPurifier/Bootstrap.php'; require_once 'HTMLPurifier.autoload.php'; // vim: et sw=4 sts=4The only thing Bootstrap.php does is define a class and execute the following line: define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..'));The only thing HTMLPurifier.autoload.php does is execute HTMLPurifier_Bootstrap::registerAutoload() (which was one of the classes defined in Bootstrap.php). The only thing HTMLPurifier_Bootstrap::registerAutoload() does is: spl_autoload_register(array('HTMLPurifier_Bootstrap','autoload'), true, true);Now the second line: $config = HTMLPurifier_Conf::createDefault();I expected that HTMLPurifier_Conf::createDefault() would be executed, but no, instead the script goes to HTMLPurifier_Bootstrap:autoload() which returns false. Next, the script goes to function PHPMailerAutoload() which is in PHPMailerAutoload.php. What!!! What does PHPMailerAutoload have to do with this? While a perfect answer would be great, general comments and a strategy to troubleshoot be the next best thing. I am stumped! Please help. So i have an array with 1 item in it... this item is a sting that looks like so a:6:{i:0;a:4:{i:1;s:4:"Home";i:2;s:1:"/";i:3;s:1:"1";i:4;s:2:"fy";}i:1;a:4:{i:0;a:4:{i:1;s:4:"About";i:2;s:1:"/about";i:3;s:1:"1";i:4;s:2:"";}i:2; I need to somehow pull out all things that are within double quotation marks. Note: Some quotes are empty, but i need to know that. So the above should pull out Home / fy About /about Thanks! hi guys when a match is over, two result fields have to be edited the first update goes well but the second one is failing, not allways, sometimes it gives the loser xp, but not the winner (with two players) the script should give the winner 100 xp second 95, third 90,... only the first two controls at the end are working the thirth one is not, and its being used to make the first two so it is doing its job there ... <?php include("./includes/egl_inc.php"); $secure = new secure(); $secure->secureGlobals(); page_protect(); global $config; $matchidcheck = $_SESSION['matchid']; $maks = '100'; $players=mysql_query("SELECT playerid FROM ffa_points WHERE matchid='$matchidcheck' order by killsdeaths DESC"); while(list($playerid)=mysql_fetch_array($players)) { $playerspoints=mysql_query("SELECT points FROM members WHERE id='$playerid'"); while(list($points)=mysql_fetch_row($playerspoints)) { $userpoints = $points; } $newpoints = $userpoints + $maks; mysql_query("UPDATE members SET points = $newpoints WHERE id='$playerid'"); mysql_query("UPDATE ffa_points SET xppoints = $maks WHERE id='$playerid' and matchid='$matchidcheck'"); if ($totalxp > 51) { $maks = $maks - 5; } } $mes="$newpoints $points $maks All Results have been stored succesfully !! Thank You !"; return success($mes,'./ffamatchesarchive.php'); include("$config"); ?> any help would be greatly appreciated thanks Hello, If anyone can help please let me know. The 2 files below are what's used to render the "Frickster's ListRave Posts" at the following URL http://www.listrave.com/member/profile.php?id=24. You can see that under Antiques it lists the same ads under both York and Altoona. The script is identifying all ads posted by User ID 24 but I don't know why it is duplicating those ads in the 2 different cities. There should actually be 2 ads for York and one for Altoona. The code is below. Again, please help Here's the code to pull the info from the data base (called memberall_listings.php) $conn = mysql_connect($dbhost1, $dbuser1, $dbpass1) or die ('Error connecting to mysql'); mysql_select_db($dbname1) or die('Could not connect: ' . mysql_error()); $tables = mysql_list_tables($dbname1); while (list($table) = mysql_fetch_row($tables)) { $site["tablename"][] = $table; } if($_REQUEST["id"]!='') $getmemberId = $_REQUEST["id"]; else $getmemberId = $_SESSION["memberid"]; //$x = getTableDetailsByTableName1(""); // echo count($site["tablename"]); $zz=-1; for($ww=0;$ww<count($site["tablename"]);$ww++) { $ValidTable = array("baltperm4w", "balt_yellowpages","boats"); if(!in_array($site["tablename"][$ww],$ValidTable)) { if (count(getTableDetailsByTableName2($site["tablename"][$ww])) >0) $zz++; for($kk=0;$kk<count(getTableDetailsByTableName2($site["tablename"][$ww]));$kk++) { // echo $site["tablename"][$zz]."<br></br>"; $getTableDetails = getTableDetailsByTableName($site["tablename"][$ww],$kk); //echo $getTableDetails["city"]; if ($kk > 0) if ($getTableDetails['city']==$lastcity && $getTableDetails['state']==$laststate) { continue; } $getAllArray[$zz][$kk]["Titlename"] = "<a href='http://www.listrave.com'>ListRave</a> --> <a href=".$getTableDetails["stateurl"].">".$getTableDetails["state"]."</a> --> <a href=".$getTableDetails["cityurl"].">".mysql_real_escape_string($getTableDetails["city"])."</a> --> <a href=".$getTableDetails["maincaturl"].">".$getTableDetails["maincat"]."</a> --> <a href=".$getTableDetails["caturl"].">".$getTableDetails["cat"]."</a>"; $getAllArray[$zz][$kk]["PostURL"] = $getTableDetails["SitePostUrl"]; $getAllArray[$zz][$kk]["AgeFormat"] = $getTableDetails["DisplayFormat"]; $getAllArray[$zz][$kk]["TableName"] = $site["tablename"][$ww]; $getAllArray[$zz][$kk]["SiteRealPath"] = $getTableDetails["SiteRealPath"]; $lastcity = $getTableDetails["city"]; $laststate = $getTableDetails["state"]; $GetAdlists[$zz]["MainArray"] = GetMemberAdLists($site["tablename"][$ww],$getmemberId); if($GetAdlists[$zz]["MainArray"]!=""){ $getAllArray[$zz][$kk]["ArrayExist"] = "Yes"; }else{ $getAllArray[$zz][$kk]["ArrayExist"] = "No"; } for($k=0;$k<count($GetAdlists[$zz]["MainArray"]);$k++) { $getdate = explode(",",$GetAdlists[$zz]["MainArray"][$k]["Posted_date"]); $getAllArray[$zz][$kk][$k]['day'] = date("l",strtotime($getdate[0])); $getAllArray[$zz][$kk][$k]['month'] = date("F",strtotime($getdate[0])); $getAllArray[$zz][$kk][$k]['date'] = date("d",strtotime($getdate[0])); $getAllArray[$zz][$kk][$k]['ListArray'] = getMemberAddetails($getdate[0],$site["tablename"][$ww],$getmemberId, $getTableDetails["city"], $getTableDetails["state"]); for($mn=0;$mn<count($getAllArray[$zz][$kk][$k]['ListArray']);$mn++) { if($getAllArray[$zz][$kk][$k]['ListArray'][$mn]["Picture0"]!='' || $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["Picture1"]!='' || $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["Picture2"]!='' || $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["Picture3"]!='' || $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["Picture4"]!='' || $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["Picture5"]!='') $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["ImageArray"] = 'Yes'; else $getAllArray[$zz][$kk][$k]['ListArray'][$mn]["ImageArray"] = 'No'; } } } } } /* if($_SERVER['REMOTE_ADDR'] = '122.165.56.46') { printArray($getAllArray); exit; } */ function SelectQry1($Qry) { $result = mysql_query($Qry) or die ("QUERY Error:".$Qry."<br>".mysql_error()); $numrows = mysql_num_rows($result); if ($numrows == 0){ return; } else { $row = array(); $record = array(); while ($row = mysql_fetch_array($result)){ $record[] = $row; } } return $record; } function getTableDetailsByTableName($tablename, $kk) { global $global_config; $Qry = "select * FROM ".$tablename.""; $getListingdetail = SelectQry1($Qry); return $getListingdetail[$kk]; } function getTableDetailsByTableName2($tablename) { global $global_config; $Qry = "select * FROM ".$tablename.""; $getListingdetail = SelectQry1($Qry); return $getListingdetail; } function GetMemberAdLists($tablename,$getmemberId) { global $global_config; $Qry = "select Posted_date FROM ".$tablename." where memberid='".$getmemberId."' group by SUBSTRING_INDEX(Posted_date,',',1) Order by Posted_date DESC"; $getimagedetail = SelectQry1($Qry); return $getimagedetail; } function getMemberAddetails($date,$tablename,$getmemberId) { global $global_config; $Qry = "select * from ".$tablename." WHERE `Posted_date` like '%".$date."%' AND ActivationStatus = 'Active' AND PublishedStatus='Active' AND memberid='".$getmemberId."' group by Posted_date Order by Ident DESC"; $getimagedetail = SelectQry1($Qry); return $getimagedetail; } ?> Here's the code to display it. Remember, this is just for "Frickster's ListRave Posts" <?php // start session ob_start(); session_start(); include "../includes/config.php"; //include('incsec/inccheckifadmin.php'); include ('incsec/incconn.php'); include ('incsec/incsettings.php'); include ('incfunctions.php'); if($_REQUEST["id"]!='') $ActiveMemberID = $_REQUEST["id"]; else $ActiveMemberID = $_SESSION["memberid"]; $query="SELECT * FROM tblmembers where memberid = '".$ActiveMemberID."'"; $result11 = mysql_query($query,$dbconnection); $members = mysql_fetch_array($result11); $pagetitle = 'ListRave - '.$members["username"]." 's".' Profile Page'; include("memberall_business.php"); include('memberall_listings.php'); //printArray($getAllArray); //exit; ?> <?php include('header_member2.php') ?> <div style="height:50px;"> </div> <table border="0" cellpadding="2" cellspacing="0" width="80%" align="center"> <tr> <td valign="top" width="30%" align="left"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" align="left"> <table width="100%"> <tr> <td valign = "top" style="text-align: center;"> <?php include ('incsec/incconn.php'); $dbconnection = mysql_connect($dbhost,$dbusername,$dbpassword); mysql_select_db($database,$dbconnection); $query="SELECT * FROM tblmembers where memberid = '".$ActiveMemberID."'"; $result = mysql_query($query,$dbconnection); $numrecs=mysql_num_rows($result); $myrow = mysql_fetch_array($result); $currentmemberid = $myrow['memberid']; $qry="SELECT * FROM tbl_listrave_ad where memberid = '".$ActiveMemberID."' and PublishedStatus='Active'"; $result1 = mysql_query($qry,$dbconnection); $getcnt =mysql_num_rows($result1); ?> <?php if($numrecs!=0) { ?> <table height="100" width="90%" border="0" cellpadding="6" cellspacing="0" align="center"> <tr> <td valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #0166FF;"> <tr> <td align="left" class="profilefheader" width="100%" colspan="2" style="padding-left:5px; padding-top:0px; height:20px; line-height:20px;" valign="middle"><?php echo $myrow["username"]; ?>'s Profile</td> </tr> <tr> <td align="left" valign="top"> <table width="100%" border="0" cellpadding="10" cellspacing="0" id="profilecontainer" align="left" style="margin-left: 10%"> <tr> <td valign = "top" width="10%"> <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td width="20%" align="left" valign="top" style="padding-right:35px"> <?php if($myrow["memberphoto"]!='') { ?> <a target="_blank" href="imageview.php?id=<?php echo $myrow["memberid"]; ?>"> <img width="180" height="180" class="Imageborder" src="<?php echo $config["sitepath"]."memberphotos/".$myrow["memberphoto"].""; ?>"> </a> <?php } else { ?> <img src="no-image.gif" border="0" width="180" height="180" class="Imageborder" /> <?php } ?> </td> </tr> <tr> <td height="30"> </td> </tr> <?php /*?><tr> <td width="80%" align="center" valign="top"> <?php if($myrow["memberphoto"]!='') { ?> <img src="upload.gif" border="0" /> <?php } else { ?> <img src="change-photo.gif" border="0" /> <?php } ?> </td> </tr><?php */?><tr valign="bottom"><td> </td></tr><tr><td align="left"><img src="addcontact.gif" alt="Add This Member To Your Contacts" /></td></tr></table> </td> <td valign = "top"> <table width="90%" border="0" cellpadding="6" cellspacing="0" align="left"> <tr> <td align="left" valign="top" colspan="2"> <table width="90%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" width="15%" nowrap="nowrap"> <span id="profilecontainer">Personal Information </span> </td> <td width="88%" valign="top"> <div style="border-top: #CCCCCC solid 1px; position:relative; top:7px;"> </div> </td> </tr> </table> </td> </tr> <?php if($myrow["firstname"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>First Name</strong> </td> <td align="left" valign="top"> <?php echo $myrow["firstname"]; ?> </td> </tr> <?php } ?> <?php if($myrow["othernames"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Last Name</strong> </td> <td align="left" valign="top"> <?php echo $myrow["othernames"]; ?> </td> </tr> <?php } ?> <?php if($myrow["gender"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Gender</strong> </td> <td align="left" valign="top"> <?php echo $myrow["gender"]; ?> </td> </tr> <?php } ?> <?php if($myrow["age"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Age</strong> </td> <td align="left" valign="top"> <?php echo $myrow["age"]; ?> </td> </tr> <?php } ?> <?php if($myrow["pobox"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Location</strong> </td> <td align="left" valign="top"> <?php echo $myrow["pobox"]; ?> </td> </tr> <?php } ?> <?php if($myrow["relationship_status"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Relationship Status</strong> </td> <td align="left" valign="top"> <?php echo $myrow["relationship_status"]; ?> </td> </tr> <?php } ?> <?php if($myrow["registrationdate"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Member Since</strong> </td> <td align="left" valign="top"> <?php echo date('M d, Y', strtotime($myrow["registrationdate"])); ?> </td> </tr> <?php } ?> <?php if($myrow["username"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>User Name</strong> </td> <td align="left" valign="top"> <?php echo $myrow["username"]; ?> </td> </tr> <?php } ?> <?php if($myrow["about_me"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>About me</strong> </td> <td align="left" valign="top" style="padding-right:80px"> <?php echo $myrow["about_me"]; ?> </td> </tr> <?php } ?> <?php if($myrow["hobbies"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Hobbies</strong> </td> <td align="left" valign="top" style="padding-right:80px"> <?php echo $myrow["hobbies"]; ?> </td> </tr> <?php } ?> <?php if($myrow["movies"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Favorite Movies</strong> </td> <td align="left" valign="top" style="padding-right:80px"> <?php echo $myrow["movies"]; ?> </td> </tr> <?php } ?> <?php if($myrow["music"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Favorite Music</strong> </td> <td align="left" valign="top" style="padding-right:80px"> <?php echo $myrow["music"]; ?> </td> </tr> <?php } ?> <?php if($myrow["books"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Favorite Books</strong> </td> <td align="left" valign="top" style="padding-right:80px"> <?php echo $myrow["books"]; ?> </td> </tr> <?php } ?> <tr> <td height="15"> </td> </tr> <tr> <td align="left" valign="top" colspan="2"> <table width="90%" border="0" cellpadding="0" cellspacing="0" > <tr> <td valign="top" width="15%" nowrap="nowrap" > <span id="profilecontainer">Contact Information </span> </td> <td width="88%" valign="top"> <div style="border-top: #CCCCCC solid 1px; position:relative; top:7px;"> </div> </td> </tr> </table> </td> </tr> <?php if($myrow["emailaddress"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Email</strong> </td> <td align="left" valign="top"> <?php echo $myrow["emailaddress"]; ?> </td> </tr> <?php } ?> <?php if($myrow["phonenumber"]!='') { ?> <tr> <td width="20%" align="left" valign="top"> <strong>Mobile Number</strong> </td> <td align="left" valign="top"> <?php echo $myrow["phonenumber"]; ?> </td> </tr> <?php } ?> & Hi Guys and Girls,
I'm having a bit of a hard time getting some pagination working. I have a script using CURL getting JSON results via a HTTP API. This is also used in a Wordpress Installation.
The API call has a maximum of 50 records returned but allows pagination.
What I can't seem to get right is actually getting this to work.
Below is the code that I'm using:
<?php //functions relating to wordpress go he //---------------------------------------- $bg_colors = array('green', 'orange', 'blue', 'yellow', 'red', 'black'); //---------------------------------------- //End functions relating to wordpress // Start PetRescue PHP/API Code //---------------------------------------- // Open CuRL/JSON Stuff $ch = curl_init(); $category=$_GET['category']; $url="http://www.xxx.com.au/api/listings?token=xxxtokenxxx&group_id=xxx&species=".$category; curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json', 'X-some-API-Key: xxxtokenxxx', )); $json = json_decode(curl_exec($ch), true); //Pagination stuffs if($_GET['page']) { $page=substr($_GET['page'],1); echo 'page'.$page; } // Functions relating to the Echo Code foreach($json['listings'] as $listing) { $short_personality=substr($listing['personality'],0,500); $peturl="http://xxx.org.au/pet-info/?petid=".$listing['id']; $medium_photo=$listing['photos'][0]['large_340']; $gallery_first=$listing['photos'][0]['xlarge_900']; $gender_class=strtolower($listing['gender']); $breed_class=strtolower($listing['species']); $name=($listing['name']); $unique_gallery_name="lightbox['.$inc.']"; $inc++; foreach($listing['photos'] as $photosthumb) { $photo_thumb_large=$photosthumb["xlarge_900"]; $photo_thumb_hidden=$photosthumb["xlarge_340"]; } $rand_background = $bg_colors[array_rand($bg_colors)]; // General IF/AND/ELSE Statements to refine the Echo Output if($listing['photos'] == null) { $medium_photo="http://xxx.org.au/wp-content/themes/xxx/images/photo_coming_soon.png"; } if($listing['desexed'] == "Yes") { $desexed="yes"; } else { $desexed="no"; } if($listing['vaccinated'] == "Yes") { $vaccinated="yes"; } else { $vaccinated="no"; } if($listing['wormed'] == "Yes") { $wormed="yes"; } elseif($listing['wormed'] == "No") { $wormed="no"; } else { $wormed="no"; } if($listing['heart_worm_treated'] == "Yes") { $heart_worm_tested="yes"; } elseif($listing['heart_worm_treated'] == "No") { $heart_worm_tested="no"; } else { $heart_worm_tested="no"; } if($listing['species'] == "Dog") { $adoption_enquiry_link="http://xxx.org.au/pre-adoption-form-dogs/?dog_name=$name"; $hwt="list-$heart_worm_tested"; } elseif($listing['species'] == "Cat") { $adoption_enquiry_link="http://xxx.org.au/pre-adoption-form-cats/?cat_name=$name"; $hwt="list-hwt-hidden"; } // Echo the output echo'<div class="animal"> <div class="animal-image"> <a class="size-thumbnail thickbox" rel="'.$unique_gallery_name.'" href="'.$gallery_first.'"> <img src="'.$medium_photo.'" class="image-with-border" alt=""> <div class="border" style="width: 340px; height: 340px;"> <div class="open"></div> </div> </a> <div class="item-title-bg '.$rand_background.'"> <h2 class="entry-title"> '.$listing['name'].'</h2> <div class="animal-adopt-button"> <a href="'.$adoption_enquiry_link.'" style="background-color: #575757; border-color: #494949; background-position:5px 0;" class="button medium"> Enquire about '.$name.'</a> </div> </div> </div> <div class="animal-thumbnail hidden"> <a class="lightbox" rel="'.$unique_gallery_name.'" href="'.$photo_thumb_large.'"> <img class="animal-thumbnail" src="'.$photo_thumb_hidden.'" > </a> </div> <div class="animal-content"> <div class="animal-left"> <ul class="animal-list"> <li class="list-sex-'.$gender_class.'">'.$listing['gender'].'</li> <li class="list-breed-'.$breed_class.'">'.$listing['breeds_display'].'</li> <li class="list-age">'.$listing['age'].'</li> <li class="list-fee">'.$listing['adoption_fee'].'</li> </ul> </div> <div class="animal-right"> <ul class="animal-list"> <li class="list-'.$desexed.'">Desexed?</li> <li class="list-'.$vaccinated.'">Vaccinated?</li> <li class="list-'.$wormed.'">Wormed?</li> <li class="'.$hwt.'">Heart Worm Tested?</li> </ul> </div> <div class="animal-full"> <ul class="animal-list"> <li class="list-description">'.$listing['personality'].'</li> </ul> </div></div> <div class="clearer"></div> </div> <div class="delimiter"></div>'; // Close the CURL } echo' <div class="pagination footer-pagination"> <nav class="pagination"> <div class="pages">'; for($i=1;$i<=$json['total_pages'];$i++) { $this_page=substr($_GET['page'],1); $active=""; if($i==$this_page) { $active="active"; } echo ' <span class="page'. $active.'"> <span class="number"> <a rel="prev" href="http://xxx.org.au/pet/?category=dog&page='.$i.'"> '.$i.'</a> </span> </span> </div> </nav> </div>'; curl_close($ch); } ?>This is a sample of the JSON results: {"listings":[{"adoption_fee":"$200 ","adoption_process":"For cats, please fill out our <a href=\"http://xxx.org.au/pre-adoption-form-cats/\">Pre-Adoption Questionnaire - Cats</a>.\r\n\r\nFor dogs, please fill out our <a href=\"http://xxx.org.au/pre-adoption-form-dogs/\">Pre-Adoption Questionnaire - Dogs</a>.\r\n\r\nFor more information on our Adoption Process, please visit this <a href=\"http://xxx.au/our-adoption-process/\">link</a>.\r\n\r\nPlease make sure that you are familiar with our <a href=\"http://xxx.org.au/adoption-agreement/\">Adoption Agreement</a> as it has recently changed.\r\n\r\nFor more information on any of our animals, please <a href=\"http://xxx.org.au/contact-us/\">Contact Us</a>.","age":"2 years 5 months","breeds":["Domestic Long Hair"],"breeds_display":"Domestic Long Hair","coat":"Long","contact_name":null,"contact_number":null,"contact_preferred_method":"Email","created_at":"30/1/2014 21:36","date_of_birth":"20/2/2012","desexed":true,"foster_needed":false,"gender":"Female","group":"xxx","heart_worm_treated":null,"id":273191,"interstate":false,"last_updated":"5/8/2014 12:20","medical_notes":"","microchip_number":"","mix":false,"multiple_animals":false,"name":"Helena HC13-394","personality":"Stunning Helena!\r\n\r\nThis beautiful girl is looking for a home that is fairly relaxed. She is not happy about sharing her current foster home with some bossy cats, she likes to be the princess of her realm.\r\n\r\nShe is very affectionate, and when it is quiet she will come and have a big smooch around our legs, and purr her pretty little purr. \r\n\r\nShe is somewhat timid to start with, but enjoys the company of people and once she trusts, she's a very special companion.\r\n\r\n","photos":[{"small_80":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_cb61a_70x70.jpg","medium_130":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_cb61a_130x130.jpg","large_340":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_cb61a_340x340.jpg","xlarge_900":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_cb61a_900x900.jpg"},{"small_80":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_7a7a7_70x70.jpg","medium_130":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_7a7a7_130x130.jpg","large_340":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_7a7a7_340x340.jpg","xlarge_900":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_7a7a7_900x900.jpg"},{"small_80":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_8b90b_70x70.jpg","medium_130":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_8b90b_130x130.jpg","large_340":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_8b90b_340x340.jpg","xlarge_900":"http://xxx.com.au/uploads/pet_photos/2014/1/30/273191_8b90b_900x900.jpg"},{"small_80":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_691df_70x70_96020.jpg","medium_130":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_691df_130x130_96020.jpg","large_340":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_691df_340x340_96020.jpg","xlarge_900":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_691df_900x900_96020.jpg"},{"small_80":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_6d9da_70x70_d2d41.jpg","medium_130":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_6d9da_130x130_d2d41.jpg","large_340":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_6d9da_340x340_d2d41.jpg","xlarge_900":"http://xxx.com.au/uploads/pet_photos/2014/4/26/273191_6d9da_900x900_d2d41.jpg"},{"small_80":"http://xxx.com.au/uploads/pet_photos/2014/7/12/273191_f209f_70x70_982c6.jpg","medium_130":"http://xxx.com.au/uploads/pet_photos/2014/7/12/273191_f209f_130x130_982c6.jpg","large_340":"http://xxx.com.au/uploads/pet_photos/2014/7/12/273191_f209f_340x340_982c6.jpg","xlarge_900":"http://xxx.com.au/uploads/pet_photos/2014/7/12/273191_f209f_900x900_982c6.jpg"}],"senior":false,"size":null,"species":"Cat","state":"WA","vaccinated":"Yes","wormed":"Yes"},And the pagination details are at the bottom of the JSON response: "page":"1","per_page":"50","total_pages":"6"The issue I get with all of this, is when calling the PHP file again, it's just returning the first page of results and not the second page. Any help would stop me from eating my own eyeballs, as I've been staring at this for hours! Cheers, Dave Hey guys, I really hope someone can help me out here. I have been working on my new website all week and am now almost finished. Just need to complete the contact page and touch up a few things... I really dont know php at all to be honest and just found a code somewhere on the net to help me. Heres my problem I have finally got the form to work but i am not recieving the correct data. I only get the email add, subject and messge. I am not getting the name of the sender.. also i really want to add a website field to the code because i do have that on the contact form... please can someone tell me where i am going wrong? the following is the php code i am using... <?php // Contact subject $subject ="Website enquiry"; // Details $message=$_POST[detail]; // Mail of sender $mail_from=$_POST[customer_mail]; // From $header="from: $name <$mail_from>"; // Enter your email address $to ='robin@rdosolutions.com'; $send_contact=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send_contact){ echo "We've recived your contact information"; } else { echo "ERROR"; } ?> please help me.. i am hoping to put the site live tomorrow... many thanks in advance.. rob Hi People. I am trying to insert data from a form into my database. Now I have the following code to connect to the DB to update a table so I know that I can connect to the DB ok Code: [Select] <?php // this code I got from the new boston, PHP tutorial 25 in selecting a mysql db // opens connection to mysql server $dbc = mysql_connect('localhost', 'VinnyG', 'thepassword'); if (!$dbc) { die("Not Connected:" . mysql_error ()); } // select database $db_selected = mysql_select_db ("sitename",$dbc); if(!$db_selected) { die("can not connect:" . mysql_error ()); } // testing code $query="UPDATE users SET username = 'testing testing' WHERE user_id = '2'"; $result=mysql_query($query); ?> Now here is the code from my form. Code: [Select] </head> <body> <?php //include "connection_file.php" //include "config01.php" $username = "username"; $height_above = "height_above"; $mb_diff = "mb_diff"; $alternative = "alternative"; ?> <form name = 'form1' method = 'post' action='config01.php'> <table width="700" border="1" cellspacing="5" cellpadding="5"> <caption> Submit Your Airfield Details </caption> <tr> <td width="100"> </td> <td width="200">Your Name</td> <td width="200"><input type='text' name='username' maxlength='30'></td> <td width="100"> </td> </tr> <tr> <td> </td> <td>Height Above MSL</td> <td><input type='text' name='height_above'maxlength= '30'></td> <td> </td> </tr> <tr> <td> </td> <td>Mb Difference</td> <td><input type='text' name='mb_diff'maxlength='40'></td> <td> </td> </tr> <tr> <td> </td> <td>Alternative Airfield</td> <td><input type='text' name='alternative' maxlength='30'></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><input type='submit' name='submit' value='post' /></td> <td> </td> <td> </td> <td> </td> </tr> </table> </form> <?php $sql01 = "INSERT INTO users SET user_id = '', username = '$username',height_above = '$height_above', mb_diff = $mb_diff, alternative = $alternative"; $result=mysql_query($sql01); ?> </body> </html> here is the config01.php that the form refers to in the 'action' above. Code: [Select] <?php $host = 'localhost'; $username = 'VinnyG'; $password = 'thepassword'; $db_name = 'sitename'; //connect to database mysql_connect ("$host","$username","password")or die ("cannot connect to server"); mysql_select_db ("db_name") or die ("cannot select DB"); ?> Please could someone look at the above code and tell me where I'm going wrong. I can connect to the DB and update using the top script but I can't submit the form for some reason. I get a "cannot connect to server" message. Please someone help. It's been driving me crazy for the past two days. Regards VinceG http://www.microlightforum.com Hi all, i was trying to include a php file in an index file into another files and those included file is including one file also. But for some reason the database connection file is not included. this is the map structure www/index.php <---- the file that uses include www/newsletter/newsletter.php <---- has a form with action process.php www/newsletter/process.php <--- this has an include referring to database.php www/newsletter/database.php <--- the databasefile This is what i did but it gives a server error in index.php include('newsletter/newsletter.php'); innewsletter.php <form action="newsletter/process.php" method="post"><!--- some form stuff--></form> in process.php include('database.php'); I really don't understand why it doesn't work and it's giving a server error 500. The form loads like it should in the index.php but the rest doesn't any help is appreciated. I have a simply script like this: $fh = fopen("test/test.js", 'w+') or die("can't open file"); fwrite($fh, $output); fclose($fh); It ONLY works if the "test" directory has a 777 permissions. Works like a charm then, but the moment it goes to even 775, I get this: Warning: fopen(test/test.js) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/mydomain.com/httpdocs/f.php on line 42 Any thoughts? I don't want this folder to remain 777 Thanks Hey guys! The error is that it seems to display EVERYTHING regardless of the if and else statements. Also, it seems to stop evaluating the rest of the document that "includes" this as soon as its done with this one. dbconnect works and all the session vars carry properly... WTF is going on!? <?php session_start(); include 'dbconnect.php'; $username = $_SESSION['username']; $q = mysql_query("SELECT User_type FROM account WHERE username = '$username'") or die(mysql_error()); $permission = mysql_fetch_row($q); $permission = $permission[0]; if(isset($_SESSION['username']) && $permission >= 2){ echo"<div id='page-section-mainmenu'><ul><li><a href=''><span>"; echo $menu001; echo "</span></a></li><li><a href=''><span>"; echo $menu002; echo "</span></a></li><li><a href=''><span>"; echo $menu003; echo "</span></a></li><li><a href=''><span>"; echo $menu004; echo "</span></a></li><li><a href=''><span>"; echo $menu006; echo "</span></a></li>";} elseif($permission <= 1){ echo"<div id='page-section-mainmenu'><ul><li><a href=''><span>"; echo $menu001; echo "</span></a></li><li><a href=''><span>"; echo $menu002; echo "</span></a></li><li><a href=''><span>"; echo $menu003; echo "</span></a></li><li><a href=''><span>"; echo $menu004; echo "</span></a></li>";} else{ echo"<div id='page-section-mainmenu'><ul><li><a href=''><span>"; echo $menu001; echo "</span></a></li><li><a href=''><span>"; echo $menu002; echo "</span></a></li><li><a href=''><span>"; echo $menu003; echo "</span></a></li><li><a href=''><span>"; echo $menu005; echo "</span></a></li>"; echo "<span> <form action='login.php' method='POST'> <input type='text' value='username' name='username'> <input type='text' value='password' name='password'> <input type='submit'> </form> </span> </li> </ul> </div> </div>";} ?> |