PDA

View Full Version : PHP Help.



TechnoPanda
02-02-2009, 10:38 PM
<?php
session_start();
require ("connect.php");
require("functions.php");
include("template/header.php");

if(!isset($_SESSION['status'])){
die('You need to <a href="login.php">login</a> before you can access the members area!');
}
if($_SESSION['id'] != $_GET['user']){
die ('Error');


}else{
$offer = mysql_real_escape_string($_GET['offer']);
$user = mysql_real_escape_string($_GET['user']);
$title = mysql_real_escape_string($_GET['title']);
$username = mysql_real_escape_string($_GET['username']);
$value1 = mysql_query("SELECT * FROM offers WHERE id='$offer'");
$value2 = mysql_fetch_array($value1);
$value = $value2['value'];
$date = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$status = "0";
$result = mysql_query("SELECT * FROM users WHERE id='$user'");
$valueoffer = mysql_fetch_array($result);
$valueamount = $valueoffer['pending'];
$newpending = $valueamount + $value;
$username = $valueoffer['username']; // I'm assuming 'username' is the name of you username field. Amend if incorrect.



$result = mysql_query("SELECT * FROM offers WHERE id='$title'");
$offertitle = mysql_fetch_array($result);
$otitle = $offertitle['offername'];


// table, field and value should all be replaced according to your table


mysql_query("INSERT into offersUSERS VALUES(NULL, '$username', '$offer', '$otitle', '$status', '$value', '$ip', '$user', '$date')");

mysql_query("UPDATE users SET pending='$newpending' WHERE id='$user'");
echo "Done! You will be credited as soon as an administrator approves the offer! <a href=\"members.php\">return?</a>";
}
include("template/footer.php");
?>

Here's my code, it currently updates the table 'username' in my database. But I can't get it to update 'offertitle'. Why?

Calgon
04-02-2009, 02:34 PM
mysql_query("INSERT into offersUSERS VALUES(NULL, '$username', '$offer', '$otitle', '$status', '$value', '$ip', '$user', '$date')");


Basic syntax of your insert query isn't working out.



mysql_query( "INSERT INTO `offersUSERS` (table1, table2, table3) VALUES('value1', 'value2', 'value3') " );


Containing table information like the table name, where you've not bothered to use `table` - is not really neat, as you can see my version looks a lot neater.

You didn't define what columns need to be updated, so that explain's why it wasn't working.

Want to hide these adverts? Register an account for free!