943,022 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 23
  • PHP RSS
Sep 9th, 2010
0

Variable Mysteriously Stops Echoing

Expand Post »
Hi,

I'm working on a page that GETs a value that is passed in the URL. This variable echos correctly up until I try echoing it inside an if statment where it needs to be.

The variable is called $siteid. Inside my if statement I have a query that runs WHERE id='$siteid'

Inside this if statement it won't echo out. It is the weirdest thing. I tried to hardcode the siteid as 95, to test it, and the query updated my database as it should. However, leaving it as the variable it will not work. Any help solving this mystery that I've been banging my head over for hours would be greatly appreciated!

My variable echos correctly up until the line that says:
// $siteid will Echo up until here. After this point it stops working.

The query I am having issues with is after the line that says:
// Problem lies in this query.

My SQL Table:
id int(11) No
userid int(11) No
url varchar(2083) No
credits int(11) No 0
dailyviews int(11) No 0
todayviews int(11) No 0
totalviews int(11) No
active tinytext No
title varchar(50) No
confirmed tinytext No

And my code:
php Syntax (Toggle Plain Text)
  1. <?php
  2. session_start();
  3.  
  4. if (isset($_SESSION['username'])){
  5. $loginstatus = "logout";
  6.  
  7. $username = $_SESSION['username'];
  8.  
  9. include_once('inc/connect.php');
  10.  
  11. $siteid = $_GET['siteid'];
  12. $message = "messagebox";
  13. $success = "&nbsp;";
  14. $error = "&nbsp;";
  15.  
  16. $useridquery = "SELECT id FROM users WHERE username='$username'";
  17. $useridresult = mysql_query($useridquery);
  18. $useridrow = mysql_fetch_assoc($useridresult);
  19.  
  20. $userid = $useridrow['id'];
  21.  
  22. $result1 = mysql_query("SELECT * FROM websites WHERE `id`='$siteid' && userid='$userid'");
  23. $siterow1 = mysql_fetch_assoc($result1);
  24. $titledb = $siterow1['title'];
  25. $urldb = $siterow1['url'];
  26. $maxviewsdb = $siterow1['dailyviews'];
  27. $statusdb = $siterow1['active'];
  28.  
  29. $titlenew = $_POST['title'];
  30. $urlnew = $_POST['url'];
  31. $maxviewsnew = $_POST['maxviews'];
  32. $statusnew = $_POST['status'];
  33.  
  34. if($statusnew=="Active"){
  35. $statusnew = "yes";
  36. }
  37. else{
  38. $statusnew = "no";
  39. }
  40.  
  41. $editnewsite = $_POST['editnewsite'];
  42.  
  43. if($success!=""){
  44. $message = "";
  45. }
  46. else{
  47. $message = "messagesuccess";
  48. }
  49. // $siteid will Echo up until here. After this point it stops working.
  50. if($editnewsite){
  51. if($titlenew){
  52. if($urlnew){
  53. if($maxviewsnew){
  54.  
  55. function valid_url($urlnew)
  56. {
  57. return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $urlnew)) ? FALSE : TRUE;
  58. }
  59. if(valid_url($urlnew)){
  60.  
  61. //Check if URL is a Duplicate for current user
  62. $results = mysql_query("SELECT * FROM `websites` WHERE `userid`='$userid' AND `url`='$url'");
  63. $rows = mysql_num_rows($results);
  64.  
  65.  
  66. if ($rows<=0)
  67. {
  68. $siteidnew = $siteid;
  69. // Problem lies in this query.
  70. $update = "UPDATE `websites` SET `title`='$titlenew', `url`='$urlnew', `dailyviews`='$maxviewsnew', `active`='$statusnew' WHERE `id`='$siteid' && `userid`='$userid'";
  71. mysql_query($update);
  72.  
  73. $titledb = $titlenew;
  74. $urldb = $urlnew;
  75. $maxviewsdb = $maxviewsnew;
  76. $statusdb = $statusnew;
  77. echo $titledb;
  78. echo $urldb.$maxviewsdb.$statusdb."<br>".$siteid;
  79. // PROBLEM HERE
  80.  
  81.  
  82. exit();
  83.  
  84. }
  85. else{
  86. $error = "You have already submitted that site";
  87. $message = "messageerror";
  88. }
  89.  
  90. } // here
  91. else {
  92. $error = "Invalid URL";
  93. $message = "messageerror";
  94. }
  95. }
  96. else{
  97. $error = "Type in the Maximum Views you<br />want your site to get daily!";
  98. $message = "messageerror";
  99. }
  100. }
  101. else{
  102. $error = "Type in the Url of your website!";
  103. $message = "messageerror";
  104. }
  105. }
  106. else{
  107. $error = "Type in a Title for your site!";
  108. $message = "messageerror";
  109. }
  110. }
  111. }
  112. else{
  113. $loginstatus = "login";
  114. header("Location: index.php");
  115. }
  116. ?>
  117. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  118. <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
  119. <head>
  120. <meta name="description" content="Free Piano Sheet Music - Sheet Music Haven" />
  121. <meta name="keywords" content="Piano,Sheet,Music,Haven,Score,Piece,Top,Trade" />
  122. <meta name="author" content="Sheet Music Haven" />
  123. <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
  124. <title>Edit Sites - Sheet Music Haven</title>
  125. <link rel="stylesheet" type="text/css" href="styles/style.css" />
  126. <link rel="stylesheet" type="text/css" href="styles/editsites.css" />
  127. <script type="text/javascript">
  128. function make_blank()
  129. {
  130. if(document.login.username.value =="Username"){
  131. document.login.username.value ="";
  132. document.login.username.style.color ="#000000";
  133. }
  134. }
  135. function make_blank1()
  136. {
  137. if(document.login.password.value =="Password"){
  138. document.login.password.value ="";
  139. document.login.password.type ="password";
  140. document.login.password.style.color ="#000000";
  141. }
  142. }
  143. function undoBlank() {
  144. if(document.login.username.value == ""){
  145. document.login.username.value ="Username";
  146. document.login.username.style.color="#ccc";
  147. }
  148. }
  149. function undoBlankpass() {
  150. if(document.login.password.value == ""){
  151. document.login.password.value ="Username";
  152. document.login.password.style.color="#cccccc";
  153. }
  154. }
  155. function inputLimiter(e,allow) {
  156. var AllowableCharacters = '';
  157. if (allow == 'NumbersOnly'){AllowableCharacters='1234567890';}
  158. var k;
  159. k=document.all?parseInt(e.keyCode): parseInt(e.which);
  160. if (k!=13 && k!=8 && k!=0){
  161. if ((e.ctrlKey==false) && (e.altKey==false)) {
  162. return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
  163. } else {
  164. return true;
  165. }
  166. } else {
  167. return true;
  168. }
  169. }
  170. </script>
  171. </head>
  172. <body bgcolor="#343331">
  173.  
  174. <!-- Header -->
  175. <div id="header">
  176. <div id="headerleft"></div>
  177. <div id="headermiddle"><a href="index.php"><img src="img/logo.png"></a></div>
  178. <div id="headerright">
  179.  
  180.  
  181. <?php echo "<form name='login' action='inc/$loginstatus.php' method='POST'>";?>
  182. <div class="loginboxdiv" id="username">
  183. <input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();">
  184. </div>
  185. <div class="loginboxdiv" id="password">
  186. <input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();">
  187. </div>
  188. <div id="login">
  189. <?php echo "<input type='image' src='img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?>
  190. </div>
  191. </form>
  192. <div id="register">
  193. <a href="register.php"><img src="img/register.png"></a>
  194. </div>
  195. <div id="forgotpassword">
  196. <a href="resetpassword.php" class="forgot">Forgot Password?</a>
  197. </div>
  198. </div>
  199.  
  200. </div>
  201.  
  202. <!-- Content Top -->
  203. <div id="contenttop">
  204. <div id="links">
  205.  
  206. <table cols="7">
  207. <tr>
  208. <td align="center" valign="middle" width="100px" height="48px"><a href="index.php"><img src="img/home.png"></a></td>
  209. <td align="center" valign="middle" width="100px" height="48px"><a href="member.php"><img src="img/member.png"></a></td>
  210. <td align="center" valign="middle" width="100px" height="48px"><a href="addsheet.php"><img src="img/addsheet.png"></a></td>
  211. <td align="center" valign="middle" width="100px" height="48px"><a href="advertise.php"><img src="img/advertise1.png"></a></td>
  212. <td align="center" valign="middle" width="100px" height="48px"><a href="faq.php"><img src="img/faq.png"></a></td>
  213. <td align="center" valign="middle" width="100px" height="48px"><a href="terms.php"><img src="img/terms.png"></a></td>
  214. <td align="center" valign="middle" width="100px" height="48px"><a href="contact.php"><img src="img/contact.png"></a></td>
  215. </tr>
  216. </table>
  217. <!-- 92x30 -->
  218. </div>
  219. </div>
  220.  
  221. <!-- Content Middle -->
  222. <div id="contentmiddle">
  223. <div id="content">
  224.  
  225. <div id="headeditsites"></div>
  226.  
  227. <br />
  228. <div id="editsite">
  229. <form action="editsites.php" method="post" name="newsite">
  230. Title: <input type="text" name="title" value="<?php echo $titledb; ?>"><br />
  231. Url: <input type="text" name="url" value="<?php echo $urldb; ?>"><br />
  232. Max Views: <input type="text" maxlength="11" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" name="maxviews" value="<?php echo $maxviewsdb; ?>"><br />
  233. <select name="status"><option value='Active' name='active'>Active</option><option value='Passive' name='passive'>Passive</option></select><br /><br />
  234. <center><input type="submit" name="editnewsite" value="Edit Site"></center>
  235. </form>
  236.  
  237. </div>
  238. </div>
  239.  
  240. </div>
  241.  
  242. <!-- Content Bottom -->
  243. <div id="contentbottom">
  244.  
  245. </div>
  246.  
  247. </body>
  248. </html>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Smudly is offline Offline
41 posts
since Jul 2010
Sep 10th, 2010
0
Re: Variable Mysteriously Stops Echoing
It sounds like you are INITIALLY arriving at the page via editsites.php?siteid=95 , in which case line 11 works as expected. BUT your FORM does not "save" that siteid, so when you submit/POST the form, it is going to editsites.php, NOT to editsites.php?siteid=95.

So add the site id to your FORM's action:
PHP Syntax (Toggle Plain Text)
  1. <form action="editsites.php?siteid=<?php echo intval($_GET['siteid']);?>" method="post"...>
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007
Sep 10th, 2010
0
Re: Variable Mysteriously Stops Echoing
Or make it a hidden variable in the form (<input type=hidden...)
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Sep 10th, 2010
0
Re: Variable Mysteriously Stops Echoing
thanks very much! All fixed
Reputation Points: 10
Solved Threads: 0
Light Poster
Smudly is offline Offline
41 posts
since Jul 2010
Sep 10th, 2010
0
Re: Variable Mysteriously Stops Echoing
Glad to help!

PS: Don't forget to mark the thread as solved!
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC