DATA is not loading into mySQL...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cyandi_man
Forum Newbie
Posts: 12
Joined: Sun Nov 02, 2008 10:47 am

DATA is not loading into mySQL...

Post by cyandi_man »

hi gang just wondering if you would be able to help me with this php code here. the data '$amount' and '$pnts' comes from a flash file which has been verified to not contain the error.

what this php code is trying to do is check total points on a table in sql and comparing with the points that the user wishes to redeem. If the total points on mySQL is sufficient enough - the points are redeemed and the redeemed points go into a 'total points redeemed' table.
if not then the appropriate error message is sent to the swf.

Code: Select all

 
<?
session_start();
$clientN = $_SESSION['client'];
$me = $_SESSION['name'];
$me2 = $_SESSION['name2'];
if (@$_SESSION['auth']!="yes")
{
header("Location: ../personal_account_login.php");
exit();
}$user="Myuser";
  $host="localhost";
  $password="MYpass";
  $database = "myDatabase";
  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");
 
$query1 = "SELECT totalpnts FROM patient_totals WHERE clientNumber='$clientN'";
$result1 = mysql_query($query1) or die(mysql_error());
while($row1 = mysql_fetch_array($result1)){
extract($row1);
if ($pnts > $totalpnts) {
Print "_root.status=SORRY!  You Do Not Have Enough Health Points to Redeem This Item - Please Choose Again!";
}
else
{
$newtotal= $totalpnts - $pnts;
$queryx = "UPDATE patient_totals SET totalpnts='$newtotal' WHERE clientNumber='$clientN'";
$resultx = mysql_query($queryx) or die(mysql_error());
 
$query3 = "INSERT INTO redemption(clientNumber, firstName, lastName, product, amount, pnts)
VALUES('$clientN', '$me', '$me2', '$item','$amount', '$pnts')";
 
$result3= mysql_query($query3)
or DIE("Unable to redeem your points at this time...please try again later.");
Print "_root.status=You have successfully redeemed $pnts Points!  You will receive an email with your voucher attached within 24hrs. Thank you!";
}
}
?>
any help would be greatly appreciated - THANKS!
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: DATA is not loading into mySQL...

Post by it2051229 »

you mean data doesn't get inserted into the mysql database? orr you can't get data from the mysql database?
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: DATA is not loading into mySQL...

Post by susrisha »

What is the data type for totalpnts?
If its an integer, you are passing the query wrong. There should be no single quotes. If there are single quotes, it will be taken as a string and adding strings in mysql?? i dont know if thats possible.
cyandi_man
Forum Newbie
Posts: 12
Joined: Sun Nov 02, 2008 10:47 am

Re: DATA is not loading into mySQL...

Post by cyandi_man »

it2051229 wrote:you mean data doesn't get inserted into the mysql database? orr you can't get data from the mysql database?
data does not get INSERTED into the database.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: DATA is not loading into mySQL...

Post by it2051229 »

are you sure this variables have values? becuase the way I see it, I can't find $item, $amount, and $pants and I'm not sure if something was stored in your session.

'$clientN', '$me', '$me2', '$item','$amount', '$pnts'

try doing a print first instead of insert to see if the variables has values.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: DATA is not loading into mySQL...

Post by susrisha »

you forgot to give the connection handler to the update as well as the insert queries. While select query of mysql usually doesnt need a connection handler, insert and update will need the connection handler
for the queries queryx and query3, you forgot to include

Code: Select all

mysql_query($queryx,$connection);
that might be the problem.
Post Reply