Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-25-2010, 03:38 AM Submit new values
Skilled Talker

Posts: 83
Trades: 0
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 Code:
<?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'>&nbsp;<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>
"
;

?>
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-25-2010, 05:52 AM Re: Submit new values
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Test for a value then if it exists, append the SQL code to update that column to the query.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-25-2010, 01:35 PM Re: Submit new values
Skilled Talker

Posts: 83
Trades: 0
Thank you, I'll work on that and see where I can get.
Smudly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Submit new values
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52937 seconds with 12 queries