Current location: Hot Scripts Forums » Programming Languages » PHP » PHP to MySQL script question...(using a field to update info in MySQL)


PHP to MySQL script question...(using a field to update info in MySQL)

Reply
  #1 (permalink)  
Old 10-29-03, 01:03 PM
DisneyFan25863 DisneyFan25863 is offline
New Member
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
PHP to MySQL script question...(using a field to update info in MySQL)

Ok, I've been thinking about how to do this for some time, but can't figure it out. I basically want to have a number stored in a MySQL Database, which can be added or subtracted to from a webpage, then displayed on another. So Basically, the script would be like this. I would put in a query string for each number, (like www.whatever.com/number.php?changenumber=yes, but I already know how to do that). I would then have it so that there would be an option with two buttons (one that says add, one that says subtract), and then a text field for a number. So, for instance, if I wanted to subtract 4 , it would go like this:

I would select the button for "subtract" on the form, then enter "4" in the text field. Clicking submit would go to a php script that would put it in a database. This is where I need help. What should I put for the script?
Something like this?


PHP Code:

<?php

$conn 
mysql_connect("localhost""user""pass");
mysql_select_db("DB",$conn);
$sql "INSERT INTO Table values ('', 'What to put here?')";
if (
mysql_query($sql$conn)) {
     echo 
"record added!";
} else {
    echo 
"something went wrong";
}
?>

If I were to just use a "$_POST[field]')" there, it would replace the number, right? So does anyone know what I should put?

Thank You!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-30-03, 12:34 AM
dotbob dotbob is offline
Newbie Coder
 
Join Date: Oct 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by DisneyFan25863
If I were to just use a "$_POST[field]')" there, it would replace the number, right? So does anyone know what I should put?

Thank You!
Why can't you extract the number out of the db to do work on it?
__________________
<img src="http://ebigman.com/image/dotbob_small.gif">Premium Domain Nameshttp://www.dotbob.ebigman.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-30-03, 03:22 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
your code is good ..
PHP Code:

<?php 

$number
=$_POST['number'];//get the number from POST
settype($number"integer");//make sure it's a number not a string ..
$conn mysql_connect("localhost""user""pass"); 
mysql_select_db("DB",$conn); 
$sql "INSERT INTO Table values ('', number=number-$number)";
/*notice that you don't need any quote here just call 'number' from database
and use it again in the same query and substract
$number from it .. ot use any other algebra ..*/
if (mysql_query($sql$conn)) { 
     echo 
"record added!"
} else { 
    echo 
"something went wrong"

?>
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-01-03, 02:14 AM
DisneyFan25863 DisneyFan25863 is offline
New Member
 
Join Date: Oct 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by NeverMind
your code is good ..
PHP Code:

<?php 

$number
=$_POST['number'];//get the number from POST
settype($number"integer");//make sure it's a number not a string ..
$conn mysql_connect("localhost""user""pass"); 
mysql_select_db("DB",$conn); 
$sql "INSERT INTO Table values ('', number=number-$number)";
/*notice that you don't need any quote here just call 'number' from database
and use it again in the same query and substract
$number from it .. ot use any other algebra ..*/
if (mysql_query($sql$conn)) { 
     echo 
"record added!"
} else { 
    echo 
"something went wrong"

?>
Shouldn't it be

PHP Code:

<?php 

$number
=$_POST['number'];//get the number from POST
settype($number"integer");//make sure it's a number not a string ..
$conn mysql_connect("localhost""user""pass"); 
mysql_select_db("DB",$conn); 
$sql "INSERT INTO Table values ('', number=number+$number)";
/*notice that you don't need any quote here just call 'number' from database
and use it again in the same query and substract
$number from it .. ot use any other algebra ..*/
if (mysql_query($sql$conn)) { 
     echo 
"record added!"
} else { 
    echo 
"something went wrong"

?>
(See the "+" insted of the "-"). So, if they wanted to add a number to it, lests say 53 it would be number+53. If they wanted to subtract a 53, it would be number+-53. Would that be right?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-02-03, 04:31 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
try ,,
I am not sure if using - after + is legal in php ... but try ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP script HELP Jerome PHP 7 12-22-09 07:44 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
PHP + MySQL script help need andyinorbit2000 PHP 1 09-09-03 03:07 AM
MySQL with PHP question. HELP for a newbie kenfused PHP 3 08-02-03 01:53 AM
I need help with my first php script NeverMind PHP 4 08-01-03 02:27 PM


All times are GMT -5. The time now is 10:41 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.