Jump to content

Error in retrieving information


emilcarlo

Recommended Posts

Hello,

 

I am having a problem with retrieving information from my database. I am kinda new in programming industry, and with the error message displayed, I can't pinpoint what went wrong in the code. Here is the PHP code:

 

<?php
include("dbconnection.php");

if(isset($_POST["btnSubmit"]))
{
$id = $_POST["id"];
$territory = $_POST["territory"];
$job_title = $_POST["job_title"];
$area_of_work = $_POST["area_of_work"];
$employer = $_POST["employer"];
$location = $_POST["location"];
$job_title = $_POST["job_title"];
$date_posted = $_POST["date_posted"];
$closing_date = $_POST["closing_date"];
$department = $_POST["department"];
$gender = $_POST["gender"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$title = $_POST["title"];
$telephone = $_POST["telephone"];
$address_1 = $_POST["address_1"];
$address_2 = $_POST["address_2"];
$address_3 = $_POST["address_3"];
$country = $_POST["country"];
$city = $_POST["city"];
$postal_code = $_POST["postal_code"];
$website = $_POST["website"];
$email_address = $_POST["email_address"];
$cg_comment = $_POST["cg_comment"];
$date_emailed = $_POST["date_emailed"];
$mailing_comments = $_POST["mailing_comments"];
$telesales_comments = $_POST["telesales_comments"];

$query = "UPDATE contacts SET territory= '".$territory."', job_title = '".$job_title."', area_of_work = '".$area_of_work."', employer = '".$employer."', location = '".$location."', job_title = '".$job_title."', employer = '".$employer."', date_posted = '".$date_posted."', department = '".$department."', closing_date = '".$closing_date."', gender = '".$gender."', first_name = '".$first_name."', last_name = '".$last_name."', title = '".$title."', telephone = '".$telephone."', address_1 = '".$address_1."', address_2 = '".$address_2."', address_3 = '".$address_3."', country = '".$country."', city = '".$city."', postal_code = '".$postal_code."', website = '".$website."', email_address = '".$email_address."', cg_comment = '".$cg_comment."', date_emailed = '".$date_emailed."', mailing_comments = '".$mailing_comments."', telesales_comments = '".$telesales_comments."' WHERE id = '".$id."'";
mysql_query($query) or die(mysql_error());

echo "<script>
	alert('You have successfully updated a record');
	window.location = 'view.php';
</script>";
}

$query = "SELECT * FROM contacts WHERE id = '".$_GET["id"]."'";
$result = mysql_query($query, $connection);

if(mysql_num_rows($result) > 0)
{
$territory = mysql_result($result,0, "territory");
$job_title = mysql_result($result, 0, "job_title");
$area_of_work = mysql_result($result, 0, "area_of_work");
$employer = mysql_result($result, 0, "employer");
$status = mysql_result($result, 0, "status");
$location = mysql_result($result,0, "location");
$department = mysql_result($result,0, "department");
$date_posted = mysql_result($result,0, "date_posted");
$closing_date = mysql_result($result,0, "closing_date");
$gender = mysql_result($result,0, "gender");
$first_name = mysql_result($result,0, "first_name");
$last_name = mysql_result($result,0, "last_name");
$title = mysql_result($result,0, "title");
$telephone = mysql_result($result,0, "telephone");
$address_1 = mysql_result($result,0, "address_1");
$address_2 = mysql_result($result,0, "address_2");
$address_3 = mysql_result($result,0, "address_3");
$city = mysql_result($result,0, "city");
$country = mysql_result($result,0, "country");
$postal_code = mysql_result($result,0, "postal_code");
$website = mysql_result($result,0, "website");
$email_address = mysql_result($result,0, "email_address");
$cg_comment = mysql_result($result,0, "cg_comment");
$date_emailed = mysql_result($result,0, "date_emailed");
$mailing_comments = mysql_result($result,0, "mailing_comments");
$telesales_comments = mysql_result($result,0, "telesales_comments");
}


?>

 

The error I am getting is:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\invent-asia\edit_client.php on line 268

 

Line 268 in the code is:

 

if(mysql_num_rows($result) > 0)

{ - This one is line 68

$territory = mysql_result($result,0, "territory");

 

Immediate response is well appreciated. Thank you very much!

Link to comment
Share on other sites

if(mysql_num_rows($result) > 0)  

is the line of code that has a problem.

 

Your code does not think $result is a valid MySQL result.

 

Try modifying this (modified) sample code from the PHP manual and see if you can pinpoint your problem:

<?php
$result = mysql_query('SELECT territory FROM contacts', $connection);
if (!$result) {
    die('Could not query:' . mysql_error());
}
echo mysql_result($result, 0); // outputs first result
?>

 

By the way, for something with that many row items, you might find it easier to use mysql_fetch_row (http://www.php.net/manual/en/function.mysql-fetch-row.php)  instead of saving each one as a variable.  This will save your results as an array.

if(mysql_num_rows($result)>0)
     $row=mysql_fetch_row($result,)

 

Then you can access each variable with e.g.

$row->territory

 

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.