Jump to content
xisto Community

dsjoes

Members
  • Content Count

    18
  • Joined

  • Last visited

Posts posted by dsjoes


  1. i think it might be this part of the sagscroller.js

    init:function($){                var setting=this.setting                this.$loadingpanel.hide()                this.$mainul=this.$slider.find('ul:eq(0)').css({zIndex:1000})                this.$lis=this.$mainul.find('li')                if (setting.navpanel.show)                        this.addnavpanel()                this.$secul=this.$mainul.clone().css({top:this.$mainul.height(), zIndex:999}).appendTo(this.$slider) //create sec UL and add it to the end of main UL                this.scrollmsg(setting.mode=="auto")        },


  2. i have got the code below it is for a scroll box and i have added the php part of it so that i can change the text from the admin page. the problem is that the scroller code is duplicating the text so it shows twice. how do i stop it from happening.

     

    I think it is the javascript part that is causing the problem but i don't know where or which part.

     

    scroller.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://forums.xisto.com/no_longer_exists/ xmlns="http://forums.xisto.com/no_longer_exists/ http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><link rel="stylesheet" type="text/css" href="sagscroller.css" /><script src="sagscroller.js">/************************************************ SAG Content Scroller- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com/)* Visit http://www.dynamicdrive.com/ for hundreds of DHTML scripts* This notice must stay intact for legal use***********************************************/</script><style type="text/css">div#mysagscroller{width: 200px;  /*width of scroller*/height:250px;background:#FFF;}div#mysagscroller ul li{background:#FFFF48;color:Black;padding:5px;margin-bottom:5px; /*bottom spacing between each LI*/}div#mysagscroller ul li:first-letter{font-size:28px;background:#009fc6;color:white;padding:0 2px;margin-right:2px;}</style><script>var sagscroller1=new sagscroller({	id:'mysagscroller',	mode: 'manual' //<--no comma following last option})</script></head><body><div id="mysagscroller" class="sagscroller">	<ul>	<?php$con = mysql_connect("host","user","pass");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("group_news", $con);$result = mysql_query("SELECT * FROM News");while($row = mysql_fetch_array($result)){echo nl2br($row['News']);}mysql_close($con);?>	</ul></div></body></html>

     

    sagscroller.js

    /*Sag Content Scroller (Aug 7th, 2010)* This notice must stay intact for usage * Author: Dynamic Drive at http://www.dynamicdrive.com/* Visit http://www.dynamicdrive.com/ for full source code*///Updated Aug 28th, 10 to v1.3var sagscroller_constants={	navpanel: {height:'16px', downarrow:'/pics/main/down1.gif', opacity:0.6, title:'Go to Next Content', background:'black'},	loadingimg: {src:'/pics/main/ajaxloading.gif', dimensions:[100,15]}}function sagscroller(options){	this.setting={mode:'manual', inittype:'stunted', pause:3000, animatespeed:500, ajaxsource:null, rssdata:null, refreshsecs:0, navpanel:{show:true, cancelauto:false}} //default settings	jQuery.extend(this.setting, options) //merge default settings with options	options=null	this.curmsg=0	this.addloadingpanel(jQuery, 'preload')	if (this.setting.rssdata) //if rss contents		google.load("feeds", "1") //init google ajax api	var slider=this	jQuery(function($){ //on document.ready		slider.$slider=$('#'+slider.setting.id)		if (slider.setting.ajaxsource||slider.setting.rssdata)			slider.$slider.empty()		slider.addloadingpanel(jQuery, 'show')		if (slider.setting.ajaxsource) //if ajax data			slider.getajaxul(slider.setting.ajaxsource)		else if (slider.setting.rssdata){ //if rss data			slider.fetchfeeds()		}		else{ //if inline content			if (slider.setting.inittype=="onload") //load scroller when page has completely loaded?				$(window).load(function(){slider.init($)})			else //load scroller immediately and get dimensions progressively instead				slider.init($)		}	})}sagscroller.prototype={	getajaxul:function(path){		var $=jQuery, slider=this		this.stopscroll() //stop animation/ scrolling of slider, in the event this is a subsequent call to getajaxul()		this.$loadingpanel.show()		$.ajax({			url: path, //path to external content			async: true,			error:function(ajaxrequest){				slider.$slider.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)			},			success:function(content){				slider.reloadul(content)				if (slider.setting.refreshsecs>0) //refetch contents every x sec?					setTimeout(function(){slider.getajaxul(path)}, slider.setting.refreshsecs*1000)			}		})	},	addloadingpanel:function($, mode){		var loadingimgref=sagscroller_constants.loadingimg		if (mode=="preload"){			var loadingimg=new Image(loadingimgref.dimensions[0], loadingimgref.dimensions[1])			loadingimg.src=loadingimgref.src			this.$loadingimg=$(loadingimg).css({position:'absolute', zIndex:1003})		}		else{			var sliderdimensions=[this.$slider.width(), this.$slider.height()]			var $loadingpanel=$('<div />').css({position:'absolute', left:0, top:0, background:'black', opacity:0.5, width:sliderdimensions[0], height:sliderdimensions[1], zIndex:1002}).appendTo(this.$slider)			this.$loadingimg.css({left:sliderdimensions[0]/2-loadingimgref.dimensions[0]/2, top:sliderdimensions[1]/2-loadingimgref.dimensions[1]/2}).appendTo(this.$slider)			this.$loadingpanel=$loadingpanel.add(this.$loadingimg)		}	},	addnavpanel:function(){		var slider=this, setting=this.setting		var $navpanel=$('<div class="sliderdesc"><div class="sliderdescbg"></div><div class="sliderdescfg"><div class="sliderdesctext"></div></div></div>')			.css({position:'absolute', width:'100%', left:0, top:-1000, zIndex:'1001'})			.find('div').css({position:'absolute', left:0, top:0, width:'100%'})			.eq(0).css({background:sagscroller_constants.navpanel.background, opacity:sagscroller_constants.navpanel.opacity}).end() //"sliderdescbg" div			.eq(1).css({color:'white'}).end() //"sliderdescfg" div			.eq(2).css({textAlign:'center', cursor:'pointer', paddingTop:'2px'}).html('<img src="'+sagscroller_constants.navpanel.downarrow+'"/>').end().end()			.appendTo(this.$slider)		var $descpanel=$navpanel.find('div.sliderdesctext').attr('title', sagscroller_constants.navpanel.title).click(function(){ //action when nav bar is clicked on			slider.stopscroll()			slider.scrollmsg(setting.mode=="auto" && !setting.navpanel.cancelauto? true : false)		})		$navpanel.css({top:this.$slider.height()-parseInt(sagscroller_constants.navpanel.height), height:sagscroller_constants.navpanel.height}).find('div').css({height:'100%'})	},	resetuls:function(){ //function to swap between primary and secondary ul		var $tempul=this.$mainul		this.$mainul=this.$secul.css({zIndex:1000})		this.$secul=$tempul.css({zIndex:999})		this.$secul.css('top', this.ulheight)	},	reloadul:function(newhtml){ //function to empty out SAG scroller UL contents then reload with new contents		this.$slider.find('ul').remove()		this.ulheight=null		this.curmsg=0;		this.$slider.append(newhtml)		this.init($)			},	setgetoffset:function($li){		var recaldimensions=(this.setting.ajaxsource || this.setting.rssdata) && this.setting.inittype=="onload" //bool to see if script should always refetch dimensions		if (this.curmsg==this.$lis.length)			return (!this.ulheight || recaldimensions)? this.ulheight=this.$mainul.height() : this.ulheight		else{			if (!$li.data('toppos') || recaldimensions)				$li.data('toppos', $li.position().top)			return $li.data('toppos')		}	},	scrollmsg:function(repeat){		var slider=this, setting=this.setting		var ulheight=this.ulheight || this.$mainul.height()		var endpoint=-this.setgetoffset(this.$lis.eq(this.curmsg))		this.$mainul.animate({top: endpoint}, setting.animatespeed, function(){			slider.curmsg=(slider.curmsg<slider.$lis.length+1)? slider.curmsg+1 : 0			if (slider.curmsg==slider.$lis.length+1){ //if at end of UL				slider.resetuls() //swap between main and sec UL				slider.curmsg=1			}			if (repeat)				slider.scrolltimer=setTimeout(function(){slider.scrollmsg(repeat)}, setting.pause)		})		var secendpoint=endpoint+ulheight		this.$secul.animate({top: secendpoint}, setting.animatespeed)	},	stopscroll:function(){		if (this.$mainul){			this.$mainul.add(this.$secul).stop(true, false)			clearTimeout(this.scrolltimer)		}	},	init:function($){		var setting=this.setting		this.$loadingpanel.hide()		this.$mainul=this.$slider.find('ul:eq(0)').css({zIndex:1000})		this.$lis=this.$mainul.find('li')		if (setting.navpanel.show)			this.addnavpanel()		this.$secul=this.$mainul.clone().css({top:this.$mainul.height(), zIndex:999}).appendTo(this.$slider) //create sec UL and add it to the end of main UL		this.scrollmsg(setting.mode=="auto")	},	///////////////////////RSS related methods below///////////////////	fetchfeeds:function(){		var slider=this, rssdata=this.setting.rssdata		this.stopscroll() //stop animation/ scrolling of slider, in the event this is a subsequent call to fetchfeeds()		this.$loadingpanel.show()		this.entries=[] //array holding combined RSS feeds' entries from Feed API (result.feed.entries)		this.feedsfetched=0		for (var i=0; i<rssdata.feeds.length; i++){ //loop through the specified RSS feeds' URLs			var feedpointer=new google.feeds.Feed(rssdata.feeds[i][1]) //create new instance of Google Ajax Feed API			feedpointer.setNumEntries(rssdata.entries) //set number of items to display			feedpointer.load(function(label){				return function(r){					slider.storefeeds(r, label)				}			}(rssdata.feeds[i][0])) //call Feed.load() to retrieve and output RSS feed.		}		},	storefeeds:function(result, label){		var thisfeed=(!result.error)? result.feed.entries : "" //get all feed entries as a JSON array or "" if failed		if (thisfeed==""){ //if error has occured fetching feed			alert("Google Feed API Error: "+result.error.message)		}		for (var i=0; i<thisfeed.length; i++){ //For each entry within feed			result.feed.entries[i].label=label //extend it with a "label" property		}		this.entries=this.entries.concat(thisfeed) //add entry to array holding all feed entries		this.feedsfetched+=1		if (this.feedsfetched==this.setting.rssdata.feeds.length){ //if all feeds fetched			if (this.setting.rssdata.groupbylabel){ //sort by label name?				this.entries.sort(function(a,{					var fielda=a.label.toLowerCase(), fieldb=b.label.toLowerCase()					return (fielda<fieldb)? -1 : (fielda>fieldb)? 1 : 0				})			}			else{ //just sort by date				this.entries.sort(function(a,{return new Date(b.publishedDate)-new Date(a.publishedDate)})			}			this.formatfeeds()		}	},	formatfeeds:function(){		function formatdate(datestr, showoptions){			var itemdate=new Date(datestr)			var parseddate=(showoptions.indexOf("datetime")!=-1)? itemdate.toLocaleString() : (showoptions.indexOf("date")!=-1)? itemdate.toLocaleDateString() : ""			return "<span class='datefield'>"+parseddate+"</span>"		}		var sagcontent='<ul>'		var slider=this, rssdata=this.setting.rssdata, entries=this.entries		for (var i=0; i<entries.length; i++){			sagcontent+='<li><a href="'+entries[i].link+'" target="'+rssdata.linktarget+'">'+entries[i].title+'</a>'				+'<div class="rsscontent">'				+(/description/.test(rssdata.displayoptions)? entries[i].content : entries[i].contentSnippet)				+'</div>'				+'<div class="rsslabel">'				+(/label/.test(rssdata.displayoptions)? "<b>Source("+(i+1)+"):</b> "+entries[i].label+" " : "")				+(/date/.test(rssdata.displayoptions)? formatdate(entries[i].publishedDate, rssdata.displayoptions): "")				+'</div>'				+'</li>\n\n'		}	sagcontent+='</ul>'	this.reloadul(sagcontent)	if (slider.setting.refreshsecs>0) //refetch contents every x sec?		setTimeout(function(){slider.fetchfeeds()}, slider.setting.refreshsecs*1000)	}}

    it is also using the script from here as well http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js


  3. The reason for that error is because you have already began outputting HTML code so redirecting after that point is not possible. You can move your whole PHP code block to the top before you begin your HTML output and it should work.

    <?php// Set Global Vars$HOST = "";$USERNAME = "";$PASSWORD = "";$DATABASE = "";$TABLE = "";// Establish a connectionmysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());mysql_select_db($DATABASE) or die(mysql_error());//==================================================================// Check if anything is posted//==================================================================if (isset($_POST['delete'])) {    $sql = ("delete from $TABLE where ");    for ($i = 0; $i < count($_POST['checkbox']); $i++) {        if ($i != 0) {            $sql.= "OR ";        }        $sql .= " id='" . $_POST['checkbox'][$i] . "'";        //==================================================================        // Select file to unlink based on id posted        //==================================================================        $sql_file_unlink = "select Download from $TABLE where id = {$_POST['checkbox'][$i]}";        $result_file_unlink =  mysql_query($sql_file_unlink);        $row_file_link = mysql_fetch_assoc($result_file_unlink);        if($row_file_link) {             unlink('../testimonial_files/' . $row_file_link['Download']);        }        //==================================================================    }    $result = mysql_query($sql);    header('Location: index.php');    exit;} else {    // select sql here    $sql = "select * from `$TABLE` order by `id`;";    $result = mysql_query($sql);}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://forums.xisto.com/no_longer_exists/ xmlns="http://forums.xisto.com/no_longer_exists/ http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Testimonials</title><link href="../style.css" rel="stylesheet" type="text/css" /><link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />      <script type="text/javascript" src="uploadify/jquery-1.4.2.min.js"></script>      <script type="text/javascript" src="uploadify/swfobject.js"></script>      <script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>      <script type="text/javascript">      $(document).ready(function() {        $('#file_upload').uploadify({          'uploader'  : 'uploadify/uploadify.swf',          'script'    : 'uploadify/uploadify.php',          'cancelImg' : 'uploadify/cancel.png',          'folder'    : '../testimonial_files',          'auto'      : true        });      });      </script>      </head><body><div class="container">  <div class="header"><br /><br /><br /> </div>  <div class="sidebar1">    <ul class="nav"><b>      <li><a href="../">Home</a></li>      <li><a href="/admin/">Testimonials upload</a></li>      <li><a href="audio/">Audio Testimonials upload</a></li>      <li><a href="dvds/">Dvd's upload</a></li>      <li><a href="newsletter/">Newsletter upload</a></li>      <li><a href="news/">News box update</a></li>     </b></ul></div>  <div class="content">  <center><h2>Admin</h2></center>  <br /><center><p><input id="file_upload" name="file_upload" type="file" /></p><p><table width="200" border="0"><form action="insert_test.php" method="post">  <tr>    <td align="right">Name:</td>    <td><input type="text" name="Name" /></td>  </tr>  <tr>    <td align="right">Description:</td>    <td><input type="text" name="Message" /></td>  </tr>    <tr>    <td align="right">Download:</td>    <td><input name="Download" type="text" /></td>    </tr>    <tr>        <td colspan="2" align="center"><input type="submit" value="Submit" /></td>  </tr></form></table></p><br /><br /><p><table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">     <tr>      <td colspan="6" align="center"><strong>Testimonials</strong> </td>    </tr>    <tr>        <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">                <table width="400" border="1" cellpadding="3" cellspacing="1">                    <tr>                        <td align="center"><strong>Select</strong></td>                        <td align="center"><strong>ID</strong></td>                        <td align="center"><strong>Name</strong></td>                        <td align="center"><strong>Description</strong></td>                        <td align="center"><strong>Download</strong></td>                        <td align="center"><strong>Last Modified</strong></td>                    </tr><?php $row = mysql_fetch_assoc($result); ?><?php do { ?>                        <tr>                            <td align="center">                                <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">                            </td>                            <td align="center"><?php echo $row['id']; ?></td>                            <td align="center"><?php echo $row['Name']; ?></td>                            <td align="center"><?php echo $row['Message']; ?></td>                            <td align="center"><a href="../testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>                            <td align="center"><?php echo date("j/n/y", strtotime($row["Modified"])) ?></td>                        </tr>                      <?php                      } while ($row = mysql_fetch_assoc($result)); ?>                        <tr>                            <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>                        </tr>                    </table>                </form>            </td>        </tr>    </table></p></center></div>  <div class="sidebar2">    <h4>Text here</h4>    <p> </p>  </div>  <div class="footer">    <center><p>Š Copyright 2010</p></center>    </div>  </div></body></html>
    thanks that worked

  4. i get the below message when i try to use the script near the bottom which deletes from an sql database and the linked file but if i put the script on a page on it's own it works without a hitch. so it is something else on his page that is causing the problem i have tried removing everything but the main design but it is then indicating the error is because of the divs i have used and every time i remove the one it wants it changes to another.

    Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php:10) in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/index.php on line 95

    line 95 is this bit
    header('Location: index.php');
    and line ten is the stylesheet for uploadify

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://forums.xisto.com/no_longer_exists/ xmlns="http://forums.xisto.com/no_longer_exists/ http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Testimonials</title><link href="../style.css" rel="stylesheet" type="text/css" /><link href="uploadify/uploadify.css" type="text/css" rel="stylesheet" />      <script type="text/javascript" src="uploadify/jquery-1.4.2.min.js"></script>      <script type="text/javascript" src="uploadify/swfobject.js"></script>      <script type="text/javascript" src="uploadify/jquery.uploadify.v2.1.4.min.js"></script>      <script type="text/javascript">      $(document).ready(function() {        $('#file_upload').uploadify({          'uploader'  : 'uploadify/uploadify.swf',          'script'    : 'uploadify/uploadify.php',          'cancelImg' : 'uploadify/cancel.png',          'folder'    : '../testimonial_files',          'auto'      : true        });      });      </script>      </head><body><div class="container">  <div class="header"><br /><br /><br /> </div>  <div class="sidebar1">    <ul class="nav"><b>      <li><a href="../">Home</a></li>      <li><a href="/admin/">Testimonials upload</a></li>      <li><a href="audio/">Audio Testimonials upload</a></li>      <li><a href="dvds/">Dvd's upload</a></li>      <li><a href="newsletter/">Newsletter upload</a></li>      <li><a href="news/">News box update</a></li>     </b></ul></div>  <div class="content">  <center><h2>Admin</h2></center>  <br /><center><p><input id="file_upload" name="file_upload" type="file" /></p><p><table width="200" border="0"><form action="insert_test.php" method="post">  <tr>    <td align="right">Name:</td>    <td><input type="text" name="Name" /></td>  </tr>  <tr>    <td align="right">Description:</td>    <td><input type="text" name="Message" /></td>  </tr>    <tr>    <td align="right">Download:</td>    <td><input name="Download" type="text" /></td>    </tr>    <tr>        <td colspan="2" align="center"><input type="submit" value="Submit" /></td>  </tr></form></table></p><br /><br /><p><?php// Set Global Vars$HOST = "";$USERNAME = "";$PASSWORD = "";$DATABASE = "";$TABLE = "";// Establish a connectionmysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());mysql_select_db($DATABASE) or die(mysql_error());//==================================================================// Check if anything is posted//==================================================================if (isset($_POST['delete'])) {    $sql = ("delete from $TABLE where ");    for ($i = 0; $i < count($_POST['checkbox']); $i++) {        if ($i != 0) {            $sql.= "OR ";        }        $sql .= " id='" . $_POST['checkbox'][$i] . "'";        //==================================================================        // Select file to unlink based on id posted        //==================================================================        $sql_file_unlink = "select Download from $TABLE where id = {$_POST['checkbox'][$i]}";        $result_file_unlink =  mysql_query($sql_file_unlink);        $row_file_link = mysql_fetch_assoc($result_file_unlink);        if($row_file_link) {             unlink('../testimonial_files/' . $row_file_link['Download']);        }        //==================================================================    }    $result = mysql_query($sql);    header('Location: index.php');    exit;} else {    // select sql here    $sql = "select * from `$TABLE` order by `id`;";    $result = mysql_query($sql);}?><table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">     <tr>      <td colspan="6" align="center"><strong>Testimonials</strong> </td>    </tr>    <tr>        <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">                <table width="400" border="1" cellpadding="3" cellspacing="1">                    <tr>                        <td align="center"><strong>Select</strong></td>                        <td align="center"><strong>ID</strong></td>                        <td align="center"><strong>Name</strong></td>                        <td align="center"><strong>Description</strong></td>                        <td align="center"><strong>Download</strong></td>                        <td align="center"><strong>Last Modified</strong></td>                    </tr><?php $row = mysql_fetch_assoc($result); ?><?php do { ?>                        <tr>                            <td align="center">                                <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">                            </td>                            <td align="center"><?php echo $row['id']; ?></td>                            <td align="center"><?php echo $row['Name']; ?></td>                            <td align="center"><?php echo $row['Message']; ?></td>                            <td align="center"><a href="../testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>                            <td align="center"><?php echo date("j/n/y", strtotime($row["Modified"])) ?></td>                        </tr>                      <?php                      } while ($row = mysql_fetch_assoc($result)); ?>                        <tr>                            <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>                        </tr>                    </table>                </form>            </td>        </tr>    </table></p></center></div>  <div class="sidebar2">    <h4>Text here</h4>    <p> </p>  </div>  <div class="footer">    <center><p>Š Copyright 2010</p></center>    </div>  </div></body></html> 


  5. Yeah your right. I didn't look at the entire code and just pasted the whole block in. the

    unlink('../admin/testimonial_files/' . $row['Download']);
    line you can delete I think because its not needed? if you look at http://php.net/manual/en/function.unlink.php this method deletes a file and I don't remember you mentioning there was any files you also needed deleting. If you do need to delete a file as well then you can paste that line back into the loop block.

     

    Edit: I just looked at your code again and by the looks of it you only want to be deleting (unlinking) the file if the user submits a delete post right? If that is the case then you would need to do:

     

    <?php// Set Global Vars$HOST = "database";$USERNAME = "sonint99";$PASSWORD = "C2sHF9Zxq3ULXCTV";$DATABASE = "Random";$TABLE = "Testimonials";// Establish a connectionmysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());mysql_select_db($DATABASE) or die(mysql_error());//==================================================================// Check if anything is posted//==================================================================if (isset($_POST['delete'])) {    $sql = ("delete from $TABLE where ");    for ($i = 0; $i < count($_POST['checkbox']); $i++) {        if ($i != 0) {            $sql.= "OR ";        }        $sql .= " id='" . $_POST['checkbox'][$i] . "'";        //==================================================================        // Select file to unlink based on id posted        //==================================================================        $sql_file_unlink = "select Download from $TABLE where id = {$_POST['checkbox'][$i]}";        $result_file_unlink =  mysql_query($sql_file_unlink);        $row_file_link = mysql_fetch_assoc($result_file_unlink);        if($row_file_link) {             unlink('../admin/testimonial_files/' . $row_file_link['Download']);        }        //==================================================================    }    $result = mysql_query($sql);    header('Location: index.php');    exit;} else {    // select sql here    $sql = "select * from `$TABLE` order by `id`;";    $result = mysql_query($sql);}?><table  align="center" width="400" border="0" cellspacing="1" cellpadding="0">     <tr>      <td colspan="6" align="center"><strong>Testimonials</strong> </td>    </tr>    <tr>        <td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">                <table width="400" border="1" cellpadding="3" cellspacing="1">                    <tr>                        <td align="center"><strong>Select</strong></td>                        <td align="center"><strong>ID</strong></td>                        <td align="center"><strong>Name</strong></td>                        <td align="center"><strong>Description</strong></td>                        <td align="center"><strong>Download</strong></td>                        <td align="center"><strong>Last Modified</strong></td>                    </tr>                    <?php $row = mysql_fetch_assoc($result); ?><?php do { ?>                        <tr>                            <td align="center">                                <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">                            </td>                            <td align="center"><?php echo $row['id']; ?></td>                            <td align="center"><?php echo $row['Name']; ?></td>                            <td align="center"><?php echo $row['Message']; ?></td>                            <td align="center"><a href="/admin/testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>                            <td align="center"><?php echo $row['Modified']; ?></td>                        </tr>                      <?php                      } while ($row = mysql_fetch_assoc($result)); ?>                        <tr>                            <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>                        </tr>                    </table>                </form>            </td>        </tr>    </table><?php 

    I hope that's what you wanted. I removed some variables as it seems like they arnt being used like the delete id from the submit button.

     

     

    Thankyou it works :D


  6. that is now showing the data but it only shows the first row in the table the others are not in it i have attached a pic to show you what i mean and the description part is supposed to be empty i haven't put anything in it yet because of testing the unlink.untitled.bmp

    i have tryed the deleting bit but i get these two messages

    Warning: unlink(/testimonial_files/) [function.unlink]: Is a directory in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 15
    Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php:15) in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 24


    i have tryed with the full file path

    /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/testimonial_files/

    i have fixed the table not displaying correctly it is just the unlink and the header problem that i am still having problems with.
    the unlink part is too high up the code because it gets the ['Download'] part from this bit
    <?php $row = mysql_fetch_assoc($result); ?><?php do { ?>


  7. that is now showing the data but it only shows the first row in the table the others are not in it i have attached a pic to show you what i mean and the description part is supposed to be empty i haven't put anything in it yet because of testing the unlink.
    untitled.bmp

    i have tryed the deleting bit but i get these two messages

    Warning: unlink(/testimonial_files/) [function.unlink]: Is a directory in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 15
    Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php:15) in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 24


    i have tryed with the full file path

    /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/testimonial_files/


  8. What is your page suppose to be doing exactly? From the looks of it you are checking if there are any submissions for delete. If there are none which is mostly the case when you frist visit the page then that block is always going to execute. Which explains why the rest of the code fails because the block of code that assigns the $result1 variable never gets executed. You might want to change your if statements around appropriately.

    if(!isset($_POST['delete'])) {$sql = "select * from `$TABLE` order by `id`;";} else {$DELETE_ID = mysql_real_escape_string($_POST['delete']);echo("select * from `$TABLE` where `id` = '$DELETE_ID';");die();// Delete the file on the diskunlink('../admin/testimonial_files/'.$row['Download']);// Build your query, kind of weird but alright.$sql = ("delete from $TABLE where ");for($i=0;$i<count($_POST['checkbox']);$i++){if($i != 0) { $sql.= "AND "; }$sql .= " id='" . $_POST['checkbox'][$i] . "'";}

    if you do
    if(!isset($_POST['delete'])) {$sql = "select * from `$TABLE` order by `id`;";die("post delete not set");} else {$DELETE_ID = mysql_real_escape_string($_POST['delete']);echo("select * from `$TABLE` where `id` = '$DELETE_ID';");die("result should be set here");// Delete the file on the diskunlink('../admin/testimonial_files/'.$row['Download']);// Build your query, kind of weird but alright.$sql = ("delete from $TABLE where ");for($i=0;$i<count($_POST['checkbox']);$i++){if($i != 0) { $sql.= "AND "; }$sql .= " id='" . $_POST['checkbox'][$i] . "'";}

    that should tell you where its executing.

    that gives me the message

    post delete not set

    the script is supposed to let me delete a selected row from my sql database and also delete the file from the download column

  9. That's very strange. Can you post your entire script again if its changed a lot? There should be some kind of output or error if something is wrong. Is anything being reported?The only other way to figure it out is to keep going back up a line and outing echo statements to make sure it the code actually reaches that point. You need to figure out exactly where it dying before you can resolve any issues.


    <?php// Set Global Vars$HOST = "XXXXXXX";$USERNAME = "XXXX";$PASSWORD = "XXXXX";$DATABASE = "XXXXX";$TABLE = "Testimonials";// Establish a connectionmysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());mysql_select_db($DATABASE) or die(mysql_error());// Query for resultsif(!isset($_POST['delete'])) {$sql = "select * from `$TABLE` order by `id`;";} else {$DELETE_ID = mysql_real_escape_string($_POST['delete']);echo("select * from `$TABLE` where `id` = '$DELETE_ID';");die();// Delete the file on the diskunlink('../admin/testimonial_files/'.$row['Download']);// Build your query, kind of weird but alright.$sql = ("delete from $TABLE where ");for($i=0;$i<count($_POST['checkbox']);$i++){if($i != 0) { $sql.= "AND "; }$sql .= " id='" . $_POST['checkbox'][$i] . "'";}$result = mysql_query($sql);if(isset($_POST['delete'])) { header('Location: index.php');exit;}}?><table  align="center" width="400" border="0" cellspacing="1" cellpadding="0"><tr><td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"><table width="400" border="1" cellpadding="3" cellspacing="1"><tr><td colspan="6" align="center"><strong>Testimonials</strong> </td></tr><tr><td align="center"><strong>Select</strong></td><td align="center"><strong>ID</strong></td><td align="center"><strong>Name</strong></td><td align="center"><strong>Description</strong></td><td align="center"><strong>Download</strong></td><td align="center"><strong>Last Modified</strong></td></tr><?php $row = mysql_fetch_assoc($result); ?><?php do { ?>        <tr>                <td align="center">                        <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">                </td>                <td align="center"><?php echo $row['id']; ?></td>                <td align="center"><?php echo $row['Name']; ?></td>                <td align="center"><?php echo $row['Message']; ?></td>                <td align="center"><a href="/admin/testimonial_files/<?php echo $row['Download']; ?>">Download</a></td>                <td align="center"><?php echo $row['Modified']; ?></td>        </tr>        <tr>        <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>        </tr></table></form></td></tr></table><?php } while($row = mysql_fetch_assoc($result)); ?>

    only messages i get are the ones i posted in the first post nothing new

  10. Try it here.

    $DELETE_ID = mysql_real_escape_string($_POST['delete']);$result1 = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';");$row = mysql_fetch_assoc($result1);mysql_close($result1);// change to $DELETE_ID = mysql_real_escape_string($_POST['delete']);echo("select * from `$TABLE` where `id` = '$DELETE_ID';");die();

    still nothing

  11. Can you try a

    echo("select * from `$TABLE` where `id` = '$DELETE_ID';");

    The first thing you should do here is to try and verify you are building the sql correctly. There may be times where the value $DELETE_ID might not be as you expected so take the generated sql string and run it against your mysql database manually to verify it is valid. Any syntax errors you get you will need to fix.

    where do i put it i have tryed under the php but it doesn't echo anything

  12. It looks like the return from mysql_query() is not valid. You should first check its valid before performing anything on it such as mysql_fetch_assoc()

    Try this first:

    $result = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';");if (!$result) {    die('Invalid query: ' . mysql_error());} else {// do what ever you need to do here.}

    Good luck.


    nothing has changed it still shows the same messages

  13. These are the errors i keep getting

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 48
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web230/b2302/ipg.myaccount/test_server/admin/test1.php on line 67


    this is the code
    <?php// Set Global Vars$HOST = "XXXXXXXX";$USERNAME = "XXXXXXXXXXXX";$PASSWORD = "XXXXXXXX";$DATABASE = "testdocs";$TABLE = "docs";// Establish a connectionmysql_connect($HOST, $USERNAME, $PASSWORD) or die(mysql_error());mysql_select_db($DATABASE) or die(mysql_error());// Query for resultsif(!isset($_POST['delete'])) {$sql = "select * from `$TABLE` order by `id`;";} else {$DELETE_ID = mysql_real_escape_string($_POST['delete']);$result1 = mysql_query("select * from `$TABLE` where `id` = '$DELETE_ID';");$row = mysql_fetch_assoc($result1);mysql_close($result1);// Delete the file on the diskunlink('../admin/testimonial_files/'.$row['Download']);// Build your query, kind of weird but alright.$sql = ("delete from $TABLE where ");for($i=0;$i<count($_POST['checkbox']);$i++){if($i != 0) { $sql.= "AND "; }$sql .= " id='" . $_POST['checkbox'][$i] . "'";}$result = mysql_query($sql);if(isset($_POST['delete'])) { header('Location: index.php');exit;}}?><table  align="center" width="400" border="0" cellspacing="1" cellpadding="0"><tr><td><form name="delete" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"><table width="400" border="1" cellpadding="3" cellspacing="1"><tr><td colspan="6" align="center"><strong>Testimonials</strong> </td></tr><tr><td align="center"><strong>Select</strong></td><td align="center"><strong>ID</strong></td><td align="center"><strong>Name</strong></td><td align="center"><strong>Description</strong></td><td align="center"><strong>Download</strong></td><td align="center"><strong>Last Modified</strong></td></tr><?php $row = mysql_fetch_assoc($result); ?><?php do { ?>        <tr>                <td align="center">                        <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['id']; ?>">                </td>                <td align="center"><?php echo $row['id']; ?></td>                <td align="center"><?php echo $row['Name']; ?></td>                <td align="center"><?php echo $row['Message']; ?></td>                <td align="center"><a href="/admin/docs/<?php echo $row['Download']; ?>">Download</a></td>                <td align="center"><?php echo $row['Modified']; ?></td>        </tr>        <tr>        <td colspan="6" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td>        </tr></table></form></td></tr></table><?php } while($row = mysql_fetch_assoc($result)); ?>

    and these are the 2 lines the errors are referring to
    <?php $row = mysql_fetch_assoc($result); ?><?php do { ?><?php } while($row = mysql_fetch_assoc($result)); ?>


  14. It's probably because your $row['Download'] is not a table field name (column) or the records just contain an empty string. Verify the field name and records for it in the database.
    Good luck


    thanks it is working now and i didn't have to change anything and both script you helped me with used the same database table and the first one was still working.

  15. <td><? echo <a href='/docs"$row['Download']"'>Download</a>; ?></td>
    Try not to mix standard HTML tags with your echo PHP statement. It makes it more organized and less prone to errors as what ever editor you may be using can highlight the HTML code.


    This is how I would write it but its really up to personal preference.
    <td><a href="/docs/<?php echo $row['Download']; ?>">Download</a></td>

    it is not picking up the field name so it is just giving links like example.com/""

  16. Hi, First of all what does the $row['Download'] output? If it is just the file name then you will need to build the anchor tag your self. You should know where the file is being uploaded to so build the anchor tag accordingly.

    while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'>" . $row['Download'] . "</td>";echo "</tr>";}echo "</table>";

    Something like ?

    while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'><a href='PATH_TO_FILE".$row['Download']."'>" . $row['Download'] . "</a></td>";echo "</tr>";}echo "</table>";

    Assuming $row['Download'] contains your file name...
    Good luck


    Thank you that worked and i made a small alteration so that it would display the word download instead of the file name.

    echo "<td width='100'><a href='/docs".$row['Download']."'>Download</a></td>";


    how would i be able to do it with this one

    <td><? echo $rows['Download']; ?></td>

    i tryed but it dosn't work
    <td><? echo <a href='/docs"$row['Download']"'>Download</a>; ?></td>


  17. i have got my table and it works here is the code

    <?php$con = mysql_connect("host","user","pass");if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("b32_5584692_Docs", $con);$result = mysql_query("SELECT * FROM Docs");echo "<table border='1'><tr><th>Name</th><th>Message</th><th>Download</th></tr>";while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td width='150'>" . $row['Name'] . "</td>";echo "<td width='250'>" . $row['Message'] . "</td>";echo "<td width='100'>" . $row['Download'] . "</td>";echo "</tr>";}echo "</table>";mysql_close($con);?>

    and what i want to do is make the download part of the table a link so that when i insert new data into the sql database i don't have to type something like this everytime
    <a href="test.doc">Download</a>


    this is the form to add to the sql database
    <form action="insert_test.php" method="post">Name: <input type="text" name="Name" /><br />Message: <input type="text" name="Message" /><br />Download: <input name="Download" type="text" /> <br /><input type="submit" value="Submit" /></form>

    and this is the upload script
    <?php $con = mysql_connect("host","user","pass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("b32_5584692_Docs", $con);$sql="INSERT INTO Docs(Name, Message, Download)VALUES('$_POST[Name]','$_POST[Message]','$_POST[Download]')";if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  }echo "Record added";header('Location: index.php');mysql_close($con)?>

    i want to be able to type things link test.doc into the download part of the form and then the table to show the link to the file.

    Thanks
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.