Jump to content

Recommended Posts

if(!$_POST['buy']){
if($row['tokens'] < $price){
$sql3 = "INSERT INTO `inventory` (`id`,`uid`,`price`,`name`,`image`) VALUES('".$id."','".$_SESSION['uid']."','".$price."','".$name."','".$imageurl."')";
$res3 = mysql_query($sql3) or die(mysql_error());
}else {
echo "Insufficient Funds!";
}
}

 

I'm trying to get this function to work, except it's not inserting ANYTHING into inventory. Been trying to get it working for what? an hour or so?

Link to comment
https://forums.phpfreaks.com/topic/173563-insert-into-problem/
Share on other sites

echo "<center><table border=\"1\" cellspacing=\"3\" cellpadding=\"3\">\n";
        echo "<form method=\"post\" action=\"./process.php\">\n";
        echo "<tr><td colspan=\"2\" align=\"Center\"><input type=\"submit\" name=\"buy\" value=\"Purchase\"></td></tr>\n";
        echo "</form></table></center>\n";

if(!$_POST['buy']){
if($row['tokens'] < $price){
$sql3 = "INSERT INTO `inventory` (`id`,`uid`,`price`,`name`,`image`) VALUES('".$id."','".$_SESSION['uid']."','".$price."','".$name."','".$imageurl."')";
$res3 = mysql_query($sql3) or die(mysql_error());
}else {
echo "Insufficient Funds!";
}
}

 

I'm trying to get it so when you click purchase and have enough 'tokens' it will insert the values already defined into the fields.

 

<?php
session_start();
include "./globals.php";


$action = $_GET['act'];
$actions_array = array("itemcomment","nitemcomment");

?>

<html>

<head>
	<title>Zoofu | View Item</title>
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
	<link rel="icon" href="/favicon.ico" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="./style.css">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</head>

<body>
<center>
	<div id="holder">
		<div id="userInfo">
			<?php

				if($_SESSION['uid']){
					$sql = "SELECT * FROM `users` WHERE `id`='".$_SESSION['uid']."'";
					$res = mysql_query($sql) or die(mysql_error());

					if(mysql_num_rows($res) == 0){
							session_destroy();
							echo "<div align=\"right\"><a href=\"./login.php\">Login</a> | <a href=\"./register.php\">Register</a></div>\n";
					}else {
						$row = mysql_fetch_assoc($res);
						echo "<div align=\"right\">Logged in as: <a href=\"./index.php?act=profile&id=".$row['id']."\">".$row['username']."</a> | <a href=\"./inventory.php\">My Inventory</a> | <a href=\"./logout.php\">Logout?</a></div>\n";
						echo "<div align=\"right\">Lv. ".$row['level']." | EXP ( ".$row['exp']." / 1000 ) | <img src=\"./token.png\"> Tokens ( ".$row['tokens']." )</div>\n";
						if($row['admin'] == '1'){
							echo "<a href=\"./admin.php\"></a>\n";
						}
					}
				}else {
					echo "<div align=\"right\"><a href=\"./login.php\">Login</a> | <a href=\"./register.php\">Register</a></div>\n";
				}

				$admin_user_level = $row['admin'];
				echo "<tr><td><center><img src=\"./logo.png\"></center></td></tr>\n";
				echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"85%\">\n";
				echo "<tr><td><center><b><a href=\"./games.php\">| Games |</a></b></td></center><td><center><b><a href=\"./catalog.php\">| Catalog |</a></b></td></center><td><center><b><a href=\"./browse.php\">| Browse |</a></b></center></td><td><center><b><a href=\"./index.php\">| Forum |</a></b></center></td><td><center><b><a href=\"./help.php\">| Help |</a></b></center></td></tr>\n";
				echo "</table></center>\n";

			?>

<div id ="content">
<?php 
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM items WHERE id = '$id'");
$fetch_array = mysql_fetch_array($query);
$name = $fetch_array['name'];
$id = $fetch_array['id'];
$price = $fetch_array['price'];
$comments = $fetch_array['comment'];
$imageurl = $fetch_array['image'];
$desc = $fetch_array['desc'];
$type = $fetch_array['type'];

$sel=mysql_query("SELECT * FROM `items` WHERE `id`=".$id."") OR die(mysql_error());
$row=mysql_fetch_array($sel);

echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"80%\">\n";
echo "<tr><td class=\"forum_header\"><center><b>".$name."</b><br>ItemID: ".$id."</center></td></tr>\n";
echo "<br>\n";
echo "</table></center>\n";

echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"30%\">\n";
echo "<tr><td class=\"forum_header\"><center><b><img src=".$imageurl."></center></td></tr>\n";
echo "</table></center>\n";

echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"50%\">\n";
echo "<tr><td class=\"forum_header\"><center><b>Description</center></b><br>".$desc."</td>\n";
echo "</tr></table></center>\n";

echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" width=\"50%\">\n";
echo "<tr><td class=\"forum_header\"><center><img src=\"./token.png\"> Tokens: $price</center><br><center><b>Type: $type</b></center></td>\n";
echo "</tr></table></center>\n";

echo "<center><table border=\"1\" cellspacing=\"3\" cellpadding=\"3\">\n";
        echo "<form method=\"post\" action=\"./process.php\">\n";
        echo "<tr><td colspan=\"2\" align=\"Center\"><input type=\"submit\" name=\"buy\" value=\"Purchase\"></td></tr>\n";
        echo "</form></table></center>\n";

if(!$_POST['buy']){
if($row['tokens'] < $price){
$sql3 = "INSERT INTO `inventory` (`id`,`uid`,`price`,`name`,`image`) VALUES('".$id."','".$_SESSION['uid']."','".$price."','".$name."','".$imageurl."')";
$res3 = mysql_query($sql3) or die(mysql_error());
}else {
echo "Insufficient Funds!";
}
}

?>

Link to comment
https://forums.phpfreaks.com/topic/173563-insert-into-problem/#findComment-914873
Share on other sites

You probably have the id field as PRIMARY KEY, so it can't be duplicate. And it SHOULD be auto_increment also so you don't even need to insert the ID field never ever. The second error appears because your SQL query has errors in it as the error message says. So echo out the query that fails and post here so we can see what is wrong. If you have some queries before $sql3 echo them and see what is the result. If $sql3 was empty it probably never goes inside that if -statement at all.

Link to comment
https://forums.phpfreaks.com/topic/173563-insert-into-problem/#findComment-915568
Share on other sites

Yeah, that's what I just realised. :) Thanks. :)

 

But the if statements isn't working... the

if($row['tokens'] < $price){ part. Dunno why.

 

Just saw the values, and don't know what the problem is there, but this statement is checking if your amount of 'tokens' is less than the item 'token value'. Shouldn't that be the other way around? eg. If the player tokens are > than the item token value...

Link to comment
https://forums.phpfreaks.com/topic/173563-insert-into-problem/#findComment-915581
Share on other sites

Yes it means $row['tokens'] has a NULL value and $price = "3". So that is why the if does not evaluate as TRUE. Because NULL is not same as 3. This is basic debugging and good to remember things like this. The next step would be to find out why is tokens NULL.

 

<?php
var_dump((NULL < '3'));

 

Actually that gives out a TRUE value so... a bit weird why it's not going anyway inside the if. But now i gotta go.. will be back later!

Link to comment
https://forums.phpfreaks.com/topic/173563-insert-into-problem/#findComment-915582
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.