Jump to content

waht is wrong with this line of code


ballhogjoni

Recommended Posts

lol its not showing my code i posted. if ($row['Username'] == $Username && $row['title'] == $title_checked && $row['description'] == $desc_checked && $row['price'] == $price) {

 

if (isset($_POST['submit'])) {
if (isset($_POST['title']) && isset($_POST['desc']) && isset($_POST['price'])) {
$title_checked = strip_tags($_POST['title']);
$desc_checked = strip_tags($_POST['desc']);
$price = $_POST['price'];
if (!empty($title_checked) && !empty($desc_checked) && !empty($price)) {
$query = mysql_query("SELECT Username, title, description, price FROM products WHERE Username = '$Username'") or die(mysql_error));
$row = mysql_fetch_array($query) or die(mysql_error));
if ($row['Username'] == $Username && $row['title'] == $title_checked && $row['description'] == $desc_checked && $row['price'] == $price) {
$verbage = '<span class="problemMessage">Product has NOT been saved. You already have this product in your database.</span>';
} else {
	if (strlen($title_checked) > 20 || strlen($desc_checked) > 30) {
		$leng = '<span class="problemMessage">Please check the length of your Title and Description. Title is 20 Characters Max and Description is 30 Characters Max.</span>';
	} elseif (strlen($title_checked) <= 20 && strlen($desc_checked) <= 30) {
    		mysql_query("INSERT INTO products (Username, title, description, price) VALUES ('$Username','$title_checked','$desc_checked','$price')") or die(mysql_error());
		$verbage = '<span class="goodMessage">Your product has been saved.</span>';
	}
} else {
	$verbage = '<span class="problemMessage">Product has NOT been Saved. Please enable Javascript & be sure to fill in all fields</span>';
}
}
}

Ya I still can't figure it out either. Here is the latest code

 

<?php 
session_start(); 
include('db.php'); 
include('functions.php'); 
checkLogin('1 2');
$query = mysql_query("SELECT * FROM users WHERE ID = '{$_SESSION['user_id']}'");
$row = mysql_fetch_array($query) or die(mysql_error());
$Username = $row['Username'];

if (isset($_POST['submit'])) {
if (isset($_POST['title']) && isset($_POST['desc']) && isset($_POST['price'])) {
$title_checked = strip_tags($_POST['title']);
$desc_checked = strip_tags($_POST['desc']);
$price = $_POST['price'];
if (!empty($title_checked) && !empty($desc_checked) && !empty($price)) {
	$query = "SELECT * FROM products WHERE Username = '$Username'"; 
	$result = mysql_query($query) or die(mysql_error());
	$row = mysql_fetch_array($result));
	if ($row['Username'] == $Username && $row['title'] == $title_checked && $row['description'] == $desc_checked && $row['price'] == $price) {
		$verbage = '<span class="problemMessage">Product has NOT been saved. You already have this product in your database.</span>';
	} elseif ($row['Username'] != $Username || $row['title'] != $title_checked || $row['description'] != $desc_checked || $row['price'] != $price) {
		if (strlen($title_checked) > 20 || strlen($desc_checked) > 30) {
		$leng = '<span class="problemMessage">Please check the length of your Title and Description. Title is 20 Characters Max and Description is 30 Characters Max.</span>';
		} elseif (strlen($title_checked) <= 20 && strlen($desc_checked) <= 30) {
    		mysql_query("INSERT INTO products (Username, title, description, price) VALUES ('$Username','$title_checked','$desc_checked','$price')") or die(mysql_error());
		$verbage = '<span class="goodMessage">Your product has been saved.</span>';
		}
	}
} else {
	$verbage = '<span class="problemMessage">Product has NOT been Saved. Please enable Javascript & be sure to fill in all fields</span>';
}
} else {
$verbage = '<span class="problemMessage">Product has NOT been Saved. Please enable Javascript & be sure to fill in all fields</span>';
}
}
?>

 

I think its the logic because nothing shows up when I view the page not even the form. (the form is not in the code above)

Sorry, I didn't realize you weren't submitting the form.

 

There are way too many problems that could be occuring before it even gets to the code you posted. You are including two other files before that code. I think what you need to do is split them up and run them individually and see which one gives an error.

I think its the logic somewhere.

 

Could be.  I can't help but notice that you go to great lengths to set up a string variable named $leng and another string variable named $verbage and neither of them is ever used in the script, let alone echo'd.  What were you expecting other than a blank screen?

I think its the logic somewhere.

 

Could be.  I can't help but notice that you go to great lengths to set up a string variable named $leng and another string variable named $verbage and neither of them is ever used in the script, let alone echo'd.  What were you expecting other than a blank screen?

 

LOL thats because I dint post the whole page of code. Here's the form

<?php
					if ($product_count <= 24) {
						if (isset($verbage)) { echo '<center>'.$verbage.'</center>'; } if (isset($leng)) { echo '<center>'.$leng.'</center>'; } unset($verbage,$leng);?>
					<form action="" onSubmit="return validateFormOnSubmit(this)" method="POST">
					<!--<div align="center" class="formText">This form requires javascript to be enabled</div>-->
					<table class="standard">
						<tr>
							<td class="formTableLeft">Title:</td>
							<td class="formTableRight"><input type="text" name="title" /></td>
						</tr>
						<tr>
							<td class="formTableLeft">Description:</td>
							<td class="formTableRight"><input type="text" name="desc" /></td>
						</tr>
						<tr>
							<td class="formTableLeft">Price:</td>
							<td class="formTableRight"><input type="text" name="price" /></td>
						</tr>
						<tr>
							<td colspan="2" align="center"><br /><input type="hidden" name="submit" /><input class="formText" type="submit" value="Add Product" /></td>
						</tr>
					</table>
					</form>
					<?php
					} else {
						echo '<span class="problemMessage"><center>You must purchase more product space. Due to the expense we receive for offering this free service, we can only allow 25 free products. <a href="">Click here</a> to purchase more product space.</center></span>';
					}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.