Jump to content

How to get variable value. Help me please


lovesuckstudio

Recommended Posts

<?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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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");

}

?>

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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';?>

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

 

 

 

 

 

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.