dmIllithid Posted May 26, 2007 Share Posted May 26, 2007 I am passing variables via a link address such as follows : content.php?page=$cat&&author=$author&&title=$title I am using urlencode to replace the whitespace in the links. I am also using a function to replace characters such as & with its w3c compliance version. (ie. &) The function is as follows: <?php function replace($string) { return preg_replace('|\&+|', '&', $string); } ?> The following is an example of how I am using the preg_replace and urlencode to populate the variables in the url. <?php function replace($string) { return preg_replace('|\&+|', '&', $string); } $a = "something"; $b = "something else"; $c = urlencode(replace($a)); $d = urlencode(replace($b)); $block = "<a href=\"view_page.php?cat=$c&id=$d\">link</a>"; echo $block; ?> This has been working fine, up until recently. Before, I only had 1 to 2 words that were getting passed through the link. I still have 1 to 2 words getting passed via the link, but now I have words containing the '&' symbol, hence the use of the preg_replace to comply with w3c. The variables are not hard-coded in my scripts, but are being pulled from a database. So when variable $a is equal to 'something', it works. But if variable $a is equal to 'something & something' it doesn't work. The contents of the variable are not passed. I recently included some debugging into my scripts to see where the error was. The following are the results of the debugging while passing variables that contain the '&' symbol which are pulled from the database. <?php echo "$author<br />$title<br />"; ?> The above results in the following : Lady Raven Ignatius The result should be Lady Raven & Doom Ignatius & Raven Again, if the arguments being passed DO NOT have the '&' symbol it works. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/ Share on other sites More sharing options...
chronister Posted May 26, 2007 Share Posted May 26, 2007 <?php $x='Lady Raven & Doom'; $x=urlencode($x); ?> <br /><br /> <a href="<?=$_SERVER['PHP_SELF'] ?>?x=<?=$x ?>">Click On Me </a> <br /><br /> <?=$_GET['x'] ?> This returns Lady Raven & Doom Drop the str_replace function. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262217 Share on other sites More sharing options...
dmIllithid Posted May 26, 2007 Author Share Posted May 26, 2007 That works on the page that I am passing from, but not the page I am passing to. The page that is passing the argument is content_page.php. The code is as follows: <?php include('db_connect.php'); $cat = $_GET[a]; $page = (!isset($_GET['page']))? 1 : $_GET['page']; $max_results = 10; $from = (($page * $max_results) - $max_results); $result = ("SELECT id FROM $cat"); $total_results = mysql_num_rows($result); $total_pages = ceil($total_results / $max_results); $pagination = ''; for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i) { $pagination .= "[$i]"; } else { $pagination .= "<a href=\"$cat.php?page=$i\">[$i]</a> "; } } $sql = ("SELECT * FROM $cat WHERE `show`='0' ORDER BY author ASC LIMIT $from, $max_results"); $sql_res = mysql_query($sql, $conn); if($cat == poem) { $head = 'Poetry'; } else if ($cat == sstory) { $head = 'Short Story'; } else { $head = 'Story'; } echo("<div class=\"af\">$head</div>\n<br />\n"); function replace($string) { return preg_replace('|\&+|', '&', $string); } while ($item = mysql_fetch_array($sql_res)) { $title = urlencode($item[title]); $author = urlencode($item[author]); $a = replace($item[title]); $b = replace($item[author]); //begin menu display block $block = "$b - <a href=\"javascript:popUp('content.php?page=$cat&&author=$author&&title=$title')\" title=\"Click to view\">$a</a><hr />"; //display the menu echo $block; } /* MYSQL DEBUGGING - Uncomment the following lines to debug this page. */ // echo "<br /><div style=\"font-variant:small-caps;background-color:white;color:black;\">Mysql debugging</div>"; // echo "<div style=\"background-color:white;color:black;\">Category : $cat<br />"; // echo "Page #$page<br />"; // echo "Mysql line start = $from<br />"; // echo "Total pages to display : $total_pages<br />"; // echo "$sql<br />"; // echo "</div><br />"; /* END MYSQL DEBUGGING */ echo "<div class=\"ag\">Pages : $pagination </div>"; mysql_free_result($result); mysql_free_result($sql_res); ?> The page receiving the arguments is actually content.php which includes the script to implement the arguments. The scripting for content.php is as follows: <?php require_once('lib/template.php'); $page = new Page('tpl/view_content.tpl'); $page->replace_tags(array( "content" => "inc/view_page.php" )); $page->output(); ?> The page containing the script is view_page.php. The coding is as follows: <?php include('db_connect.php'); $author = $_GET['author']; $title = $_GET['title']; $page = $_GET['page']; /* SECTION DEBUG */ // echo "$author<br />$title<br />$page<br />"; /* END DEBUGGING */ echo "<meta http-equiv=\"refresh\" content=\"5;URL=$_SERVER[php_SELF]?page=$page&&author=$author&&title=$title\">"; $sql = "SELECT * FROM $page WHERE author='$author' AND title='$title'"; $res = mysql_query($sql) or die(mysql_error()); $rows = mysql_fetch_array($res); $content = stripslashes($rows[content]); $uid = $rows[id]; $sql2 = "SELECT uid, AVG(rate) FROM rating WHERE uid='$uid' AND cat='$page' GROUP BY uid"; $res2 = mysql_query($sql2) or die(mysql_error()); $a = mysql_fetch_array($res2); $a['AVG(rate)'] = number_format($a[1], 2, '.', ''); ?> <div> <table style="width:500px;text-wrap:none;"> <tr> <td colspan="3" style="font-variant:small-caps;"><b><?php echo $rows['title']; ?></b></td> </tr> <tr> <td colspan="3" width="500px" align="center"><?php echo $content; ?></td> </tr> <tr> <td style="font-variant:small-caps;">Date Submitted</td> <td style="font-variant:small-caps;">Author</td> <td style="font-variant:small-caps;">Rating</td> </tr> <tr> <td><?php echo $rows['sdate']; ?></td> <td><?php echo $rows['author']; ?></td> <td><a href="javascript:popUp('inc/rate.php?cat=<?php echo $page; ?>&&uid=<?php echo $uid; ?>')" title="Click to rate"><?php echo $a['AVG(rate)']; ?></a> of 5 stars</td> </tr> </table> </div> You can see that I dropped the str_replace from the variables being passed, but the page receiving still isn't receiving the entire data to be passed. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262222 Share on other sites More sharing options...
chronister Posted May 26, 2007 Share Posted May 26, 2007 I suggest getting rid of the preg_replace chunk. If you simply use the urlencode, it will make any variables transferred via the url be setup like so this+is+a+variable+passed+in+the+URL+&+should+not+break+your+script Try getting rid of your replace statement and let the built in functions do what they are designed to do. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262300 Share on other sites More sharing options...
dmIllithid Posted May 27, 2007 Author Share Posted May 27, 2007 content_page.php page is the page that shows the user the author and the title so that they know, when they click the on the link, what poem/short story/story they will be seeing on the next page. On this page, I have 2 sets of variables for the same values. <?php $title = urlencode($item[title]); $author = urlencode($item[author]); ?> *************************** The variables above the the only variables getting passed throught the link. The variables below are shown on the page itself. *************************** <?php $a = replace($item[title]); $b = replace($item[author]); ?> *************************** If I remove the str_replace function then what the user sees is the following: Lady+Raven+%26+Doom - Ignatius+%26+Raven If I leave the second set of variables in with the str_replace function they see : Lady Raven & Doom - Ignatius & Raven I don't think that my coding on content_page.php is the problem. I honestly think it is on view_page.php. I need the passed variables to match what is in the database. Right now, I am passing "javascript:popUp('content.php?page=sstory&&author=Lady+Raven+%26+Doom&&title=Ignatius+%26+Raven')" from content_page.php to view_page.php. Perhaps I should be using urldecode() on view_page.php to decipher what is really there? Because right now, the variables passed DO NOT match the data in the database. ** EDIT ** I tried urldecode after posting this and it doesn't fix the problem either. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262392 Share on other sites More sharing options...
MadTechie Posted May 27, 2007 Share Posted May 27, 2007 have you tried rawurldecode ? can you post some data from the database so we can see if/how its encoded Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262405 Share on other sites More sharing options...
dmIllithid Posted May 27, 2007 Author Share Posted May 27, 2007 The following is a dump of the table containing the sql in question. -- -- Table structure for table `sstory` -- CREATE TABLE `sstory` ( `id` int(4) NOT NULL auto_increment, `content` text NOT NULL, `title` varchar(65) NOT NULL default '', `sdate` date NOT NULL default '0000-00-00', `author` varchar(65) NOT NULL default '', `rating` int(5) NOT NULL default '0', `show` int(2) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `sstory` -- INSERT INTO `sstory` VALUES (1, '<pre>Before we met, you showed me your diary.\r\n\r\nI must confess that I am still confused by this sequence of\r\nevents, as, I imagine, you must be confused by my decision to\r\nleave your life so suddenly. I''ve gone over everything in my head\r\ntime and time again and I can''t shake the feeling that, somehow, \r\neverything got mixed up. Though this may seem a flimsy reason to \r\nyou, it is reason enough for me. I don''t understand, so I''m going \r\nto leave.\r\n\r\nBefore we met, you showed me your diary and then we were \r\nhaving sex on the wooden floor of your living room. I still \r\nremember the way the plants filtered the sunlight and the sound \r\nof the tea kettle building up steam. Then our son was at the foot \r\nof the bed, asking me where you''d gone.\r\n\r\n"I don''t know," I told him, "I expect she''ll be back soon."\r\n\r\nToday I went into your study and found that you''d converted it \r\ninto a gallery. The first photo of every roll of film we''d ever had \r\ndeveloped was there, somewhere. I found that I could date every \r\none, even the ones that hadn''t happened yet. They seemed to go \r\non forever, a jumbled mess of happy memories, each one partially \r\nobscured by blinding white light. I knocked over a jar full of tacks \r\nbut when I went to pick them up I was overcome with vertigo \r\nand I had to leave.\r\n\r\nWe were making desperate love in your basement when you told \r\nme about spacetime. You said that the future is just as real as \r\nthe past. You told me that just because you aren''t there yet \r\ndoesn''t mean it isn''t real. You said it was like Baghdad still being \r\nreal when you''re in London. You talked about personal time and \r\nlight cones and folding space and I didn''t understand anything \r\nexcept the way that your breasts moved and the way your breath \r\nmisted in the cold. Then we were on a roller coaster and you were \r\nscreaming and you said, "This is what it''s going to be like all the \r\ntime." A balloon seller lost hold of his wares and they floated \r\nmajestically into the sky. It was beautiful.\r\n\r\nAfter you introduced yourself, we resumed our date and I asked \r\nyou again why you''d chosen a drive-in. You told me that you had \r\na special soft spot in your heart for B-movies. You said that there \r\nwas something endearing about the earnestness of it all. You said \r\nthat they called out to our imaginations in a way that big budget \r\nfilms can no longer achieve. You said that all science fiction - no \r\nmatter how dismal - was optimistic in that it assumed that there \r\nwould be a future at all. We were in a board room and you were \r\nexplaining to the assembled group of investors about the Machine. \r\nThey were smiling and nodding. They didn''t really understand but \r\nexperts had told them that your idea showed promise and, after \r\nall, a war was on. The coffee tasted terrible and I kept fidgeting in \r\nmy seat. You were radiant. No one thought to ask what would \r\nhappen if the Machine broke.\r\n\r\nToday, I watched an egg assemble itself on the kitchen floor. It \r\nmade a strange popping noise as the last bit of eggshell attached \r\nitself. It flew into the air up and up and then came to rest on the \r\ncounter. A helicopter roared overhead and our son came in and \r\ntold me he was scared. I didn''t know what to tell him. The war \r\nhas begun and no one can say how or when it will end.\r\n\r\nI remember your reaction when you read this letter. I remember \r\nhow the last line, where I say "we weren''t meant to live like this," \r\nbrought a tear to your eye and you turned to our son and tried to \r\nexplain to him that I was gone. But how could you explain? What \r\ndoes ''gone'' mean to a child his age? Then we were lying together \r\nunder the stars and when the first fireworks went off, you leaned \r\nover and kissed me for the first time. You tasted like popcorn. I \r\ncan''t blame you for choosing a new husband.\r\n\r\nWhen you finally came back, you were younger. That was the \r\nhardest for both of us, I think. We didn''t share the same memories \r\nanymore. You held me and told me that it would be alright, that \r\nyou had hardly changed but I think that we both know now that that \r\nwasn''t true at all. Time changed people. That''s how it worked.\r\n\r\nToday, I went down to the basement and stared at the Machine. I \r\ncan still remember the day you turn it on. You''ll stand in front of a \r\ncrowd of reporters with our son and your new husband at your \r\nside and you''ll give your speech about the tyranny of time and \r\ndeath and the triumph of science and about setting us free. But \r\ninside, you''ll be thinking, "I wish he had been here to see this." I \r\nknow this because, before we met, you showed me your diary and \r\nyou wrote about this day. How could you not? It was the most \r\nimportant day of your life. You saved us from the enemy and \r\nended the war. You asked me to stop it. There''s nothing I can do. \r\nThe future is just as real as the past. There is no before or after \r\nanymore. Because of you, there never was.\r\n\r\nWe weren''t meant to live like this.</pre>', 'Time, Again', '2007-05-24', 'Tim Maly', 0, 0); INSERT INTO `sstory` VALUES (2, '<pre>Servants led the Chosen to their rooms. Raven had discovered while the planning went on that she was undeniable tired. She smiled as she thought of the rest she would catch up on during the night. One of the servants opened her door for her and she ushered Xavier, her canine friend, in first. She stood in the middle of the room for a moment to take in her surroundings. The room was quite beautiful, but she would''ve chosen the soft grass over the plushness of the room any day. She heard Ignatius'' voice dismissing the servant from her room and was startled slightly by it. She turned and looked at him and smiled warmly. Over the last few months the young girl and the human druid had become very close. They toyed with the idea of becoming more than simple friends, but Ignatius was reserved in that aspect. Now, he looked at her and spoke "So it seems that our children need to be tended to. Shall we do this together?" Indeed they did need attention. The children he referred to were the brother and sister wolf pups they had rescued. The earlier battle had left their fur crusted with blood. Raven said nothing, only nodded at the druid.\r\n\r\nIgnatius found some cloth and tore it into strips for the purpose of cleaning their wounds. He used the warm water from the bath that had been drawn in the young Ranger''s room. Ignatius wiped them down, spending extra time with Sierra, who had earned the most grievous wounds. Taking his time, he talked to Raven without looking at her. "I sincerely doubt we could get them into a tub but this should serve to keep their wounds clean."\r\n\r\nShe still said nothing as they washed the blood from the pups fur. She was in thought..and deep. Once they had finished with the task, Ignatius sighed as he realized that he had once again found himself alone with the woman that he had fallen in love with. Raven stood and smiled at the druid. She could only think of how sweet he was as she watched his gentleness with Sierra.\r\n\r\nRealizing that they were again to do battle, the druid was unsure that he should press his luck with the Ranger. He took her hand in his gently and walked to her. He kissed her deeply. The two had shared kisses before, but Raven knew that this one was different from the rest. Ignatius poured himself into this one, she returned his fervor. She wrapped her arms around the Druid''s neck. When the kiss was finished, the ranger wasn''t quick to let go. She left her arms around his neck and lay her head on his shoulder. She wanted to just stand there and forget that anything was wrong. Forget that they were one of these so-called Chosen and just go on about their lives. She didn''t want to let go and that much was obvious to the druid. She kissed his cheek tenderly and whispered in his ear. "Stay with me, my druid."\r\n\r\nInitially, Ignatius resisted the offer to stay, for he was not certain of how private the palace really was. Plus, as dirty as he was, he did not want to share his companion''s bath water. After kissing her again, he said "Raven, I''m not sure about this..place. And I am dirty. I will bathe, clean up and then I shall return to you."\r\n\r\nShe smiled innocently and nodded her understanding. Ignatius held her in his arms for a few moments. He then left her room for his own, and bathed with his wolf, until his own tub was caked in dirt and canine hair. Shrugging, Ignatius knew that he was not meant to live in such circumstances, and decided that he would go to Raven''s room for certain. There he would spend the night.\r\n\r\nRaven, too, was dirty. She relaxed in her bath for only a few moments. She tried to wash the last of the sea from herself. She dressed in the one garment of clothing she loved best from sleeping. It wasn''t as nice as the Baroness in the next room probably had, but it would have to do. She looked in the mirror, at the garment hanging from her shoulders and thought for a moment of asking Lilorianda for pointers to make her looks a little more feminine.\r\n\r\nThe druid knocked on her door. He appeared before her, cleaner than he had been in months. Shrugging, the druid stated, "The soap made me sneeze, so I didn''t use a whole lot of it." Raven chuckled. "So how do we look?" The ranger grinned widely as she looked upon the man before her and the wolf he had become so attached to. "Handsome," she said as she touched his face. She then knelt to Sierra, "and quite beautiful." The druid smiled and took her in his arms right at the door. This time he drew her close and kissed her passionately for a long moment. Raven sighed deeply as she had decided to stop fighting her own urges. The young girl leaned into the man that held her. She felt safer than she had since living her woodland home. As he could feel his own body respond to her''s, Ignatius leaned away from the kiss. "I shall not leave you, my Wildflower. For I am your''s."\r\n\r\nLocked in a deep embrace, he moved his friend towards the bed and collapsed with her onto the soft, plush cushions. The two laughed and carried on for a bit. The druid could not remember a time where he felt so happy, so complete, even if it was for just a few precious moments. Raven was lost in the moment with the druid that had gone from stranger, to best friend, to fellow student and now it seemed he would become her lover. The druid smiled at the young girl that laid beside him in the bed. He stood and found the candles in the room and began blowing out the light. Raven sat up and watched him move across the room. "Leave one lit," she said innocently to him. The man did so and made his way back to her in the bed. He laid her back onto the bed. She wrapped her arms around his neck once again. Their lips found each other easily even in the dim light of the one candle. Raven''s face was lit just enough for him to see the look in her eyes. Neither of them had been in this situation before, but somehow both knew exactly what the other wanted. The two rolled about almost playfully in the silky sheets of the palace room. Both trying to be as quiet as possible, so that none could interfere in their moment. Ignatius fetl the arousal of his body as his lips met Raven''s yet again. Excited, he began to undress her between the kisses and movement between the two. Smiling, he said "I have spent many nights dreaming of this moment, Raven. Dreaming of being with you."\r\n\r\nRaven found herself sitting atop the druid. She looked at him with intense coal eyes now. He ebon-colored hair was loose and wild. It hung past the middle of her back. Once of the shoulder straps of her loose white gown hung off her darkly tanned shoulder. The druid couldn''t help but to wonder why she looked at him like she did. Raven knew exactly why, though. She was thinking of the battle to come and was memorizing everything about him. She wanted to remember him just like this, in case something did happen to one of them. With thoughts rushing through her mind, one stuck out for the ranger above all else. ''Stop wasting time and become one with him.'' Her innocent smile widened a bit. She leaned over the druid an placed her lips on his forehead. She proceeded to move her lips over every inch of him, not wanting to miss a spot. Her body moved with his as he reacted to her touch. The druid shuddered as he felt Raven''s kisses across his body. He moaned in anticipation as his arousal became so fierce it was almost painful. He knew that he would not be able to stop, and began to return her kisses. With a gentle touch, he explored her soft, tanned skin. With his mouth, he kissed her on the neck, moving to the angel''s hair upon the side of her neck. With his hands, he cupped her breasts, felt her hips, held the small of her smack and could feel the desire to be inside of her.\r\n\r\nRaven needed him in every way she could ever need anyone. She knew that it was a dangerous thing to love someone so much, but she was tired of fighting with herself. She had decided to give him her all. She could only hope that he would do the same in return. She knew that after this night, they would both be forever changed. She raised back up to look upon his face, to make sure that what she was doing was okay. She trembled with the thought of her giving herself to him. It was not fear, however, only excitement. She took his hands and pulled him to a sitting position, while she remained in his lap now. She removed his shirt carefully, as she didn''t know how well he had been healed from the previous battle. She ran her fingers through his hair and kissed him as passionately as he had done to her earlier that evening. She pressed her body to his. The heat coming from her was intense. She cupped her hands on his face and pulled away from the kiss for only a moment. She looked deep into his soul it seemed. "This is your last chance. Are you sure this is what you want?" Her voice was soft, quiet and terribly seductive. For the first time, Ignatius heard the seriousness within her tone. She had been serious before, but never with him.\r\n\r\nRealizing her seriousness, that this was really happening, Ignatius breathed heavily. "Yes, I want this. I want you, Raven." Looking into her eyes, he matched her serious expression and guided himself into her. As she sat atop him, the ecstasy of her hips meeting his was greeted by a low moan from the druid. He felt as if the explosion from a thousand suns was beginning to build, slowly, as the rhythm of the two nature lovers began in the act of consummation. Raven bit her own lip in an attempt at keeping their silence. She wanted to tell him a thousand things, but could not find a voice to speak.\r\n\r\nAs they began their fierce lovemaking, Ignatius imagined that nothing else existed. Nothing was worth noticing for those moments, except the beautiful woman that was atop him. Raven closed her eyes and tossed her head back . She wanted to use the sense that she had been working on, now. The ranger wanted to take the druid into her very being in every way that she could. She opened her bold eyes and could not help but to look into his. Looking into her eyes, he could feel himself falling into them, falling ever deeper into love with this creature of the forest.\r\n\r\nThe next morning, the two awoke at the same time, both sweating from their dreams. Raven gasped aloud at the thought of their patron druid being harmed. Ignatius comforted her as best he could. He told her that he had the very same dream. Raven stood up, without a shred of clothing on her dark body, and stretched. She peaked out of the curtain at the window to make sure that she wouldn''t be seen. The sun was a most welcome sight to her eyes. He anguish form the dream sson was gone. She pulled the curtains wide open once she was sure that she wouldn''t be spied on by any passer-bys. She stood a few feet from the window, allowing the sun to touch every inch of her. She breathed deep and smiled. She then looked to Ignatius. "Come on, sleepyhead. I hope that they don''t send servants to wake us and find you not in your bed." The ranger winked and grinned at the druid. She took to donning her armor and clothing. Her weapons were put in all the right places, as well. She watched the druid with a playful look playing about her features.\r\n\r\nShe stood in front of the mirror, finally and the image from her dream came back to her. She shuddered visibly. She pulled her long black hair up into a pony-tail. She caught a glimpse of her onyx earring and smiled. She knew that somehow Killendroh was watching her at that moment. This gave the young ranger a revived vigor that she had felt she was losing over the last few months. She smiled and straightened her posture. It was time that she put her full effort into their quest. She would have to in order to stay alive. She thought of Ignatius and the two of them soaring the skies.\r\n\r\nShe turned to see if he was ready to join the others downstairs. "Shall we?" She went and stood next to the door until he was ready. Ignatius finished and walked over to the door and to Raven. She noticed the look in his eyes had changed slightly since their night of passion. It had become more..adoring somehow. The young woman wrapped him up in her arms one last time before they joined the others. She kissed him gently. Smiling, she looked upon the face of the man that had taken the one thing from her that no other could..her heart. She once again found herself wanting to say a thousand things, but decided that it was best left unsaid for now. Afterall, actions did speak louder than words and she was sure that she had screamed out by her actions the night before, time and time again. </pre>', 'Ignatius & Raven', '2007-05-26', 'Lady Raven & Doom', 0, 0); Currently there is 2 ways that data can be inserted into the database. The first way is by user submission, the second is by admin submission. The following is the code for the admin submission: <?php /* DEFINE VARIABLES */ include('db_connect.php'); if((!isset($_POST['content'])) || (!isset($_POST['title'])) || (!isset($_POST['author']))) { ?> <table> <tr> <td> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table> <tr> <td>Author</td> <td><input type="text" name="author" /></td> </tr> <tr> <td>Title</td> <td><input type="text" name="title" /></td> </tr> <tr> <td>Content</td> <td><textarea rows="10" cols="60" name="content"></textarea> </tr> </table> <br /> <input type="submit" value="Post" /> </form> </td> </tr> </table> <?php } else { $content = "<pre>" .addslashes($_POST[content]). "</pre>"; $title = $_POST['title']; $author = $_POST['author']; $sql="INSERT INTO `sstory` (content, title, sdate, author, rating) VALUES('$content', '$title', NOW(), '$author', '0')"; if (!mysql_query($sql, $conn)) { die('Error: ' .mysql_error()); } echo "Record added."; echo "<meta http-equiv='refresh' content='3;url=admin/inc/edit.php'>"; } ?> The following the code for user submission: <?php /* DEFINE VARIABLES */ include('db_connect.php'); if((!isset($_POST['cat'])) || (!isset($_POST['author'])) || (!isset($_POST['title'])) || (!isset($_POST['content']))) { ?> <div align="center" style="font-size:x-large;font-variant:small-caps;">Submissions page!</div> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table align="center"> <tr> <td> <input type="radio" value="poem" name="cat" />Poetry<br /> <input type="radio" value="sstory" name="cat" />Short Stories<br /> <input type="radio" value="story" name="cat" />Stories<br /> </td> <td> <table cellpadding="3"> <tr> <td> Author </td> <td> <input type="text" name="author" /> </td> </tr> <tr> <td> Title </td> <td> <input type="text" name="title" /> </td> </tr> <tr> <td> Content </td> <td> <textarea rows="5" cols="30" name="content"></textarea> </td> </tr> </table> </td> </tr> <tr> <td colspan="2"> <input type="submit" name="Submit" value="Submit" /> </td> </tr> </table> </form> <?php } else { $nContent = "<pre>" .addslashes($_POST[content]). "</pre>"; $sql = "INSERT INTO $_POST[cat] (`content`, `title`, `sdate`, `author`, `show`) VALUES('$nContent', '$_POST[title]', NOW(), '$_POST[author]', '1')"; if (!mysql_query($sql, $conn)) { die('Error: ' .mysql_error()); } echo "Thank you! Your submission will be reviewed for posting.<br />You will now be re-directed to the index page."; echo "<meta http-equiv='refresh' content='5;url=index.php'>"; } ?> And no, I haven't tried to use rawurlencode(). Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262408 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 "javascript:popUp('content.php?page=sstory&&author=Lady+Raven+%26+Doom&&title=Ignatius+%26+Raven')" Are the && pieces a typo, that should be content.php?page=sstory&author=Lady+Raven+&+Doom&title=Ignatius+&+Raven **edit** Maybe I am missing something, but That is the first thing I see that is not correct, and I don't see a $_GET[] where those vars are being received on the page Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262418 Share on other sites More sharing options...
dmIllithid Posted May 27, 2007 Author Share Posted May 27, 2007 I have played with the rawurlencode(), urlencode() and the str_replace functions and tested them all to see what is being passed. With each function my link contains the entire author and title (ie. Author = Lady Raven & Doom, Title = Raven & Ignatius). However, the full contents of the variable are not being passed to the next page. I am only getting partial info from the variables (ie. Author = Lady Raven, Title = Raven). The second half of the argument (ie. "& Doom" from the author, "& Ignatius" from the title) is getting dropped from 1 page to the next. The double & in the link was no typo, however you are the second person on this forum to ask about that, so I took the second & symbol out. Uploaded the changes and it still isn't passing the arguments correctly. Review the pages of code I have posted thus far. The $_GET[] is in the page, at the top of view_page.php. I will post it again incase you missed it. <?php include('db_connect.php'); $author = $_GET['author']; $title = $_GET['title']; $page = $_GET['page']; /* SECTION DEBUG */ echo "$author<br />$title<br />$page<br />"; echo "<meta http-equiv=\"refresh\" content=\"5;URL=$_SERVER[php_SELF]?page=$page&author=$author&title=$title\">"; $sql = "SELECT * FROM $page WHERE author='$author' AND title='$title'"; $res = mysql_query($sql) or die(mysql_error()); $rows = mysql_fetch_array($res); $content = stripslashes($rows[content]); $uid = $rows[id]; $sql2 = "SELECT uid, AVG(rate) FROM rating WHERE uid='$uid' AND cat='$page' GROUP BY uid"; $res2 = mysql_query($sql2) or die(mysql_error()); $a = mysql_fetch_array($res2); $a['AVG(rate)'] = number_format($a[1], 2, '.', ''); ?> <div> <table style="width:500px;text-wrap:none;"> <tr> <td colspan="3" style="font-variant:small-caps;"><b><?php echo $rows['title']; ?></b></td> </tr> <tr> <td colspan="3" width="500px" align="center"><?php echo $content; ?></td> </tr> <tr> <td style="font-variant:small-caps;">Date Submitted</td> <td style="font-variant:small-caps;">Author</td> <td style="font-variant:small-caps;">Rating</td> </tr> <tr> <td><?php echo $rows['sdate']; ?></td> <td><?php echo $rows['author']; ?></td> <td><a href="javascript:popUp('inc/rate.php?cat=<?php echo $page; ?>&uid=<?php echo $uid; ?>')" title="Click to rate"><?php echo $a['AVG(rate)']; ?></a> of 5 stars</td> </tr> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262421 Share on other sites More sharing options...
dmIllithid Posted May 27, 2007 Author Share Posted May 27, 2007 The following is a link to the page that has the variables and will be passing the arguments to the view_page.php : http://exceptionalgamers.org/WoW/swap.php?a=sstory There are currently 2 short stories on the page. I have enabled the debugging on both the content_page.php and the view_page.php., so you will be able to see the arguments to be passed and what is actually getting to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262424 Share on other sites More sharing options...
chronister Posted May 27, 2007 Share Posted May 27, 2007 Ok, so I see that it is displaying correctly w/o the encoding. However when I copy link location this is what I get javascript:popUp('content.php?page=sstory&author=Lady+Raven+%26+Doom&title=Ignatius+%26+Raven') Maybe try using urldecode to change the %26 back to the & symbol on the next page. That is all I got for now. It is late and I am going to bed. If you are still having problems, post back and I will see what I can do. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262455 Share on other sites More sharing options...
dmIllithid Posted May 27, 2007 Author Share Posted May 27, 2007 I have implemented the urldecode() in the page receiving the variables and it doesn't fix the issue. the view_page.php is still only getting part of the argument. It seems as though the '&' symbol is the problem going from page to page, as the argument stops when it gets to the '&' symbol cutting it and second half of the variable off. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262472 Share on other sites More sharing options...
trq Posted May 27, 2007 Share Posted May 27, 2007 It seems as though the '&' symbol is the problem going from page to page, as the argument stops when it gets to the '&' symbol cutting it and second half of the variable off Of course it does. The & symbol delimits the next variable/key pair in http. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262480 Share on other sites More sharing options...
dmIllithid Posted May 27, 2007 Author Share Posted May 27, 2007 Problem solved. Thank you thorpe for verifying what I finally realized at the end. The end result is that I did need to use the str_replace, but instead of using the & symbol, I need to change it, on the page before passing the variables, to something that would not delimit the argument. Then use the str_replace function to change it back to its original format so it could be used when accessing the database. Quote Link to comment https://forums.phpfreaks.com/topic/53076-solved-problem-getting-info-from-db-while-passing-variables-via-address/#findComment-262489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.