Jump to content

Undefined Variable Problem


bugzy

Recommended Posts

I can't get the value of $edit_proj_name and $edit_content fromn the below code.

 

 

 

<?php

if(isset($id))
{

$edit_proj_id = $_GET['id'];

$edit_query = "Select proj_name, content from rec_proj where proj_id = {$edit_proj_id}";

$edit_result = mysql_query($edit_query, $connection);

$edit_proj_name = mysql_result($edit_result,$i,"proj_name");
$edit_content = mysql_result($edit_result,$i,"content");



}


?>

 

 

I wonder what the problem is..

Link to comment
Share on other sites

if(isset($id))

 

Have you defined that variable or is it meant to be a GET method?

if(isset($_GET['id']))

 

hey thank you for the response.

 

It's a get, the value is coming from

 

<a href=\"edit_project.php?id=". mysql_result($result,$i,"proj_id") ."\">[edit]</a>

Link to comment
Share on other sites

pic=358216.msg1693066#msg1693066 date=1335128154]

Did you try the code I gave you?

 

I just tried it...

 

Now I'm having this error

 

Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\hee\edit_project.php on line 52

 

Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\hee\edit_project.php on line 53

5

Link to comment
Share on other sites

bugzy,

  There are any number of mysteries in your code that could account for your problem.

 

-As pointed out, your code may never be reached because we don't see where $id gets a value.  In your snippet it looks like it's undefined.

-You do a mysql_query, but you do not check that $edit_result is valid.

-You call mysql_result, with a row parameter of $i, which we don't see being assigned anywhere.  It should be an integer, starting with '0' for the first row in the result set.

 

Any one of these could be the problem.

 

Link to comment
Share on other sites

bugzy,

  There are any number of mysteries in your code that could account for your problem.

 

-As pointed out, your code may never be reached because we don't see where $id gets a value.  In your snippet it looks like it's undefined.

-You do a mysql_query, but you do not check that $edit_result is valid.

-You call mysql_result, with a row parameter of $i, which we don't see being assigned anywhere.  It should be an integer, starting with '0' for the first row in the result set.

 

Any one of these could be the problem.

 

 

Hello!

 

Thank you very much for the suggestion.

 

-I have posted where variable "id" is coming from the above post.

 

-As I'm using mysql_result and only getting 1 row, isn't the default value of $i will going to be "0" which mean the 1st row? Will I'm going to have a problem even if in mysql query I'm only asking for 1 row?

 

 

instead of using mysql_result what's the best way that you can suggest to fetch a data from a database? an example using my code above will going to be really helpful...

 

I'm just new so I'm still learning the right way to do it. :)

 

Thanks!

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.