lovesuckstudio Posted October 1, 2010 Share Posted October 1, 2010 <?php session_start(); if (isset($_SESSION['MM_Username'])){ ?> <?php require_once('../Connections/spr.php'); ?> <?php require_once('spr.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_rate")) { //to here from line 152 $stringtoken = $stringtoken.$str; /* Use tab and newline as tokenizing characters as well */ $token = strtok($stringtoken,"/"); while ($token !== false) { //$in = $token; echo "$token<br />"; mysql_select_db($database_spr, $spr); $Result1 = mysql_query($token, $spr) or die(mysql_error()); // echo "Word=$tok<br />"; $token = strtok("/"); } } mysql_select_db($database_spr, $spr); $query_display_all = "SELECT * FROM staff WHERE Staff_ID != ".$_SESSION['MM_Username']; $display_all = mysql_query($query_display_all, $spr) or die(mysql_error()); $row_display_all = mysql_fetch_assoc($display_all); $totalRows_display_all = mysql_num_rows($display_all); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #33FF66; } .style1 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style></head> <body> <table width="985" border="0" align="left"> <form action="" method="POST" name="form_rate" class="style1" id="form1" > <tr> <th width="213" scope="col">Staff ID</th> <th width="238" scope="col">Staff Name</th> <th width="57" scope="col"> </th> <th width="64" scope="col"> </th> <th width="55" scope="col">Rate</th> <th width="51" scope="col"> </th> <th width="55" scope="col"> </th> <th width="218" scope="col">Comment/Remarks</th> </tr> <?php //loop starts here $i=1; $str = " "; $hidden_staff_voted_id_ = " "; do { ?> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><div align="center"><?php echo $row_display_all['Staff_ID']; ?></div></td> <td><div align="center"><?php echo $row_display_all['Staff_Name']; ?></div></td> <?php $rate = "Radio_".$row_display_all['Staff_ID']?> <?php $staff_voted_id = $row_display_all['Staff_ID']; ?> <?php // $staff_vote_id = $_POST['MM_Username']; ?> <td> <input type="radio" name="<?php echo $rate ?>" id="Rate_1" value=1 />1 </td> <td> <input type="radio" name="<?php echo $rate ?>" id="Rate_2" value=2 />2 </td> <td> <input type="radio" name="<?php echo $rate ?>" id="Rate_3" value=3 /> 3 </td> <td> <input type="radio" name="<?php echo $rate ?>" id="Rate_4" value=4 /> 4 </td> <td> <input type="radio" name="<?php echo $rate ?>" id="Rate_5" value=5 /> 5 </td> <td><input type="text" name="comment" id="comment" /></td> </tr> <tr> <td><input name="hidden_Staff_Vote_ID" type="hidden" id="hidden_Staff_Vote_ID" value="<?php echo $_SESSION['MM_Username'] ?>" /> </td> <td> <input name="hidden_Rate" type="hidden" id="hidden_Rate" value="<?php echo $_POST[$rate]; ?>" /></td> <td><input name="hidden_Staff_Voted_ID" type="hidden" id="hidden_Staff_Voted_ID" value="<?php echo $staff_voted_id ?>" /></td> <?php $hidden_staff_vote_id = $_POST["hidden_Staff_Vote_ID"]; $hidden_staff_voted_id = $_POST["hidden_Staff_Voted_ID"]; $hidden_rate = $_POST[$rate]; ?> <input type="text" name="hidden" id="hiddenField2" value ="<?php $_POST[$rate];?>"/> <?php $insertSQL = sprintf("INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (%s, %s, %s)", GetSQLValueString($_POST[$rate],"int"), GetSQLValueString($_POST['hidden_Staff_Vote_ID'],"int"), GetSQLValueString($staff_voted_id,"int")); //string tokenizer for SQL statement /*from here*/ $str = $str.$insertSQL."/";//how to get this string value to line 47 $hidden_staff_voted_id_ = $hidden_staff_voted_id_.$staff_voted_id; ?> <?php $i++; } while ($row_display_all = mysql_fetch_assoc($display_all)); ?> </td> <td></td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input type="text" name="textfield" id="textfield" value="<?php echo $hidden_staff_voted_id_ ?>" /> <input name="hidden_insertSQL" type="text" id="hidden_Rate_2" value="<?php echo $str ?>" /> </td> <td><input type="submit" name="Submit" id="Submit" value="Submit" /></td> <td><input type="reset" name="Reset" id="Reset" value="Clear All" /></td> <td> </td> <td> </td> <td> </td> <td><?php echo $token; ?> </td> </tr> <input type="hidden" name="MM_insert" value="form_rate" /> </form> </table> <p class="style1"> <input name="hiddenField" type="text" id="hiddenField" value="<?php echo $str ?>" /> </p> </body> </html> <?php mysql_free_result($display_all); //$stringT = $stringT.$string; ?> <?php } else { header ("Location: error.php"); } ?> My question is how to get the $str value from line 152 to line 48? thank you in advance guys Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/ Share on other sites More sharing options...
trq Posted October 1, 2010 Share Posted October 1, 2010 You cannot get a value from a variable that hasn't been defined yet. Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117789 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 I'm sorry, can u guide me? Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117793 Share on other sites More sharing options...
Pikachu2000 Posted October 1, 2010 Share Posted October 1, 2010 Guide you with with what? You can't use a variable's value before the variable is defined. Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117794 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 guide me for where i'm wrong. i cant see it. i think i have defined the $str = " "; when i clicked submit button, it appears at the textfield, but the sql statement in the $str doesnt appear at the $stringtoken. sorry if i'm asking a silly question. i'm very new in php. anyway thanks for the replies Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117797 Share on other sites More sharing options...
Pikachu2000 Posted October 1, 2010 Share Posted October 1, 2010 So let me get this straight. You don't need that value from line 152 to be available on line 48 until after the form has been submitted, or are you trying to get it before the form has been submitted? Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117799 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 guide me for where i'm wrong. i cant see it. i think i have defined the $str = " "; when i clicked submit button, it appears at the textfield, but the sql statement in the $str doesnt appear at the $stringtoken. sorry if i'm asking a silly question. i'm very new in php. anyway thanks for the replies &&I'm sorry, can u guide me? If you have an if statement with variables in it that are not defined, there is nothing for the if statement to compare. So as a normal human being situation you ask someone: could you give me a glass of water if A = B ? that other person obviously will ask ok, but what is A and what is B? since they are not defined. if ( $a==$b ){ give_glass_of_water(); } So how to fix this, we define A and B $a = 5; // $a is now assigned with the value of 5; $b = 4; // $b is now assigned with the value of 4; if ( $a==$b ){ // here we compare the value of A with B give_glass_of_water(); }else{ echo 'no water for you mister!'; } Hope this clears the defining part a bit. Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117800 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 So let me get this straight. You don't need that value from line 152 to be available on line 48 until after the form has been submitted, or are you trying to get it before the form has been submitted? i'm trying to get the value before the form has been submitted. but i just don't know how. i want when i clicked the submit button, the value get into the $stringtoken, then it will split into token and then run the sql. if there's any other idea, just say it. thanks guys . Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117801 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 My question is how to get the $str value from line 152 to line 48? thank you in advance guys You can't the script is read from top to bottom. Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117802 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 guide me for where i'm wrong. i cant see it. i think i have defined the $str = " "; when i clicked submit button, it appears at the textfield, but the sql statement in the $str doesnt appear at the $stringtoken. sorry if i'm asking a silly question. i'm very new in php. anyway thanks for the replies &&I'm sorry, can u guide me? If you have an if statement with variables in it that are not defined, there is nothing for the if statement to compare. So as a normal human being situation you ask someone: could you give me a glass of water if A = B ? that other person obviously will ask ok, but what is A and what is B? since they are not defined. if ( $a==$b ){ give_glass_of_water(); } So how to fix this, we define A and B $a = 5; // $a is now assigned with the value of 5; $b = 4; // $b is now assigned with the value of 4; if ( $a==$b ){ // here we compare the value of A with B give_glass_of_water(); }else{ echo 'no water for you mister!'; } Hope this clears the defining part a bit. thanks, now i get it clear Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117803 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 My question is how to get the $str value from line 152 to line 48? thank you in advance guys You can't the script is read from top to bottom. okay. is there any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117805 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 Sorry but could you maybe give the name of the variable you're mentioning, since the layout above doesn't have numbers in the side line. -edit oh nvm you gave it its $str. but please do give the lines number 48 and 152 since it makes thing much more clear Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117806 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 one more question, i cant get the value from line 152 to 48 cause the script is read from top to bottom, so i just try to post the value to other form in other page, but i cant get it too. how to get the value from "hidden_insertSQL" ? ive tried the echo, $_POST method but it just wont work. here is the code : <?php session_start(); if (isset($_SESSION['MM_Username'])){ //echo "<center>Selamat Datang, ".$_SESSION['MM_Username']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #33FF66; } .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000; } --> </style></head> <body> <table width="980" height="261" border="0"> <form name="form_submit_rate" method = "post" class = "style1" id = "form_submit_rate" action = "ratestaffsuccess.php"> <tr> <td width="301" height="95"> </td> <td width="663"><input type="text" name="hidden_SQL" id="hiddenField" value="<?php $_POST["hidden_insertSQL";?>" /></td> </tr> <tr> <td height="158"><div align="right"><img src="images/warning.png" width="128" height="128" /></div></td> <td class="style1"><p>Your evaluation has successfully submitted. Thank you.</p> <p><a href="form_login.php">Click here to login</a></p></td> </tr> </form> </table> </body> </html> <?php } else { header ("Location: error.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117807 Share on other sites More sharing options...
Pikachu2000 Posted October 1, 2010 Share Posted October 1, 2010 Actually, even if $a and $b are undefined, if($a == $b) will still return true, because they both evaluate to NULL. The problem with what you are trying to do is that you want to use an actual value before it's available. This should make sense. echo $a; // Will output nothing at this point, because it is as yet undefined. $a = 'This is a string value for the variable'; // $a now has a value echo $a; // Now it will output the string, because the value is assigned before it was used. Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117809 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 Sorry but could you maybe give the name of the variable you're mentioning, since the layout above doesn't have number in the side line. $str Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117810 Share on other sites More sharing options...
Pikachu2000 Posted October 1, 2010 Share Posted October 1, 2010 one more question, i cant get the value from line 152 to 48 cause the script is read from top to bottom, so i just try to post the value to other form in other page, but i cant get it too. how to get the value from "hidden_insertSQL" ? ive tried the echo, $_POST method but it just wont work. here is the code : Nothing in the $_POST array will have a value unless the form has been submitted. However, if you're trying to use the value after the form has been submitted, the syntax is off a little. Just make sure that is actually the right value for there, because the form field is named hidden_SQL, not hidden_insertSQL. // THIS <?php $_POST["hidden_insertSQL";?> // SHOULD BE THIS <?php echo $_POST['hidden_insertSQL';?> Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117812 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 Sorry but could you maybe give the name of the variable you're mentioning, since the layout above doesn't have numbers in the side line. -edit oh nevermind you gave it its $str. but please do give the lines number 48 and 152 since it makes thing much more clear //to here from line 152 $stringtoken = $stringtoken.$str; this is line 48 /*from here*/ $str = $str.$insertSQL."/";//how to get this string value to line 47 this is line 152 sorry i didnt find the button to edit the code. this is dreamweaver generated code. yeah its quite long to read. sorry guys Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117813 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 Ok what you need to do is either put the value of $str in a hidden field beneath the part where you're assigning it and retrieve it from a $_POST variable on another page or assign it's value to a session variable also beneath the assignment of $str. so you can do like: $str = $str.$insertSQL."/";//how to get this string value to line 47 $_SESSION['monkeys'] =$str; //so here you assign a session variable to be used when you refresh the page or submit etc. than on line 47 you first assign $str with the session var you just created: if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form_rate")) { //to here from line 152 $str = $_SESSION['monkeys']; // <----------------------here you assign $str with session var $stringtoken = $stringtoken.$str; //<-------------------so it can be used here Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117815 Share on other sites More sharing options...
lovesuckstudio Posted October 1, 2010 Author Share Posted October 1, 2010 Nothing in the $_POST array will have a value unless the form has been submitted. However, if you're trying to use the value after the form has been submitted, the syntax is off a little. Just make sure that is actually the right value for there, because the form field is named hidden_SQL, not hidden_insertSQL. // THIS <?php $_POST["hidden_insertSQL";?> // SHOULD BE THIS <?php echo $_POST['hidden_insertSQL';?> ive tried it before, but it doesnt retrieve the value after form is submitted. i got this : INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (NULL, NULL, 2345)/INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (NULL, NULL, 7890)/INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (NULL, NULL, 8355)/INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (NULL, NULL, 8910)/ instead of this : INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (4, 1234, 2345)/INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (3, 1234, 7890)/INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (2, 1234, 8355)/INSERT INTO vote (Rate, Staff_Vote_ID, Staff_Voted_ID) VALUES (1, 1234, 8910)/ it seems like the original value of the text field. Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117816 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 // THIS <?php $_POST["hidden_insertSQL";?> // SHOULD BE THIS <?php echo $_POST['hidden_insertSQL';?> Should be : <?php echo $_POST['hidden_insertSQL'];?> it was missing a ] Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117817 Share on other sites More sharing options...
Pikachu2000 Posted October 1, 2010 Share Posted October 1, 2010 Completely missed that. Too busy getting ready to go to sleep . . . Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117818 Share on other sites More sharing options...
fortnox007 Posted October 1, 2010 Share Posted October 1, 2010 Completely missed that. Too busy getting ready to go to sleep . . . hehe same here nighty night! Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117819 Share on other sites More sharing options...
DarkMantis Posted October 1, 2010 Share Posted October 1, 2010 Oops sorry. Didn't realise there was another page xDD Quote Link to comment https://forums.phpfreaks.com/topic/214872-how-to-get-variable-value-help-me-please/#findComment-1117973 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.