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
https://forums.phpfreaks.com/topic/139191-solved-query-empty/
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
https://forums.phpfreaks.com/topic/139191-solved-query-empty/#findComment-728020
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
https://forums.phpfreaks.com/topic/139191-solved-query-empty/#findComment-728041
Share on other sites

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.