Jump to content

Submit new values


Smudly

Recommended Posts

Hello, I've got a page that I've created that allows me to change multiple values in a row in my database. These values are all stored in a single row. I have input boxes for every one of the columns in my row. If a box is filled in, that value will be updated for that column in the row. This sounds like all I have to do is an Update query for the row, but it's becoming more complicated.  Take a look:

 

<?php

include_once('../inc/admin.php');
include_once('../inc/connect.php');

$varsquery = mysql_query("SELECT * FROM vars WHERE id='2'");
$row = mysql_fetch_array($varsquery);

$varsquery1 = mysql_query("SELECT * FROM vars WHERE id='1'");
$row1 = mysql_fetch_array($varsquery1);

$edit = $_GET['edit'];
$newvalue = "";

echo "
<html>
<head>
<title>Variables</title>
<style>
a:link{
text-decoration: none;
color: #519904;
}
a:visited{
text-decoration: none;
color: #519904;
}
a:hover{
text-decoration: none;
color: #4296ce;
}
#border{
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
";

echo "<div style='font-size: 28px; text-align: center;'>Variables</div><br />
<table align='center'>
<tr>
<th bgcolor='#cccccc'><a href='changevars.php?sort=number'>#</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=variable'>Variable</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=value'>Value</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=rate'>Rate</a></th>
<th bgcolor='#cccccc'><a href='changevars.php'>Change</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=default'>Default</a></th>
</tr><form action='changevars.php' method='POST'>";

$i = 1;
$color = 0;
while ($i < mysql_num_fields($varsquery)) {
    $meta = mysql_fetch_field($varsquery, $i);
    if (!$meta) {
        echo "No information available<br />\n";
    }

if ($color % 2){
$bgcolor = "#cccccc";
}
else{
	$bgcolor = "#ffffff";
}

	echo "<tr bgcolor='$bgcolor'><td align='center' width='20' bgcolor='#eeeeee' id='border'>$i</td>";
	echo "<td align='center' width='200' id='border'>$meta->name</td>";
	echo "<td align='center' width='200' id='border'>" .$row[$i]. "</td>";
	echo "<td align='center' width='100' id='border'>0</td>";
	echo "<td align='center' width='200' id='border'><input type='text' name='$meta->name'></td>";
	echo "<td align='center' width='200' id='border' bgcolor='#77ff77'>" .$row1[$i]. "</td>";
	echo "</tr>";
	$newvalue .= $_GET[$meta->name];
    $i++;
$color++;
}
echo "<tr><td colspan='6' align='center'><input type='submit' name='edit' value='Edit'> <input type='reset' name='reset' value='Reset'></td></tr></form>"; 
echo "</table>";

if ($edit){

// Update new value
$sql = mysql_query("UPDATE vars SET `credits500`='$newvalue[0]' WHERE id='2'");

}

// Footer
echo "
</body>
</html>
";

?>

Link to comment
Share on other sites

You should really get in the habit of separating your query strings from the query execution. Combining them makes debugging more difficult, as you can see. Using mysql_error() during development is a good idea, on a live site, you'd want to echo a generic "Sorry, there was a problem, try later" error message, and log the mysql_error() rather than display it. See if this now returns any errors.

 

// Update new value
$query = "UPDATE vars SET `credits500`=$newvalue[0] WHERE id=2"  // removed quotes, assuming integer data is expected
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());

Link to comment
Share on other sites

OK, so echo the query, and make sure the value of $newvalue[0] is what you'd expect it to be.

 

$query = "UPDATE vars SET `credits500`=$newvalue[0] WHERE id=2"  // removed quotes, assuming integer data is expected
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());
echo "<br />$query<br />";

Link to comment
Share on other sites

I typed it all exactly how you did, and it echos out absolutely nothing when hitting submit. I even tried typing in a value in the input box before hitting submit.

No errors were returned.

 

I even tried to echo out $newvalue[0], and it didn't show anything.

Link to comment
Share on other sites

<?php

include_once('../inc/admin.php');
include_once('../inc/connect.php');


// In admin area, Calculate how much each credit, view, impression is costing at the current price
// Do if statements and determine if the value should have a calculation to get rate

$varsquery = mysql_query("SELECT * FROM vars WHERE id='2'");
$row = mysql_fetch_array($varsquery);

$varsquery1 = mysql_query("SELECT * FROM vars WHERE id='1'");
$row1 = mysql_fetch_array($varsquery1);

$edit = $_GET['edit'];
$newvalue = "";

echo "
<html>
<head>
<title>Variables</title>
<style>
a:link{
text-decoration: none;
color: #519904;
}
a:visited{
text-decoration: none;
color: #519904;
}
a:hover{
text-decoration: none;
color: #4296ce;
}
#border{
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
";

echo "<div style='font-size: 28px; text-align: center;'>Variables</div><br />
<table align='center'>
<tr>
<th bgcolor='#cccccc'><a href='changevars.php?sort=number'>#</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=variable'>Variable</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=value'>Value</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=rate'>Rate</a></th>
<th bgcolor='#cccccc'><a href='changevars.php'>Change</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=default'>Default</a></th>
</tr><form action='changevars.php' method='POST'>";

$i = 1;
$color = 0;
while ($i < mysql_num_fields($varsquery)) {
    $meta = mysql_fetch_field($varsquery, $i);
    if (!$meta) {
        echo "No information available<br />\n";
    }

if ($color % 2){
$bgcolor = "#cccccc";
}
else{
	$bgcolor = "#ffffff";
}

	echo "<tr bgcolor='$bgcolor'><td align='center' width='20' bgcolor='#eeeeee' id='border'>$i</td>";
	echo "<td align='center' width='200' id='border'>$meta->name</td>";
	echo "<td align='center' width='200' id='border'>" .$row[$i]. "</td>";
if ($i==1){$amount = 500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==2){$amount = 1000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==3){$amount = 2500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==4){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==5){$amount = 7500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==6){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==7){$amount = 15000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i=={$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==9){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==10){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==11){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==12){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==13){$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==14){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==15){$amount = 75000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==16){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==17){$amount = 250000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==18){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==19){$amount = 20000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==20){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==21){$amount = 75000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==22){$amount = 125000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==23){$amount = 250000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==24){$amount = 500000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==25){$amount = 500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==26){$amount = 1000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==27){$amount = 2500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==28){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==29){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==30){$amount = 15000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==31){$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==32){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==33){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
else{$rate = 0.00;}
	echo "<td align='center' width='100' id='border' bgcolor='#9CB8FF'>".$rate."</td>";
	echo "<td align='center' width='200' id='border'><input type='text' name='$meta->name'></td>";
	echo "<td align='center' width='200' id='border' bgcolor='#9CFFB3'>" .$row1[$i]. "</td>";
	echo "</tr>";
	$newvalue .= $_GET[$meta->name];
    $i++;
$color++;
}
echo "<tr><td colspan='6' align='center'><input type='submit' name='edit' value='Edit'> <input type='reset' name='reset' value='Reset'></td></tr></form>"; 
echo "</table>";

if ($edit){

// Update new value
// $sql = mysql_query("UPDATE vars SET `credits500`='$newvalue[0]' WHERE id='2'");

$query = "UPDATE vars SET `credits500`=$newvalue[0] WHERE id=2";
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());

}


// Footer
echo "
</body>
</html>
";

?>

Link to comment
Share on other sites

Alright, I am now getting the following two errors echoed to the page:

 

Resource id #7

 

Resource id #8

 

I am also getting:

 

Query string: UPDATE vars SET `credits500`= WHERE id=2

Produced this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=2' at line 1

 

Here is my newly updated code:

 

<?php

include_once('../inc/admin.php');
include_once('../inc/connect.php');


// In admin area, Calculate how much each credit, view, impression is costing at the current price
// Do if statements and determine if the value should have a calculation to get rate

$varsquery = mysql_query("SELECT * FROM vars WHERE id='2'");
$row = mysql_fetch_array($varsquery) or die('<br />Query string: ' . $varsquery . '<br />Produced this error: ' . mysql_error());
echo "<br />$varsquery<br />";

$varsquery1 = mysql_query("SELECT * FROM vars WHERE id='1'");
$row1 = mysql_fetch_array($varsquery1) or die('<br />Query string: ' . $varsquery1 . '<br />Produced this error: ' . mysql_error());
echo "<br />$varsquery1<br />";

$edit = $_GET['edit'];
$newvalue = "";

echo "
<html>
<head>
<title>Variables</title>
<style>
a:link{
text-decoration: none;
color: #519904;
}
a:visited{
text-decoration: none;
color: #519904;
}
a:hover{
text-decoration: none;
color: #4296ce;
}
#border{
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
";

echo "<div style='font-size: 28px; text-align: center;'>Variables</div><br />
<table align='center'>
<tr>
<th bgcolor='#cccccc'><a href='changevars.php?sort=number'>#</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=variable'>Variable</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=value'>Value</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=rate'>Rate</a></th>
<th bgcolor='#cccccc'><a href='changevars.php'>Change</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=default'>Default</a></th>
</tr><form action='changevars.php' method='POST'>";

$i = 1;
$color = 0;
while ($i < mysql_num_fields($varsquery)) {
    $meta = mysql_fetch_field($varsquery, $i);
    if (!$meta) {
        echo "No information available<br />\n";
    }

if ($color % 2){
$bgcolor = "#cccccc";
}
else{
	$bgcolor = "#ffffff";
}

	echo "<tr bgcolor='$bgcolor'><td align='center' width='20' bgcolor='#eeeeee' id='border'>$i</td>";
	echo "<td align='center' width='200' id='border'>$meta->name</td>";
	echo "<td align='center' width='200' id='border'>" .$row[$i]. "</td>";
if ($i==1){$amount = 500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==2){$amount = 1000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==3){$amount = 2500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==4){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==5){$amount = 7500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==6){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==7){$amount = 15000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i=={$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==9){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==10){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==11){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==12){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==13){$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==14){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==15){$amount = 75000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==16){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==17){$amount = 250000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==18){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==19){$amount = 20000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==20){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==21){$amount = 75000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==22){$amount = 125000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==23){$amount = 250000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==24){$amount = 500000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==25){$amount = 500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==26){$amount = 1000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==27){$amount = 2500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==28){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==29){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==30){$amount = 15000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==31){$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==32){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==33){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
else{$rate = 0.00;}
	echo "<td align='center' width='100' id='border' bgcolor='#9CB8FF'>".$rate."</td>";
	echo "<td align='center' width='200' id='border'><input type='text' name='$meta->name'></td>";
	echo "<td align='center' width='200' id='border' bgcolor='#9CFFB3'>" .$row1[$i]. "</td>";
	echo "</tr>";
	$newvalue .= $_GET[$meta->name];
    $i++;
$color++;
}
echo "<tr><td colspan='6' align='center'><input type='submit' name='edit' value='Edit'> <input type='reset' name='reset' value='Reset'></td></tr></form>"; 
echo "</table>";

if ($edit){

// Update new value
// $sql = mysql_query("UPDATE vars SET `credits500`='$newvalue[0]' WHERE id='2'");

$query = "UPDATE vars SET `credits500`=$newvalue[0] WHERE id=2";
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());
echo "<br />$query<br />";
}


// Footer
echo "
</body>
</html>
";

?>

Link to comment
Share on other sites

You're trying to echo the mysql_query() execution result (which is a resource), not the query string. Take the query string out of the execution, store it in a variable, and use the variable in the execution. This is the first query, mimic it for the second query as well.

 

$query = "SELECT * FROM vars WHERE id = 2";
$result = mysql_query($query);
$row = mysql_fetch_array($result) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());
echo "<br />$query<br />";

Link to comment
Share on other sites

Wow, I am really failing tonight. I appreciate the help.

 

I fixed those issues (along with changed $_GET to $_POST), and am getting the following error:

 

Query string: UPDATE vars SET `credits500`= WHERE id=2
Produced this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id=2' at line 1

 

These two lines are also echoed out as expected:

SELECT * FROM vars WHERE id = 2

 

SELECT * FROM vars WHERE id= 1

 

The error only shows once I click Edit and the values still do not update as expected.

I'll keep messing with it until you are able to reply again. Thanks

Link to comment
Share on other sites

It would appear that newvalue[0] has no value. Are you sure the value is supposed to be in an array element?

 

What is this supposed to assign to it?

$newvalue = ""; // it's initialized as a string, not an array.
$newvalue .= $_GET[$meta->name]; // this won't make it into an array . . . 

Link to comment
Share on other sites

I think I need to change the $newvalue so it is an array. The $meta->name is the column name. It's supposed to grab the value for the current column at the current id (2), so it can update. This may not be the most logical way to do it.

 

I've attached a screenshot of what my page looks like so you can understand how I currently have it setup.

 

[attachment deleted by admin]

Link to comment
Share on other sites

OK. I see what you're trying to do now, and I think if you drop the [0] from $newvalue[0] and change $newvalue .= $_GET[$meta->name]; to $newvalue = $_POST[$meta->name]; (since you've specified POST as the form's method) it should have a value.

Link to comment
Share on other sites

Alright, it's now updating the value for credits500. But that was just the first of 45 columns. The way I am attempting to get it to work, is each input field that is created will have its own unique name, so when I type a value in that field, it will only change the value that is in the same row as the input field on the page.

 

As of right now, if I type a value in a separate field, it updates the first value 'credits500'. I realize my update query isn't complete yet. It will eventually have all of the column values.

 

Right now my update query is (the one after clicking edit):

$query = "UPDATE vars SET `credits500`=$newvalue WHERE id=2";
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());

 

So, I would add in the 45 diff values that would be needed. For an example, here is the update query with the first 2:

 

$query = "UPDATE vars SET `credits500`=$newvalue, `credits1000`=$newvalue WHERE id=2";
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());

 

When I try typing in 7.55 for example (in any of the fields), the new values for "Credits500" and "Credits1000" are both set to 7.55. (No errors return)

 

How can I modify this to have each input be set to its appropriate column?

 

(screenshot attached)

 

Updated Code:

 

<?php

include_once('../inc/admin.php');
include_once('../inc/connect.php');


// In admin area, Calculate how much each credit, view, impression is costing at the current price
// Do if statements and determine if the value should have a calculation to get rate

$varsquery = "SELECT * FROM vars WHERE id = 2";
$result = mysql_query($varsquery);
$row = mysql_fetch_array($result) or die('<br />Query string: ' . $varsquery . '<br />Produced this error: ' . mysql_error());

$varsquery1 = "SELECT * FROM vars WHERE id = 1";
$result1 = mysql_query($varsquery1);
$row1 = mysql_fetch_array($result1) or die('<br />Query string: ' . $varsquery1 . '<br />Produced this error: ' . mysql_error());


$edit = $_POST['edit'];
$newvalue = "";

echo "
<html>
<head>
<title>Variables</title>
<style>
a:link{
text-decoration: none;
color: #519904;
}
a:visited{
text-decoration: none;
color: #519904;
}
a:hover{
text-decoration: none;
color: #4296ce;
}
#border{
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
";

echo "<div style='font-size: 28px; text-align: center;'>Variables</div><br />
<table align='center'>
<tr>
<th bgcolor='#cccccc'><a href='changevars.php?sort=number'>#</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=variable'>Variable</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=value'>Value</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=rate'>Rate Per</a></th>
<th bgcolor='#cccccc'><a href='changevars.php'>Change</a></th>
<th bgcolor='#cccccc'><a href='changevars.php?sort=default'>Default</a></th>
</tr><form action='changevars.php' method='POST'>";

$i = 1;
$color = 0;
while ($i < mysql_num_fields($result)) {
    $meta = mysql_fetch_field($result, $i);
    if (!$meta) {
        echo "No information available<br />\n";
    }

if ($color % 2){
$bgcolor = "#cccccc";
}
else{
	$bgcolor = "#ffffff";
}

	echo "<tr bgcolor='$bgcolor'><td align='center' width='20' bgcolor='#eeeeee' id='border'>$i</td>";
	echo "<td align='center' width='200' id='border'>$meta->name</td>";
	echo "<td align='center' width='200' id='border'>" .$row[$i]. "</td>";
if ($i==1){$amount = 500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==2){$amount = 1000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==3){$amount = 2500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==4){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==5){$amount = 7500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==6){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==7){$amount = 15000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i=={$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==9){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==10){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==11){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==12){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==13){$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==14){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==15){$amount = 75000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==16){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==17){$amount = 250000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==18){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==19){$amount = 20000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==20){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==21){$amount = 75000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==22){$amount = 125000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==23){$amount = 250000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==24){$amount = 500000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==25){$amount = 500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==26){$amount = 1000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==27){$amount = 2500; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==28){$amount = 5000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==29){$amount = 10000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==30){$amount = 15000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==31){$amount = 25000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==32){$amount = 50000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
elseif ($i==33){$amount = 100000; $price = $row[$i]; $rate = $price / $amount; $rate = number_format($rate, 6);}
else{$rate = 0.00;}
	echo "<td align='center' width='100' id='border' bgcolor='#9CB8FF'>".$rate."</td>";
	echo "<td align='center' width='200' id='border'><input type='text' name='$meta->name'></td>";
	echo "<td align='center' width='200' id='border' bgcolor='#9CFFB3'>" .$row1[$i]. "</td>";
	echo "</tr>";
	$newvalue .= $_POST[$meta->name];
    $i++;
$color++;
}
echo "<tr><td colspan='6' align='center'><input type='submit' name='edit' value='Edit'> <input type='reset' name='reset' value='Reset'></td></tr></form>"; 
echo "</table>";

if ($edit){

// Update new value
// $sql = mysql_query("UPDATE vars SET `credits500`='$newvalue[0]' WHERE id='2'");

$query = "UPDATE vars SET `credits500`=$newvalue, `credits1000`=$newvalue WHERE id=2";
$sql = mysql_query($query) or die('<br />Query string: ' . $query . '<br />Produced this error: ' . mysql_error());
echo "<br />$query<br />";
	echo "<SCRIPT language='JavaScript'><!--
			window.location='changevars.php';//-->
		  </SCRIPT>";
}


// Footer
echo "
</body>
</html>
";

?>

 

 

 

 

[attachment deleted by admin]

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.