AliceIsMyName Posted March 6, 2010 Share Posted March 6, 2010 Arrgghhhh!!! after hours and hours of twisting my code in all directions I think I need help before I completely ruin my code or even my mind!! I am a complete novice in php so I hope the answer will stand out to you more experienced coders :S I have been coding a captcha for a form, got that working (after hours and hours, days in fact) which felt really great, but my joy did not last long... What I thought would be easy peasy compared to what I had just coded, is just not working!!! I want the code to return an error message in the case that the captcha entered by the user doesn't match... I have been trying to make at least one of 2 existing strings change to show this message. These strings variables are : - $captcha_txt (found on index_bis.php lines 27, 45, 49, 61) - $commentbox_title (found on index_bis.php line90 and on comment_form_with_captcha.php line39) This is my first post ever on these so very very useful forums full of talented helpful people! I think I'll celebrate with some chocolate, get over my frustration and wait and pray someone amazing will post an answer back to me soon _______________________________________________________________________________________________ This is the url to my little site I'm coding = http://alcox.monline.dk/php2/index_bis.php The codes are viewable there too since this is part of an assignment for school, I had to provide links for the teachers although there is no link there to my comment_form_with_captcha.php source, since it will replace my_comment_form.php once all is working HERE is my code: 1 - comment_form_with_captcha.php : <?php $a =$_SESSION["captcha"] ; $b =$_POST["captcha"] ; if(! isset($_POST['updated'])){ $comment_form_html .= show_comment_form_admin(); } if(isset($_POST["captcha"])) if($a==$b){ $comment_form_html .= update_comment_form(); $commentbox_title .= "Thank you for commenting!"; $commentbox_title_style .=("commentbox_title_thx"); $comment_form_html .= show_comment_form_admin();} if(isset($_POST["captcha"])) if($a!=$b){ $comment_form_html .= show_comment_form_admin(); $captcha_txt .= "<p class='formtext'>brrrrrrrrrrrrrrrrrrrrrr</p>";} function show_comment_form_admin(){ //read data and set user name and comment $_SESSION['captcha'] = $captcha_input2; $comment_form_r = get_comment_form_data(); $comment = $comment_form_r["p"]; $usersname = $comment_form_r["h5"]; $directory = 'images/captcha/'; $captcha_imgs = array('4dfoe.jpg', '95f2d.jpg','443ee.jpg', 'ba902.jpg', 'd10fc.jpg','dq7mtl.jpg', 'znmzgn.jpg'); shuffle($captcha_imgs); foreach ($captcha_imgs as $captcha_img_src); $captcha_img .= '<img src="images/captcha/' . $captcha_img_src . '" id="captcha_img" alt="captcha" />'; $captcha_input2 .= str_replace (".jpg","","$captcha_img_src"); $captcha_input3 .= '<p>' . $captcha_input2 . '</p>'; $captcha_txt = '<p class="formtext">check that you are human and copy this code:</p>'; if(isset($_POST["captcha"])) if($a!=$b){ $comment_form_html .= show_comment_form_admin(); $captcha_txt .= "<p class='formtext'>brrrrrrrrrrrrrrrrrrrrrr</p>";} $out = ' <form method="post" action="#painting_title"> <fieldset> <p class="formtext">Your name:</p> <input type="text" name="h5"></input> <p class="formtext">Your comment:</p> <textarea name="p" id="users_comment" rows="" cols=""></textarea> ' . $captcha_txt . ' ' . $captcha_img . ' <input id="captcha" type="text" name="captcha"></input> <input type="image" class="post_bt" src="images/submit_button_1.gif" alt="Submit button" name="updated" value="Post comment"/> </fieldset> </form> '; return $out; } function update_comment_form(){ $img = $_GET['pic']; $title = str_replace(".jpg","_", $img); $title2 = str_replace("big_","", $title); $path = "comment_form.xml"; $path2 = ($title2) . "comment_data.xml"; $file = "comment_data/".($path); $file2 = "comment_data/".($path2); $xml = simplexml_load_file($file); $usersname = $_POST['h5']; $comment = $_POST['p']; $xml -> p = '"'. $comment . '"'; $xml -> h5 = $usersname .=":"; file_put_contents(($file2), $xml->asXML(), FILE_APPEND); } // get_comment_form_data here function get_comment_form_data(){ $img = $_GET['pic']; $title = str_replace(".jpg","_", $img); $title2 = str_replace("big_","", $title); $path = "comment_form.xml"; $path2 = ($title2) . "comment_data.xml"; $file = "comment_data/".($path); $file2 = "comment_data/".($path2); $xml = simplexml_load_file($file); $comment_form_r = array(); $comment_form_r["h5"] = $xml -> h5; $comment_form_r["p"] = $xml -> p; return $comment_form_r; } $comments_on_panting = 'comment_data/' . $title2 . 'comment_data.xml'; $comment = file_get_contents($comments_on_panting); ?> 2 - index_bis.php : <?php session_start(); $page_title = "Alice's Paintings"; $dir = 'images/'; $thumbs = array("small_promenade.jpg", "small_nina.jpg", "small_brian.jpg", "small_misty_window_panes.jpg", "small_horse.jpg", "small_souvenir_de_bang_og_jensen.jpg", "small_souvenir_du_bar_saint_laurent.jpg", "small_pommes.jpg", "small_courbes_et_couleurs.jpg", "small_montpellier_et_la_pluie.jpg", "small_feuilles_extraordinaires.jpg", "small_just_for_fun.jpg", "small_copenhagen_dancing_for_jonathan.jpg", "small_copenhagen_dancing_for_alice.jpg", "small_plastic_bag.jpg", "small_brian_portrait.jpg"); $gallery = '<div class="gallery"><div id="thumbs">' . "\n"; for ($i=0; $i<count($thumbs); $i++){ $thumb = $thumbs[$i]; $find ="/small_/"; $replace ="big_"; $big = preg_replace ($find, $replace, $thumb); $gallery .= '<a href="?pic='. $big .'#root_link">'; $gallery .= '<img src="' . $dir . $thumb . '" alt=" " /></a>'; } if(isset($_GET['pic'])){ $img = $_GET['pic']; include ("galleryifs.php"); $title = str_replace(".jpg","_", $img); $title2 = str_replace("big_","", $title); $title3 = str_replace("_"," ", $title2); $commentbox_title = ("Comment on this painting here:"); $commentbox_title_style =("commentbox_title_1"); $gallery .= '<a href="?pic=big_' . $nextimg . '.jpg#root_link"><img src="' . $dir . $img . '" alt="img " style="padding-top:30px;"/></a></div></div>'; $galleryrootlink =' <p id="root_link"><a href="index.php">Back to gallery root</a></p>'; }else{ $gallery .= '<p>Pick a Painting from the thumbnails above...</p><img src="images/big_i_love_painting.jpg" alt="img" /></div></div>'; $commentbox_title = ("Comment on this gallery here:"); $commentbox_title_style = ("commentbox_title_2"); $commentbox_title_extra = ("You can also comment on the individual paintings as you navigate through the gallery."); } include("sourcelinks1.php"); include ("galleryifs.php"); if( isset($_POST['updated'])){ header('Location:?pic='. $img .'#painting_title');} ?> <?php $find1 ='<?xml version="1.0" encoding="utf-8"?>'; $replace1 =""; $comment = str_replace("$find1","$replace1","$comment"); ?> <?php include("head.php")?> <body <?php echo $ratingobj; ?>> <div class="maincontent"> <div class="title_1"></div> <?php echo $galleryrootlink;?> <?php echo $gallery; ?> <h2 id="painting_title"><?php echo ucwords ("$title3"); ?></h2> <?php echo $vid_link; ?> <div id="<?php echo $rating; ?>"></div> <?php include("comment_form_with_captcha.php");?> <div class="comments_box"> <h3 id="<?php echo $commentbox_title_style; ?>" ><?php echo $commentbox_title; ?></h3> <h5 id="commentbox_title_2_extra" ><?php echo $commentbox_title_extra; ?></h5> <div class="comments"> <?php echo $comment ?> </div> <div class="comments_form"> <?php echo $comment_form_html?> </div> </div> <h1>Source links:</h1> <?php echo $show_source_link;?> <?php echo $show_head_source_link;?> <?php echo $show_galleryconfig_source_link;?> <?php echo $show_cform_source_link;?> <?php echo $show_cform_xml_link; ?> <?php echo $show_cform_saveddata_xml_link; ?> <?php echo $show_cform_flch_link; ?> <?php echo $show_rating_php_link;?> <?php echo $show_rating_xml_link;?> <?php echo $show_theselinks1_source_link;?> </div> </body> </html> Thanks so much for taking the time to read this and for any help you might give me !! Alice Link to comment https://forums.phpfreaks.com/topic/194353-please-im-going-mad-what-is-the-probably-very-simple-solution-to-my-code/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.