
petroz
Members-
Posts
180 -
Joined
-
Last visited
Never
Everything posted by petroz
-
holy schmoley! Thank you for your insight!
-
Try something like this SELECT `name`, `text` FROM `table` WHERE `name` = 'peter' ORDER BY RAND() LIMIT 2;
-
Im sorry... kind of working in the dark with the amount of code your providing. If you can give me a bigger picture (More of your code....) I can problem write in a method there for you.
-
<form action="index-5.php" method="post"> does not redirect to the index-5.php, it simply tells the form where to submit. So if your form is on the same page as your PHP script that processes it then you can use <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
-
Using session ID and username to update database?
petroz replied to orangecat's topic in PHP Coding Help
Have you looked at your session cookie to see if there is any data in it? -
This is untested, but header is the method for redirect. if ($number == "scuba") { //echo "CORRECT"; header('Location: success.php'); }
-
Using session ID and username to update database?
petroz replied to orangecat's topic in PHP Coding Help
I dont see where you are setting $userid, but you can try inserting the session data directly into the query... Not recommended, but it should work. mysql_query("UPDATE users SET dogs = '$breed' WHERE userID = '".$_SESSION['userid']."'"); -
Did any of this help?
-
Something like this might help... <?php $file = 'mytextfile.txt'; $data = $_POST['content']; if($_SERVER['REQUEST_METHOD'] == "POST") { //update the text file $fp = fopen($file, 'w+'); fwrite($fp, $data); fclose($fp); ?> <form action = "<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include $file; ?> </textarea> <br /> <input type="submit" value="Save"> </form> <? } else { ?> <form action = "<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include $file; ?> </textarea> <br /> <input type="submit" value="Save"> </form> <? }
-
I find it easier to work with an array for check boxes. Look at the example below. <?php if($_SERVER['REQUEST_METHOD'] == "POST") { $box = $_POST['myCheckBox']; foreach($box as $checked) { //delete($checked); print_r($checked); echo "<hr>"; } } else { //do something get ?> <form target="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="checkbox" name="myCheckBox[]" value="1"> <input type="checkbox" name="myCheckBox[]" value="2"> <input type="checkbox" name="myCheckBox[]" value="3"> <input type="submit"> </form> <? }
-
I dont see any check boxes...
-
Can you show some of your code? I might be able to point you in the right direction...
-
First... If you truly want to protect the file, you need to move it out of a public web directory. Second... Whitelisting IP's is very easy. Here is a rough example. <?php class Files { function __construct() { include 'db.php'; //start your database connection $this->mydir = "/var/protectedFiles/"; //note how it is not in the web directory $this->ip = $_SERVER['REMOTE_HOST']; //gets the IP address of the user //build an array of the url, then pickout the file they are looking for $request = parse_url($_SERVER['HTTP_REFERER']); $path = $request['path']; $path_parts = explode('/', $path); //seperate the path string into an array $this->myfile = $path_parts[1]; //if the url is like so... http://example.com/files/myfile.zip //run through the authorization process and give them what they deserve! $auth = $this->check_IP(); if($auth === "TRUE") { $file_exists = $this->check_file(); if($file_exists === "TRUE") { $file = file_get_contents($this->mydir.$this->myfile); //set an optional header header('HTTP/1.1 200 OK'); header('Content-Type: application/zip'); //print the file! print_r($file); } else { echo "We could not find the file you are looking for!"; die; } } else { echo "Access Denied"; die; } } private function check_IP() { //check your IP database for an IP $sql = "SELECT * FROM `ip_whitelist` WHERE `ip` = '".$this->ip."'"; $query = mysql_query($sql); $valid = mysql_num_rows($query); if($valid === 1) { return "TRUE"; //if the IP exists in your database } else { return "FALSE"; // if the IP does not exist in your database } } private function check_file() { if(file_exists($this->mydir.$this->myfile)) { return "TRUE"; // I found a file!!! } else { return "FALSE"; //I could not find what you are looking for! } } }
-
Another note... Switch is an old school method for for dealing with conditions.. here is an example. $sql = "SELECT * FROM airplanes WHERE ama='$ama'"; $query = mysql_query($sql); $rows = mysql_num_rows($query); switch ($rows) { case 0: echo "Error!!!!"; break; case 1: include 'display.php'; break; default: echo "we found more than one!"; break; }
-
Here is what your looking for... <?php require('header.php'); mysql_select_db('center'); $sql = "select username, password from users"; $result = mysql_query($sql); //$row = mysql_fetch_array($result); //$user = $row['username']; //$pass = $row['password']; echo "<table border='1'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>$row['username']</td>"; echo "<td>$row['password']</td>"; echo "</tr>"; } echo "</table>"; ?>
-
For the life of me, I cannot find a way to delete, cancel or remove facebook events I created & updated using the FB PHP SDK & the Graph API. I've tried every single permutation found on facebook's documentation & stack overflow... Here are some of the clues I have found on my quest.. https://developers.facebook.com/docs/reference/api/#deleting https://developers.facebook.com/docs/reference/api/event/ https://developers.facebook.com/docs/reference/rest/events.cancel/ http://stackoverflow.com/questions/2931387/facebook-sdk-and-graph-api-comment-deleting-error http://stackoverflow.com/questions/2858748/facebook-api-delete-status http://stackoverflow.com/questions/3832405/facebook-graph-api-delete-like Here is what I have tried so far. function delete_fb_event($event_data, $data) { //load the user for offline access and userid $user = $this->load_user($data['aid']); if(!empty($user[0]['fb_offline_access'])) { //instantiate Facebook API require 'facebook.php'; $facebook = new Facebook(array( 'appId' => 'BLAHBLAHBLAH', 'secret' => 'BLAHBLAHBLAHBLAHBLAHBLAH', 'cookie' => true, )); $fb_event = array( "access_token" => $user[0]['fb_offline_access'], ); $result = $facebook->api('/'.$event_data['fb_event_id'], 'DELETE', $fb_event); //Uncaught GraphMethodException: Unsupported delete request //$result = $facebook->api('/'.$user[0]['fb_id']."_".$event_data['fb_event_id'], 'POST', array('access_token' => $user[0]['fb_offline_access'], 'method' => 'delete')); Uncaught OAuthException: (#803) Some of the aliases you requested do not exist //$result = $facebook->api('/'.$event_data['fb_event_id']."_".$user[0]['fb_id'], 'POST', array('access_token' => $user[0]['fb_offline_access'], 'method' => 'delete')); Uncaught OAuthException: (#803) Some of the aliases you requested do not exist //$result = $facebook->api('/'.$event_data['fb_event_id'], 'POST', array('access_token' => $user[0]['fb_offline_access'], 'method' => 'delete')); Uncaught GraphMethodException: Unsupported post request //$result = $facebook->api('/'.$user[0]['fb_id']."_".$event_data['fb_event_id'], 'POST', array( 'access_token' => $user[0]['fb_offline_access'], 'method' => 'delete' )); Uncaught OAuthException: (#803) Some of the aliases you requested do not exist return $result; } else { echo "error3"; //no FB offline access } }
-
header is only going to redirect..... It would not execute display.php within his current script.
-
If display.php isnt a class with methods and its just procedural... just "include" it, like so. include "display.php"
-
LOL!!! How do you know???
-
Calling a jQuery function from PHP, NOT the other way around.
petroz replied to gergy008's topic in PHP Coding Help
I work in a PHP MVC environment and I do a ton of javascript. The easiest path I've found is having a <body onload="$onload"> on my view files. Basically, when I a specific script is run, if there is a defined onload javascript in my php file, the view file will render the onload tag to the body. My view works like so. <body <?php if(!empty($onLoad)) { echo 'onLoad="'.$onLoad.'"'; }?>> Then the controller would look like this. function add() { if($_SERVER['REQUEST_METHOD'] == "POST") { redirect('record/add'); } else { //set onLoad $data['onLoad'] = 'PO.add();'; // this is the javascript method I want to fire when the doc is ready //load the view $data['main_content'] = "record/add"; $this->load->view('includes/template', $data); } } Might be overkill for what you are looking to accomplish... but its a different approach. -
Replace your AND's with ",". AND's are used for WHERE statements. Should look like so. UPDATE `table` SET `field1` = 'BLAH!', `field2` = 'FOO', `field3` = 'BAR' WHERE `id` = '1' AND `status` = '1';
-
Hi Guys, I have an array that contains a few records from mysql. The array looks like so Array ( [0] => Array ( [id] => 1 [name] => New Product [url] => New-Product [title] => Title Used On Heading [description] => Write a 3 to 5 Paragraph summary of product [preview_image] => 0 [body_image] => 0 [status] => 1 ) [1] => Array ( [id] => 2 [name] => New Product [url] => New-Product [title] => Title Used On Heading [description] => Write a 3 to 5 Paragraph summary of product [preview_image] => 0 [body_image] => 0 [status] => 0 ) ) I am trying to modify the preview_image value on each of the arrays in this array like so; //modify the products array foreach($data['raw_products'] as $data['products']) { //set the preview image row $data['products']['preview_image'] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.previewIMG('".$data['products']['preview_image']."')", "class" => "noLink")); //set the body image row $data['products']['body_image'] = anchor('admin/list_products/#', "View IMG", array("onHover" => "admin.bodyIMG('".$data['products']['body_image']."')", "class" => "noLink")); } It works fine for one record, but then when I print_r($data['products']) I only see one record. Any help would be greatly appreciated.
-
Hi Guys, I got this method to upload an image once, now nothing is uploading at all and I cant seem to figure out why. I set permissions of both the script and image upload directory to www:/data and 777, but its still not working. When I print the return from basename, it show's 0, which means the file is uploaded.. But it not:( Here is my method. function add_product() { if($_SERVER['REQUEST_METHOD'] == "POST") { //get the form data $data['product'] = array( "name" => $this->input->post('name'), "title" => $this->input->post('title'), "description" => $this->input->post('description'), "status" => $this->input->post('live'), "url" => str_replace(" ", '-',$this->input->post('name')), "preview_image" => $this->input->post('preview_image'), "body_image" => $this->input->post('body_image') ); //add the record the the DB $this->load->model('products_model'); $return = $this->products_model->add_product($data); //upload the images $name = $_FILES['preview_image']['name']; $target = '/var/www/www.example.com/content/product_img/'; $upload = $target.basename($name); switch ($_FILES['preview_image']['error']) { case 1: print '<p> The file is bigger than this PHP installation allows</p>'; break; case 2: print '<p> The file is bigger than this form allows</p>'; break; case 3: print '<p> Only part of the file was uploaded</p>'; break; case 4: print '<p> No file was uploaded</p>'; break; } echo img('content/product_image/'.$name); //upload the images $name2 = $_FILES['body_image']['name']; $target2 = '/var/www/www.example.com/content/product_img/'; $upload2 = $target2.basename($name2); switch ($_FILES['preview_image']['error']) { case 1: print '<p> The file is bigger than this PHP installation allows</p>'; break; case 2: print '<p> The file is bigger than this form allows</p>'; break; case 3: print '<p> Only part of the file was uploaded</p>'; break; case 4: print '<p> No file was uploaded</p>'; break; } echo img('content/product_image/'.$name); //redirect to edit view //redirect('admin/edit_product/'.$return); //testing //print_r($data); } else { $data['title'] = 'Add Product :: FSG'; $data['main_content'] = 'admin/add_product'; $data['user'] = $this->facebook_connect->user; $data['user_id'] = $this->facebook_connect->user_id; $this->load->view('includes/template', $data); } } Here is the html for the form. <form action="<?php echo site_url();?>admin/add_product" method="post" enctype="multipart/form-data"> <div class="fieldset"> <h2 class="legend"> Product Information </h2> <ul class="form-list"> <li class="fields"> <div class="name"> <div class="field"> <label for="name" class="required"><em>*</em>Product Name</label> <div class="input-box"> <input type="text" id="name" name="name" value="New Product" title="Product Name" class="input-text required-entry" /> </div> </div> <div class="field title"> <label for="title" class="required"><em>*</em>Product Title</label> <div class="input-box"> <input type="text" id="title" name="title" value="Title Used On Heading" title="Product Title" class="input-text required-entry" /> </div> </div> </div> </li> <li> <label for="email" class="required"><em>*</em>Product Description</label> <div class="input-box"> <textarea id="description" name="description">Write a 3 to 5 Paragraph summary of product</textarea> </div> </li> <li class="control"> <input type="checkbox" name="live" id="live" value="1" title="Live Product" class="checkbox" /><label for="live_product">Publish Product</label> </li> </ul> </div> <div class="fieldset"> <h2 class="legend"> Product Images </h2> <ul class="form-list"> <li> <label for="preview_image" class="required"><em>*</em>Preview Image :: 240 X 166 Pixels</label> <div class="input-box"> <input type="file" name="preview_image"> </div> </li> <li class="fields"> <div class="field"> <label for="body_image" class="required"><em>*</em>Description Image :: 320 X 320 Pixels</label> <div class="input-box"> <input type="file" name="body_image"> </div> </div> </li> </ul> </div> <div class="buttons-set"> <p class="required"> * Required Fields </p> </p><button type="submit" title="Submit" class="button"><span><span>Submit</span></span></button> </div> </form>
-
I added intval to $ID.