Page 2 of 2

Posted: Wed Jun 14, 2006 8:14 pm
by LiveFree

Code: Select all

$sql2 = "INSERT INTO coffers (username,offer_name,offer_type) VALUES ('{$data[username]}', '{$data[offer_name]}', '{$data[offer_type]}')";

Posted: Thu Jun 15, 2006 5:09 am
by a94060
ok,thanks,ill try it a little later

Posted: Thu Jun 15, 2006 6:35 pm
by a94060
well the query is working...but i ran into another rpoblem. That is,when i select the link to approve it,it moves it to the coffers but it does not delete it from the poffers table. So i end up with the offfer still there and it is also added to the coffers table.Code After change:

Code: Select all

<?PHP
session_start();
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?PHP
error_reporting(e_all);
if($_SESSION['in'] != '1' ) {
echo '<font color=red>You are not logged in,please go <a href="../admin">Here</a> to login.</font>';
}
else {
/*the action page.all actions of the admin will be redirected here.
That is all*/
include("../includes/sql.php");
$act = $_GET['act'];
$entry = $_GET['entry'];//the id of the entry

	if($act == 'approve') {
	$query = "SELECT * FROM poffers WHERE id = $entry";
	$result = mysql_query($query);
	$data = mysql_fetch_array($result,MYSQL_ASSOC);
	$sql2 = "INSERT INTO coffers (username,offer_name,offer_type) VALUES ('{$data[username]}', '{$data[offer_name]}', '{$data[offer_type]}')";  
	$sql2run = mysql_query($sql2) or die(mysql_error());//inserts the offer to completed table.
	//remove it from the old table
	$put = mysql_affected_rows($sql2run) or die(mysql_error());
		if($put == 1) {
		$delete = "DELETE * FROM poffers WHERE id=$entry";
		$delrun = mysql_query($delete) or die(mysql_error());
		$hits = mysql_affected_rows($delrun) or die(mysql_error());
			if($hits >= 1) {
			echo 'The offer' .$entry.' has been removed from pending offers and has been moved to completed offers.';
			}
			else{
			echo 'The entry was not added.';
			}
		}
	}
}
if($act == 'offer_add') {
$offer = $_GET['offer'];
$type = $_GET['select'];//tells what type of offer it is

$sql = "INSERT INTO offers ('offer_name' , 'offer_type') VALUES (" .$offer. " , " .$type.")";
$query = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows($query) != 1) {
echo "Your add was not successful,please go back and try again.";
}
else {
echo "Your Offer was sucessfully added to the database.";
}
}
?>
</body>
</html>

Posted: Thu Jun 15, 2006 7:03 pm
by RobertGonzalez
I would seriously recommend error checking. After each query, error check it...

Code: Select all

<?php
$sql = "SQL STATEMENT";
$result = mysql_query($sql) or die("Could not run the query: " . mysql_error());
?>
This will tell you your problems with your queries.

Posted: Thu Jun 15, 2006 7:03 pm
by LiveFree
People always confuse DELETE with SELECT

Code: Select all

$delete = "DELETE FROM poffers WHERE id=$entry";

Posted: Thu Jun 15, 2006 8:25 pm
by a94060
so,i did not need the * in there right?

Posted: Thu Jun 15, 2006 8:27 pm
by a94060
ok,ill try to make sure that i use that error checking as it will probably eliminate lots of posts over here. Thanks for the help,will try tommorow.