PHP - Replacing Broken Images.
Ok mixing javascript with php.... im having bugs .
I basically want to replace any broken image links with a picture "noimage.gif" in the images folder. I tried this code but am getting the error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/showroom.php on line 78 This is the javascript header - all seems fine: <script language="JavaScript" type="text/javascript"> function ImgError(source){ source.src = "/images/noimage.gif"; source.onerror = ""; return true; } </script> this is the code thats erroring... is it the way ive written in the code into the IMG tag? while($row = mysql_fetch_array($result)){ echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100% BORDER=0>"; echo "<TR />"; echo "<TD WIDTH=30% VALIGN=TOP />"; echo " <A HREF='images/".$row['photo']."' target=_blank><IMG SRC='images/".$row['photo']."' width=186 height=155 border=0 onerror="ImgError(this);" /></A> "; echo "<br />"; echo "</TD>"; echo "<TD WIDTH=10 VALIGN=TOP />"; Similar TutorialsHi I am a php learner and I am having some problems while loading images from templates. I will explain everything so hope you can understand my question.. My Folder Structure WEB SITE NAME - index.php [default landing page] + Images [images folder] + css [css folder] + templates [templates folder] |-- header.inc.php [header template] |-- footer.inc.php [footer template] + includes [folder for all classes and variables] + js [folder for all js files] + contact-us [this is a folder] |--index.php [this is the file inside the contact-us folder] + about-us [this is a folder] |-- index.php [this is the file inside the about-us folder] This is the header.inc.php file without some html markups Quote <title>Web Site Name</title> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> </head> <body> <img src="images/phpmadeeasy.jpg" width="200" height="70" alt="php made easy logo" /> </body> ------------------------------------------------------------------------------ This is a sample main landing index.php page [i added codes only where i get into problems] Quote <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ As you can guess, default index.php file works fine... load both logo and banner images but... this is the index.php file located under the about-us folder Quote <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="../images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ Here only the banner image load because the template file still show the logo image path as "images/phpmadeeasy.jpg" instead of "../images/phpmadeeasy.jpg" so is there any way me to define the default image folder as a variable so i can use that variable to load images from any directory level Example: Quote <?php echo $images; ?>images/phpmadeeasy.jpg" <script type="text/javascript" src="<?php echo $js; ?>/jquery-1.4.4.min.js" <link href="<?php echo $css; ?>reset.css" rel="stylesheet" type="text/css" Thanks........... Hi I am a php learner and I am having some problems while loading images from templates. I will explain everything so hope you can understand my question.. My Folder Structure WEB SITE NAME - index.php [default landing page] + Images [images folder] + css [css folder] + templates [templates folder] |-- header.inc.php [header template] |-- footer.inc.php [footer template] + includes [folder for all classes and variables] + js [folder for all js files] + contact-us [this is a folder] |--index.php [this is the file inside the contact-us folder] + about-us [this is a folder] |-- index.php [this is the file inside the about-us folder] This is the header.inc.php file [just a example to let you understand my problem] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "URL/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="URL/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Web Site Name</title> <link href="css/reset.css" rel="stylesheet" type="text/css" /> <link href="css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> </head> <body> <img src="images/phpmadeeasy.jpg" width="200" height="70" alt="php made easy logo" /> </body> ------------------------------------------------------------------------------ This is a sample main landing index.php page [i added codes only where i get into problems] <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ As you can guess, default index.php file works fine... load both logo and banner images but... this is the index.php file located under the about-us folder <?php include_once('includes/header.inc.php') ?> <div id="mainWrapper"> <img src="../images/phpbigbanner.jpg" width="200" height="70" alt="php big banner" /> </div> <?php include_once('includes/footer.inc.php') ?> ------------------------------------------------------------------------------ Here only the banner image load because the template file still show the logo image path as "images/phpmadeeasy.jpg" instead of "../images/phpmadeeasy.jpg" so is there any way me to define the default image folder as a variable so i can use that variable to load images from any directory level Example: <?php echo $images; ?>images/phpmadeeasy.jpg" <script type="text/javascript" src="<?php echo $js; ?>/jquery-1.4.4.min.js" <link href="<?php echo $css; ?>reset.css" rel="stylesheet" type="text/css" Thanks........... Hi I am trying to replace characters in a string with images so character 'a' will be replaced with a.jpg etc I have tried the following code but that doesn't result in the desired effect as the updated string gets it's characters replaced as the script works through it so the 'img' in the first updated string gets replaced with with images and it all ends up quite a mess. Is there a simpler way to do this? $content = "abc" ; $content = str_replace("a", "<img src=images/a.jpg >", $content); $content = str_replace("b", "<img src=images/b.jpg >", $content); $content = str_replace("c", "<img src=images/c.jpg >", $content); $content = str_replace("d", "<img src=images/d.jpg >", $content); $content = str_replace("e", "<img src=images/e.jpg >", $content); $content = str_replace("f", "<img src=images/f.jpg >", $content); $content = str_replace("g", "<img src=images/g.jpg >", $content); $content = str_replace("h", "<img src=images/h.jpg >", $content); $content = str_replace("i", "<img src=images/i.jpg >", $content); $content = str_replace("j", "<img src=images/j.jpg >", $content); $content = str_replace("k", "<img src=images/k.jpg >", $content); $content = str_replace("l", "<img src=images/l.jpg >", $content); $content = str_replace("m", "<img src=images/m.jpg >", $content); $content = str_replace("n", "<img src=images/n.jpg >", $content); $content = str_replace("o", "<img src=images/o.jpg >", $content); $content = str_replace("p", "<img src=images/p.jpg >", $content); $content = str_replace("q", "<img src=images/q.jpg >", $content); $content = str_replace("r", "<img src=images/r.jpg >", $content); $content = str_replace("s", "<img src=images/s.jpg >", $content); $content = str_replace("t", "<img src=images/t.jpg >", $content); $content = str_replace("u", "<img src=images/u.jpg >", $content); $content = str_replace("v", "<img src=images/v.jpg >", $content); $content = str_replace("w", "<img src=images/w.jpg >", $content); $content = str_replace("x", "<img src=images/x.jpg >", $content); $content = str_replace("y", "<img src=images/y.jpg >", $content); $content = str_replace("z", "<img src=images/z.jpg >", $content); echo $content ; Any help would be gratefully appreciated. Thanks Megalos (paul) Please help. I am trying to replace parenthesises () in a string with <>. I tried preg_replace and str_replace, but was not success. Here is what I have for str_replace: $word = "(test)"; $word = str_replace('(', '<', $word); $word = str_replace(array('(', ')'), array('<','>'), $word); Much of the PHP documentation is broken into very small pages. I find that this makes it very difficult to use. Does anyone else find this? I have a hackish but useful program which takes the PHP single-file documentation and splits it into one page per extension, ensuring that links between pages work correctly. It works quite well. I wonder if anyone else would find this useful? If so, then I should have time in the next few weeks to clean it up and make it publicly available. I get a php error...Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given $sql = "SELECT `pm_messages`.`conversation_id` FROM `pm_messages` GROUP BY `pm_messages`.`conversation_id` WHERE `pm_messages`.`conversation_id` = ${conversation['id']}"; $result = mysql_query($sql); $replies = mysql_fetch_assoc($result); I copied the code for password_hash at php.net: <?php /** * In this case, we want to increase the default cost for BCRYPT to 12. * Note that we also switched to BCRYPT, which will always be 60 characters. */ $options = [ 'cost' => 12, ]; echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options); ?> and changed it for use in my login page:
$options = ['cost' => 12,]; $user = mysqli_real_escape_string($db_link,$_GET['username']); $pass = password_hash($_GET['password'], PASSWORD_BCRYPT, $options); but my page keeps saying invalid user/pass. Upon echoing the $pass I find that the result changes EACH time. so I created a test page that runs the code from php.net (verbatim code) 20x and I got: [pre]
$2y$10$Nlf0J520viR4C5jd3nIdd.6M3OMKACx503Jm3PiXDYZIs.13XAheq [/pre] Is password_hash broken? or am I mistaken to think that it's supposed to return the same output everytime fror the same input? Edited March 17, 2019 by Karaethontypos corrected this doesnt work and ive spent ages trying to figure it out
its the bit with else
<?php //CORS header header("Access-Control-Allow-Origin: *"); //Capture parameter $create = $_POST['create']; $fuser = $_POST['fuser']; if (!file_exists("uploads/$fuser/$create")); { if ($f = fopen("uploads/$fuser/$create", 'w')) { fwrite($f, 1); fclose($f); echo 'OK'; } } else { $f = fopen("uploads/$fuser/$create", 'w') fwrite($f, 5); fclose($f); echo 'FAIL' ; } ?>this bit does work below, its until i try to do else if , or else <?php //CORS header header("Access-Control-Allow-Origin: *"); //Capture parameter $create = $_POST['create']; $fuser = $_POST['fuser']; if (!file_exists("uploads/$fuser/$create")); { if ($f = fopen("uploads/$fuser/$create", 'w')) { fwrite($f, 1); fclose($f); echo 'OK'; } }help Hey guys, I have a quick question. Im going to be making a script that will output the name of a news article along with the poster's name beside it. There is only a certain amount of space where that stuff can go so I want to know how I can make it so that say after 20 characters, it ends and puts "..." beside it. Is this possible with php? How would I do it? Hey all, i need a function or a way to replace each letter in a string to a star (*) Thanks Hello, Is str_replace the best way to go about this? In MYSQL, a html template is stored, such that: Quote <table width="{$width}">lots of other ........</table> This is extract from the database, and stored in a string. I would use eval(), but, any user can update this template, so I need to be able to set which variables will be replaced with what the variable is. Thanks! hi freaks, still working on my email bot. im currently trying to escape <>-tags to be displayed- but not the browser wont exectute it (i.e. xls-tags) i want them as chars. so whin my $content is like <xsl:stylesheet> <xsl:template match="/"> <more xls...> it shows a stylesheet. i just want the chars. Here is what ive been trying so far: but its bad Code: [Select] <?php $string='<tag> > < asdasf'; $bomb=array( '<', '>', ); $defusal=array( '-', '!', ); $string= preg_replace($bomb,$defusal,$string); echo $string; ?> error: Warning: preg_replace() [function.preg-replace]: No ending matching delimiter '>' found in C:\xampp1\htdocs\code.php on line 13 donno any further now How come this is not replacing correctly? $rp = strtr($rp,"[TIMES]","<span style='font-family: Times New Roman, Times, serif'>") [ m ]printf[/ m]produces a link to
php.net/<span>printf
Unless you use nobbc tags, then it works fine ???
Edited by Barand, 24 November 2014 - 02:25 PM. So on my website I have a basic if statement that checks some arguments to see if a user can add another user as a friend. Well I had gotten that part down and for the longest time other people on my website have been able to use the feature. Now all of a sudden the if statement doesn't work? Why? Here is the statement: if ($privacy['privacy']['who_can_add'] == '1' AND $zext->user['id'] != '0' AND $zext->user['id'] != $u['id']) { $add_friend = $u['add_friend']; } of course if I put $add_friend outside the if statement, the button appears. How can a statment work one day but not the other? Is it an issue with my server? dump of $privacy: Code: [Select] $ => Array (4) ( | ['hide_o_status'] = Integer(1) 0 | ['who_can_view'] = Integer(1) 1 | ['who_can_add'] = Integer(1) 1 | ['who_can_contact'] = Integer(1) 1 ) dump of $zext->user['id']: Code: [Select] $ = String(2) "10" dump of $u['id']: Code: [Select] $ = String(2) "4" it all has correct information and the if statement has not been changed from before when it had worked and outputted $add_friend all day long. it worked until last night, i don't know what happened or why, php version has not been changed or anything. if anybody has any ideas on what's going on help would be much appreciated. Thanks, Matt. OK, hello everyone from your newest newbie - to this forum anyway. First thing to say is I do not claim to be the best php coder there is - as you will see when you look at my code ! Secondly, I have scoured/googled many sources to try and understand an answer to my problem without success. So, please first look at this page - http://www.thepearsons-ws.co.uk/php/MetMonthly.php If you pick March 2011 say you see a list of data presented on the same page. This is the effect I want to get to with a GD graph. If you now try my first attempt - http://www.thepearsons-ws.co.uk/php/raingraph3monthlyselect.php - and pick March 2011 and Submit AND click the link you get a graph on a new page. OK, but now what I want - I want the image on that same first page. So, I have the attached code which produces this - http://www.thepearsons-ws.co.uk/php/raingraph3monthlyselect2.php I have hacked the code around a bit but basically it's - PHP - form and data selection HTML - form with pull downs PHP - display graph. The image is broken. If I remove the HTML block completely it produces output but of course I can not vary the selection. Any small element of HTML here destroys the image - no whitespace or such - just <html> is enough. So, any clues on how to correctly structure this code would be greatly appreciated. Regards Phil If I have a web page located he www . company . com / how-to-repair-your-computer.html
And I decide to re-structure my website like this www . company . com / articles / how-to-repair-your-computer.html
How do I make sure that people don't search and end up at the old, now broken, link?
It seem inevitable that as a website grows, that you will want to re-organize things. What is the best way to make sure that anyone who searches or clicks on an old link - say from an email from a friend - doesn't get a 404 error?
Also, how do you avoid ruining a web pages rank on Google after you move things? (I think if the URL changes, Google makes you start all over as far as getting listed on page-1 and all of that?
Is this something I have to hande on my end, or is it a Google issue, or something else?
I recently changed hosts, now my image uploader which used to work fine doesn't work. $indeximage = $_FILES['indeximage']; if($indeximage) { $indeximagename = basename($_FILES['indeximage']['name']); $indeximagenew = $_SERVER['DOCUMENT_ROOT'] . '/images/uploaded/index/' . $indeximagename; if (!file_exists($indeximagenew)) { if ((move_uploaded_file($_FILES['indeximage']['tmp_name'], $indeximagenew)) === true) { echo 'Index Image uploaded to this address '; echo 'http://www.address.co.uk/images/uploaded/index/'; echo $indeximagename; echo '<br />'; }else { echo 'Unable to move Index Image into the right folder.'; } } } It now echos Unable to move Index Image into the right folder. I tried putting: ini_set("display_errors", "1"); error_reporting(E_ALL); at the beginning. Before the upload it reads: Notice: Undefined index: images in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 58 Notice: Undefined index: indeximage in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 62 After it reads: Warning: move_uploaded_file(): Unable to move '/tmp/phpTd67fh' to '/var/www/vhosts/huhmagazine.co.uk/httpdocs/images/uploaded/index/calidewitt.jpg' in /var/www/vhosts/huhmagazine.co.uk/httpdocs/admin/images.php on line 71 $compQ = "SELECT companies.companyid, companies.companyname, companies.companylogo, companies.companyoccupation, companies.industry, eQuestions.capitalrequested FROM companies LEFT JOIN eQuestions ON companies.companyid = eQuestions.companyid"; This is not displaying data correctly. I'm assuming eQuestions.capitalrequested is not in the correct spot? |