Jump to content

woodplease

Members
  • Posts

    121
  • Joined

  • Last visited

    Never

Everything posted by woodplease

  1. hey. i have a webpage with a menu so that when a link is clicked, a div on the same page loads the links content into it. This works fine. The content of the div is a web form, that when submitted, reloads the page to add the content to the database. the problem is that when the form is submitted, the whole page is re-loaded instead of the div. how can i change it so that when the form(in the div) is submitted, the page is only reloaded in the div? The Menu code: <script type="text/javascript"> var loadedobjects="" var rootdomain="http://"+window.location.hostname function ajaxpage(url, containerid){ var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } page_request.open('GET', url, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText } function loadobjs(){ if (!document.getElementById) return for (i=0; i<arguments.length; i++){ var file=arguments[i] var fileref="" if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding if (file.indexOf(".js")!=-1){ //If object is a js file fileref=document.createElement('script') fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", file); } else if (file.indexOf(".css")!=-1){ //If object is a css file fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file); } } if (fileref!=""){ document.getElementsByTagName("head").item(0).appendChild(fileref) loadedobjects+=file+" " //Remember this object as being already added to page } } } </script> </head> <center> <div id="leftcolumn"> <a href="javascript:ajaxpage('new_cat.php', 'rightcolumn');">New Category</a> <a href="javascript:ajaxpage('new_album.php', 'rightcolumn');">New Album</a> <a href="javascript:ajaxpage('new_user.php', 'rightcolumn');">New User</a> </div> <div id="rightcolumn"><h3>Choose a page to load.</h3></div> The form code: <?php include "../dbconnect.php"; include "../menu.php"; if (isset ($_POST['cat_name'])){ $cat_name = mysql_real_escape_string($_POST['cat_name']); } if (isset ($_POST['cat_desc'])){ $cat_desc = mysql_real_escape_string($_POST['cat_desc']); } ?> <head> <script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script> </head> <center> <?php if (isset($_POST['submit'])) { mysql_query ("INSERT INTO category (cat_name, cat_desc) VALUES ('$cat_name', '$cat_desc')"); ?> <div id="txtHint"> <h1>Category added</h1><br /><br /><br /></div> <a href='javascript:javascript:history.go(-2)'>BACK</a> <?php } else { ?> <div id="stylized" class="login"> <h1>Create new Category</h1> <p>Please enter details for the new Category</p> <form id="new_category" method="post" action="new_cat.php"> <label>Category Name </label><input type="text" name="cat_name" size="50" /> <label>Description</label><textarea rows="10" cols="40" name="cat_desc"></textarea> <button type="submit" name="submit" >Add New Category</button> <?php } ?> </center>
  2. thats the problem, i cant view the error as the page itself doesnt load in the browser, its just run on the server
  3. i'm using swfupload to upload multiple files to a server. when the JavaScript runs, it calls the upload script on a separate php file. ive set the variable that defines what php file to load so that it passes a $_GET variable in the URL upload_url: "upload-file.php?album_id=<?php echo $album_id; ?>", This so on the actual upload page, i can add this variable to the database, along with detail about the uploaded file. My problem is that i'm not sure if the page is retrieving the variable as the page itself is never actually displayed. I've added an sql script to it to add to the database, but nothing gets added. First page <script type="text/javascript"> $(function(){ $('#swfupload-control').swfupload({ upload_url: "upload-file.php?album_id=<?php echo $album_id; ?>", file_post_name: 'uploadfile', file_size_limit : "10240", file_types : "*.jpg;*.png;*.gif", file_types_description : "Image files", file_upload_limit : 20, flash_url : "js/swfupload/swfupload.swf", button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png', button_width : 114, button_height : 29, button_placeholder : $('#button')[0], debug: false }) .bind('fileQueued', function(event, file){ var listitem='<li id="'+file.id+'" >'+ 'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+ '<div class="progressbar" ><div class="progress" ></div></div>'+ '<p class="status" >Pending</p>'+ '<span class="cancel" > </span>'+ '</li>'; $('#log').append(listitem); $('li#'+file.id+' .cancel').bind('click', function(){ var swfu = $.swfupload.getInstance('#swfupload-control'); swfu.cancelUpload(file.id); $('li#'+file.id).slideUp('fast'); }); // start the upload since it's queued $(this).swfupload('startUpload'); }) .bind('fileQueueError', function(event, file, errorCode, message){ alert('Size of the file '+file.name+' is greater than limit'); }) .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued); }) .bind('uploadStart', function(event, file){ $('#log li#'+file.id).find('p.status').text('Uploading...'); $('#log li#'+file.id).find('span.progressvalue').text('0%'); $('#log li#'+file.id).find('span.cancel').hide(); }) .bind('uploadProgress', function(event, file, bytesLoaded){ //Show Progress var percentage=Math.round((bytesLoaded/file.size)*100); $('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); }) .bind('uploadSuccess', function(event, file, serverData){ var item=$('#log li#'+file.id); item.find('div.progress').css('width', '100%'); item.find('span.progressvalue').text('100%'); var pathtofile='<a href="uploads/'+file.name+'" target="_blank" ></a>'; item.addClass('success').find('p.status').html('Done!!! '+pathtofile); }) .bind('uploadComplete', function(event, file){ // upload has completed, try the next one in the queue $(this).swfupload('startUpload'); }) }); </script> Upload-file.php <?php include "dbconnect.php"; if (isset($_GET['album_id'])){ $album_id = $_GET['album_id']; } $time = time(); $uploaddir = './images/album_photos/'; $name = mt_rand(). basename($_FILES['uploadfile']['name']); $file = $uploaddir.$name; $size=$_FILES['uploadfile']['size']; if($size>10485760) { echo "error file size > 10 MB"; unlink($_FILES['uploadfile']['tmp_name']); exit; } if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { echo "success"; } else { echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)"; } ?> <?php $img = imagecreatefromjpeg($file); $width = imagesx($img); $height = imagesy($img); $thumbWidth = 100; $new_width = $thumbWidth; $new_height = floor($height * ($thumbWidth / $width)); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($tmp_img, "images/photo_thumbs/t_".$name); imagedestroy($tmp_img); imagedestroy($img); $thumb_url = "images/photo_thumbs/t_".$name; $img = imagecreatefromjpeg($file); $width = imagesx($img); $height = imagesy($img); if ($height > $width){ $thumbHeight = 500; $new_height = $thumbHeight; $new_width = floor($width * ($thumbHeight / $height)); } else { $thumbWidth = 500; $new_width = $thumbWidth; $new_height = floor($height * ($thumbWidth / $width)); } $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($tmp_img, "images/display_photos/d_".$name); imagedestroy($tmp_img); imagedestroy($img); $display_url = "images/display_photos/d_".$name; mysql_query("INSERT INTO photos (upload_date, url, display_url, thumb_url, album_id) VALUES ('".$time."', '".$file."', '".$display_url."','".$thumb_url."', '".$album_id."')") or die (mysql_error()); ?> Any ideas?
  4. Ah right thanks, i was thinking i may have to use php to print the javascript, but was getting confused with all the quotes and single quotes.
  5. I'm using the swfupload script to upload multiple files to the server. i want to be able to pass a variable to the upload script so that i can also add the information to a database. i'm using the $_GET variable as the upload script page isnt actually displayed. how can i pass the $_GET variable to my script. $album_id = $_GET['album_id']; <script> $(function(){ $("#swfupload-control").swfupload({ upload_url: "upload-file.php?album_id='$album_id'", //i want the $album_id here so when the upload-file.php is called, the variable is passed to it. file_post_name: "uploadfile", file_size_limit : "10240", file_types : "*.jpg;*.png;*.gif", file_types_description : "Image files", file_upload_limit : 20, flash_url : "js/swfupload/swfupload.swf", button_image_url : "js/swfupload/wdp_buttons_upload_114x29.png", button_width : 114, button_height : 29, button_placeholder : $('#button')[0], debug: false }) .bind("fileQueued'", function(event, file){ var listitem='<li id="'+file.id+'" >'+ 'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+ '<div class="progressbar" ><div class="progress" ></div></div>'+ '<p class="status" >Pending</p>'+ '<span class="cancel" > </span>'+ '</li>'; $('#log').append(listitem); $('li#'+file.id+' .cancel').bind('click', function(){ var swfu = $.swfupload.getInstance('#swfupload-control'); swfu.cancelUpload(file.id); $('li#'+file.id).slideUp('fast'); }); // start the upload since it's queued $(this).swfupload('startUpload'); }) .bind('fileQueueError', function(event, file, errorCode, message){ alert('Size of the file '+file.name+' is greater than limit'); }) .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued); }) .bind('uploadStart', function(event, file){ $('#log li#'+file.id).find('p.status').text('Uploading...'); $('#log li#'+file.id).find('span.progressvalue').text('0%'); $('#log li#'+file.id).find('span.cancel').hide(); }) .bind('uploadProgress', function(event, file, bytesLoaded){ //Show Progress var percentage=Math.round((bytesLoaded/file.size)*100); $('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); }) .bind('uploadSuccess', function(event, file, serverData){ var item=$('#log li#'+file.id); item.find('div.progress').css('width', '100%'); item.find('span.progressvalue').text('100%'); var pathtofile='<a href="uploads/'+file.name+'" target="_blank" ></a>'; item.addClass('success').find('p.status').html('Done!!! '+pathtofile); }) .bind('uploadComplete', function(event, file){ // upload has completed, try the next one in the queue $(this).swfupload('startUpload'); }) }); </script> Any help would be greatly appreciated.
  6. i've sorted it now, i needed to put the destination in "imagejpeg($tmp_img, "/images/photo_thumbs"). Not sure why it wouldnt let me use the variable though
  7. i've tried that, no luck. i've even created a hyperlink to that location to check its accessible, which it is.
  8. it outputs "/images/album_photos/img2059005505.jpg" and then displays the image, so its definitely selecting the right image.
  9. hey, i have some code that uploads an image to a directory, and then creates a thumbnail of that image and stores that in another directory. The uploading of the file works, however after re-sizing the image, i get an error "Warning: imagejpeg() [function.imagejpeg]: Unable to open './images/album_thumb/' for writing: No such file or directory in C:\xampp\htdocs\kens\test2.php on line 43". The directory is there, so i'm not sure why i'm getting the error. Any ideas? $src = ($target.$name.".jpg"); $dest = "./images/album_thumb/"; $img = imagecreatefromjpeg($src); $width = imagesx($img); $height = imagesy($img); $thumbWidth = 10; $new_width = $thumbWidth; $new_height = floor($height * ($thumbWidth / $width)); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($tmp_img, $dest); imagedestroy($tmp_img); imagedestroy($img); $target is the the location of the file from the upload part of the script, and $name is the name of the file
  10. hey, i'm having an sql syntax error message display when trying to search my database. "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MATCH ('entry_text') AGAINST ('ancient')' at line 1" 'ancient' is the value being held in $search_string the code that i'm using is <?php if (isset($_POST['search_string'])){ $search_string = mysql_real_escape_string($_POST['search_string']); } ?> <form name="wikisearch" method="post" action="test.php"> <input type="text" name="search_string" size="40" /> <input type="submit" name="search" value="Search" /> </form> <?php if (isset($_POST['search_string'])){ $res = mysql_query("SELECT * FROM entry MATCH ('entry_text') AGAINST ('$search_string')")or die (mysql_error()); $ant = mysql_num_rows($res); echo "results: ".$ant; } ?> ANy ideas whats wrong
  11. Hi, i'm trying to retrieve and display just the first 50 characters of a field in a table, but when i try to display the result, i keep getting an undefined index error. $text =mysql_query("SELECT LEFT(entry_text,50) FROM entry WHERE entry_id='22'") or die(mysql_error()); while($row2 = mysql_fetch_array($text)){ echo "<p>".$row2['entry_text']; } When i leave out the " LEFT(entry_text,50)", so that it retrieves all the characters, it works fine. Any ideas? the exact error i get is "Notice: Undefined index: entry_text in C:\wamp\www\new\index.php on line 52"
  12. this seems to work, thanks. can you see whats wrong with my original code though? as it worked perfectly a couple of months ago, but now just displays a blank page. could it be some sort of php configuration issue?
  13. I've recently re-uploaded a website i created last year. when it was last online, everything worked perfectly, but now i'm finding that some of my pages that are supposed to retrieve data from a table are not returning anything. i havnt changed any code, and i have confirmed that there is data in the table. my c ode is as follows <?php $news=mysql_query("SELECT * FROM news ORDER BY date DESC") or die ("Unable to load latest site news"); $numofrows = mysql_num_rows($news); echo $numofrows; for($t = 1; $t<$numofrows; $t++){ $latest= mysql_fetch_array($news); $news_date = date("Y-m-d",$latest['date']); echo"<div class='rightLinks'>".$news_date."</div>"; echo $latest['article_title']."</h2><p>".$latest['article_text']; } ?> i've added the "echo $numofrows" just to check that it is getting something from the database, and the correct number of rows is displayed. if anyone can see any problems, any help would be greatly appreciated thanks
  14. i'm trying to echo out the results from a query onto a page, but rather than having them echo out as rows in a table, i want them to be displayed in columns, i.e. first column would have the first 10 results and the second column would have the next to. Any ideas on how i could do this? at the moment i'm using this code to display my results $read=mysql_query("SELECT * FROM entry WHERE category_id=".$id." ORDER BY entry_title") or die("query failed".mysql_error()); $result=mysql_num_rows($read); for($j = 0; $j < $result; $j++) { $row = mysql_fetch_array($read); echo "<a href=article.php?id=".$row['entry_id']. ">".$row['entry_title']."</a><br />"; } but this just displays it as a list down the middle thanks
  15. its ok, i've fixed it now, turns out i needed to add some quotes to the variable if(!isset($_SESSION["'$id'"])){ $_SESSION["'$id'"]= $id; Thanks anyway
  16. i'm creating a page counter which updates a value in a database each time the page is loaded. I'm trying to make it so that it checks to see if a session has been set, if not, it updates the database, and then sets the session. This way it wont update every time someone refreshes the page. $id=$_GET['id']; if(!isset($_SESSION[$id])){ $_SESSION[$id]= $id; $views = $row['views'] + 1; $update_views=mysql_query("UPDATE topic SET views='".$views."' WHERE topic_id='".$id."'") i want to set the session variable as that of the page id ($id) The problem is that it keeps updating the database everytime the page is reloaded. I'm not sure if i'm setting the session variable correctly. Any ideas would be great Thanks
  17. the $_Get['orderby'] returns a single letter, so i want to return all the values that begin with that letter
  18. well i'm not sure if it is or not, i do know that its similar to a regular expression, but i'm not quite sure how to use them
  19. sorry, typing error on my part, it already is $sort=$_GET['orderby']; so that isn't the problem
  20. i'm trying to an if statement so that a piece of code is only executed if a returned variable equals a letter in the alphabet(any letter) the variable is from a $_GET, and all i want to check is if the variable contains a letter. This is what i have so far, but it doesnt work $sort=$_GET[orderby]; if ($sort=="[A-Z]") { $read=mysql_query("SELECT * FROM films WHERE title LIKE '".$sort."%'") or die(mysql_error()); $result=mysql_num_rows($read); } else { $read=mysql_query("SELECT * FROM films ORDER BY title") or die("query failed"); $result=mysql_num_rows($read); } Any help would be great.
  21. hi, i'm trying to create an "if" statement that will add a value to a variable if it returns empty, e.g. if $year returns empty, set $year to "unknown", or if $certificate returns empty, set $certificate to unknown the code i have so far if (empty($year)) { $year="unknown"; } elseif (empty($certificate)) { $certificate="unknown"; } mysql_query("INSERT INTO films (title, year, certificate, date_added) VALUES ('$title','$year','$certificate','$date')") or die("Unable to add film<br/><a href='./add_film.php'>Back</a><br/>" .mysql_error()); when it $certficate returns empty, it will change the value to unknown, but when $year returns empty, it doesnt change its value. Any help would be great
  22. i think i've removed all of the bom characters, but its still not working i've posted the entire code in case anyone can see the error <?php session_start(); include "includes/dbconnect.php"; include "includes/functions.php"; forum_connect(); ?> <!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> <link rel="stylesheet" type="text/css" href="../style.css" /> <title>Wiki</title></head> <body id="page1"> <div id="header"> <div class="container"> <div class="logo"> <a href="index.html"><img src="images/logo.gif" alt="logo" /></a> </div> <?php nav_menu3(); ?> </div> </div> <div id="main"> <div id="content"> <div class="mainBanner"> <div class="indent"> <h1>SiFi Wiki<strong>Get your data here!</strong><strong></strong></h1> </div> </div> <div class="wrapper"> <div class="aside left"> <div class="inside"> <h3>Menu</h3> <ul class="list1"> <li> <?php menu(); ?> </ul> <a href="news.php">Read More... </a></div> </div> <div class="mainContent"> <div class="section"> <div class="box"> <div class="top"> <div class="bot"> <div class="inner"> <h2><img src="images/icon1.gif" alt="" /><strong><br/>Wiki's</strong><br/></h2> <?php $entry = mysql_query("SELECT * FROM entry ORDER BY entry_title") or die ("Query failed"); $numofrows2 = mysql_num_rows($entry); for($j = 0; $j < $numofrows2; $j++) { $row2 = mysql_fetch_array($entry); echo "<a href='view_entry.php?wiki={$row2[entry_title]}'>".stripslashes($row2[entry_title])."</a> "; echo "<br/>"; } ?></div> </div> </div> </div> </div> </div> </div> </div> <div id="footer"> <?php login(); ?> <a href="about.html">About</a> </div> </div> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.