Jump to content

[SOLVED] query empty


jeppers

Recommended Posts

what do u think might be causing my query to be empty. i am not sure what about you.

 

<?php // check the form has been submitted 
if (isset($_POST['submitted'])) {

$errors = array(); // Initialize error array.

// Check for a first name.
if (empty($_POST['title'])) {
	$errors[] = 'You forgot to enter the title';
} else {
	$t =($_POST['title']);
}

// Check for a last name.
if (empty($_POST['description'])) {
	$errors[] = 'You forgot to enter the description.';
} else {
	$d =($_POST['description']);
}

// Check for a last name.
if (empty($_POST['price'])) {
	$errors[] = 'You forgot to enter the price.';
} else {
	$p =($_POST['price']);
}

if (empty($errors)) { // If everything's OK.

$result = mysql_query($query)or die(mysql_error());;
if (mysql_num_rows($result) == 0) {

	// make query
	$query = "UPDATE foods SET title='$t', description='$d', price='$p'
			  WHERE food_id=$id";
			  $result = @mysql_query($query) or die(mysql_error());
			  if (mysql_affected_rows()==1) {// if ran ok 
			  
				//print message
				echo '<h1> Edit Food</h1>
				<p>The food has been updatted</p><p><br /><br /></p>';

			} else { //if it did not run ok
				echo '<h1> System error</h1>
				<p>Sorry there has been an error and the food could not be updated. sorry</p>';
				echo '<p>' . mysql_error() .'<br /><br />Problem:' . $query . '</p>';// debugging message
				//include ('footer.php')
				exit();
			}
		}else{ 
			echo '<h1>sorry your food has been updated already</h1>';
		}

	} else { //report the errors
		echo '<h1>Error!</h1>
		<p>The follow errors have occurred:<br />';
		foreach ($errors as $msg){//print each message 
			echo "-$msg<br />\n";
		}
		echo'</p><p>Please try again.</p><p><br /></p>';
	}//end of if
}

Link to comment
Share on other sites

Does something look off here to you?

 

...snip...
   if (empty($errors)) { // If everything's OK.
   
   $result = mysql_query($query)or die(mysql_error());;
   if (mysql_num_rows($result) == 0) {
...snip...

 

You are doing a completely random mysql_query() without even setting $query.  Also, you have two semicolons.

Link to comment
Share on other sites

well the script is pulling a $id from another script.

 

// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php
$id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted.
$id = $_POST['id'];
} else { // No valid ID, kill the script.
echo '<h1">Page Error</h1>
<p>This page has been accessed in error.</p><p><br /><br /></p>';
exit();
}

 

 

thanks for spotting the double colon

 

so why do u think there is an empty query

Link to comment
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.