sql error - not a valid result resource.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

In the following code I am getting the following error. Can somebody help. changing $result to another variable like $result1 doesnot help.

if(!($conn=mysql_connect("localhost","odbc","")))
  alert("could not connect odbc to mysql-server localhost!\n".mysql_error());
if(!($select=mysql_select_db("multimedia")))
  alert("could not change to database multimedia".mysql_error());

function script_det()
{
 global $window2;
 global $box;
 global $i;

// $result = "";

 $window2->set_title('Details of the Script');

 if(!isset($scrdetbox2))
 {
  $scrdetbox2 = &new GtkVBox();
  $scrdetbox2->set_homogeneous(true);
  $window2->add($scrdetbox2);
  $box->pack_start($scrdetbox2, false, false, 10);
  $scrdetbox2->show();

  $label1 = &new GtkLabel('Fill the Script Name');
  $scrdetbox2->pack_start($label1,true,true,10);
  $label1->show();

  $box2 = &new GtkHBox(False,5);
  $box2->set_homogeneous(true);
  $box2->set_border_width(20);
  $scrdetbox2->pack_start($box2);
  $box2->show();

  $label2 = &new GtkLabel('Script Name : ');
  $box2->pack_start($label2,true,true,10);
  $label2->show();
  $entry1 = &new GtkEntry();
  $entry1->set_editable(true);
  $box2->pack_start($entry1,true,true,10);
  $entry1->show();

  $box3 = &new GtkHBox(False,5);
  $box3->set_homogeneous(true);
  $box3->set_border_width(20);
  $scrdetbox2->pack_start($box3);
  $box3->show();

  $label3 = &new GtkLabel('Script ID :');
  $box3->pack_start($label3);
  $label3->show();
  $entry2 = &new GtkEntry();
  $entry2->set_editable(false);
  $box3->pack_start($entry2,true,true,10);
  $entry2->show();

  $box4 = &new GtkHBox(False,5);
  $box4->set_homogeneous(true);
  $box4->set_border_width(20);
  $scrdetbox2->pack_start($box4,true,true,10);
  $box4->show();

  $label4 = &new GtkLabel('Name of the Author :');
  $box4->pack_start($label4);
  $label4->show();
  $entry3 = &new GtkEntry();
  $entry3->set_editable(false);
  $box4->pack_start($entry3,true,true,10);
  $entry3->show();

  $box5 = &new GtkHBox(False,5);
  $box5->set_homogeneous(true);
  $box5->set_border_width(20);
  $scrdetbox2->pack_start($box5,true,true,10);
  $box5->show();

  $label5 = &new GtkLabel('Authors Orgainsation :');
  $box5->pack_start($label5,true,true,10);
  $label5->show();
  $entry4 = &new GtkEntry();
  $entry4->set_editable(false);
  $box5->pack_start($entry4,true,true,10);
  $entry4->show();

  $box6 = &new GtkHBox(False,5);
  $box6->set_homogeneous(true);
  $box6->set_border_width(20);
  $scrdetbox2->pack_start($box6,true,true,10);
  $box6->show();
  $label6 = &new GtkLabel('Script Description :');
  $box6->pack_start($label6,true,true,10);
  $label6->show();
  $entry5 = &new GtkEntry();
  $entry5->set_editable(false);
  $box6->pack_start($entry5,true,true,10);
  $entry5->show();

  $box7 = &new GtkHBox(False,6);
  $box7->set_homogeneous(true);
  $box7->set_border_width(20);
  $scrdetbox2->pack_start($box7,true,true,10);
  $box7->show();
  $label7 = &new GtkLabel('Date of Entry:');
  $box7->pack_start($label7,true,true,10);
  $label7->show();
  $entry6 = &new GtkEntry();
  $entry6->set_editable(false);
  $box7->pack_start($entry6,true,true,10);
  $entry6->show();

  $box8 = &new GtkHButtonBox();
  $box8->set_layout(GTK_BUTTONBOX_SPREAD);
  $scrdetbox2->pack_start($box8,true,true,10);
  $box8->show();
  $button1 = &new GtkButton('Search');
  $button1->connect_object('clicked', 'srch_scr',$entry1,$entry2,$entry3,$entry4,$entry5,$entry6);
  $box8->pack_start($button1);
  $button1->show();
  $button2 = &new GtkButton('Close');
  $button2->connect_object('clicked', 'hide_box', $scrdetbox2);
  $box8->pack_start($button2);
  $button2->show();

  $button3 = &new GtkButton('Next');
  $button3->connect_object('clicked', 'srch_scr_next',$entry1,$entry2,$entry3,$entry4,$entry5,$entry6);
  $box8->pack_start($button3);
  $button3->show();
  $button4 = &new GtkButton('Clear');
  $button4->connect_object('clicked', 'clr_scr',$entry1,$entry2,$entry3,$entry4,$entry5,$entry6);
  $box8->pack_start($button4);
  $button4->show();
 }
 else
  $scrdetbox2->show();

 function srch_scr($widget1,$widget2,$widget3,$widget4,$widget5,$widget6)
 {
  global $i;
  global $conn;
  global $result;

  $name1 = $widget1->get_text();
  $query = "SELECT name,id,author,organisation,descpr,entry FROM script_det WHERE name REGEXP '^$name1'";
  $result = mysql_query($query,$conn);

  $aff=mysql_num_rows($result);
  if($aff!="0")
  {
   if($i<1)
   {
    list($name,$scrid,$auth,$org,$scrdesc,$dat) = mysql_fetch_row($result);
    $widget1->set_text($name);
    $widget2->set_text($scrid);
    $widget3->set_text($auth);
    $widget4->set_text($org);
    $widget5->set_text($scrdesc);
    $widget6->set_text($dat);
    $i++;
   }
   else
   {
    $message=msg_box ("Message", 0, "Use Next Button to scroll", "OK", 1);
    $message->show;
   }
  }
  else
  {
   $message=msg_box ("Message", 0, "No matches found", "O! K", 1);
   $message->show;
  }

  return $result;
 }

 function srch_scr_next($widget1,$widget2,$widget3,$widget4,$widget5,$widget6)
 {
  global $i;
  global $flag;
  global $conn;
  global $result;

 /* $name1 = $widget1->get_text();
  $query = "SELECT id,descpr,path,entry FROM script_det where name regexp '^$name1'";
  $result = mysql_query($query,$conn);*/

  if($i < mysql_num_rows($result))
  {
   list($name,$scrid,$auth,$org,$scrdesc,$dat) = mysql_fetch_row($result);
   $widget1->set_text($name);
   $widget2->set_text($scrid);
   $widget3->set_text($auth);
   $widget4->set_text($org);
   $widget5->set_text($scrdesc);
   $widget6->set_text($dat);
   $i++;
  }
  else
  {
   $message=msg_box ("Message", 0, "No more results. Use search button for New search", "OK", 1);
   $message->show;
   $widget1->delete_text(0,-1);
   $widget2->delete_text(0,-1);
   $widget3->delete_text(0,-1);
   $widget4->delete_text(0,-1);
   $widget5->delete_text(0,-1);
   ! ;$widget6->delete_text(0,-1);
   $i=0;
  }

  return true;
 }

 function clr_scr($widget1,$widget2,$widget3,$widget4,$widget5,$widget6)
 {
  $widget1->delete_text(0,-1);
  $widget2->delete_text(0,-1);
  $widget3->delete_text(0,-1);
  $widget4->delete_text(0,-1);
  $widget5->delete_text(0,-1);
  $widget6->delete_text(0,-1);
  $i=0;
 }

}

function image_det()
{
 global $j;
 global $window2;
 global $box;

 $window2->set_title('Details of the Image');
 if(!isset($imgdetbox))
 {
  $imgdetbox = &new GtkVBox();
  $imgdetbox->set_homogeneous(true);
  $window2->add($imgdetbox);
  $box->pack_start($imgdetbox, false, false, 10);
  $imgdetbox->show();

  $label1 = &new GtkLabel('Fill the name of Image');
  $imgdetbox->pack_start($label1,true,true,10);
  $label1->show();

  $box2 = &new GtkHBox(False,5);
  $box2->set_homogeneous(true);
  $box2->set_border_width(20);
  $imgdetbox->pack_start($box2);
  $box2->show();

  $label2 = &new GtkLabel('Image Name : ');
  $box2->pack_start($label2,true,true,10);
  $label2->show();
  $entry1 = &new GtkEntry();
  $entry1->set_editable(true);
  $box2->pack_start($entry1,true,true,10);
  $entry1->show();

  $box3 = &new GtkHBox(False,5);
  $box3->set_homogeneous(true);
  $box3->set_border_width(20);
  $imgdetbox->pack_start($box3);
  $box3->show();

  $label3 = &new GtkLabel('Image ID :');
  $box3->pack_start($label3);
  $label3->show();
  $entry2 = &new GtkEntry();
  $entry2->set_editable(false);
  $box3->pack_start($entry2,true,true,10);
  $entry2->show();

  $box4 = &new GtkHBox(False,4);
  $box4->set_homogeneous(true);
  $box4->set_border_width(20);
  $imgdetbox->pack_start($box4,true,true,10);
  $box4->show();
  $label4 = &new GtkLabel('Image Description :');
  $box4->pack_start($label4,true,true,10);
  $label4->show();
  $entry3 = &new GtkEntry();
  $entry3->set_editable(false);
  $box4->pack_start($entry3,true,true,10);
  $entry3->show();

  $box5 = &new GtkHBox(False,5);
  $box5->set_homogeneous(true);
  $box5->set_border_width(20);
  $imgdetbox->pack_start($box5,true,true,10);
  $box5->show();
  $label5 = &new GtkLabel('Path of the Image file :');
  $box5->pack_start($label5,true,true,10);
  $label5->show();
  $entry4 = &new GtkEntry();
  $entry4->set_editable(false);
  $box5->pack_start($entry4,true,true,10);
  $entry4->show();

  $box6 = &new GtkHBox(False,6);
  $box6->set_homogeneous(true);
  $box6->set_border_width(20);
  $imgdetbox->pack_start($box6,true,true,10);
  $box6->show();
  $label6 = &new GtkLabel('Date of entry :');
  $box6->pack_start($label6,true,true,10);
  $label6->show();
  $entry5 = &new GtkEntry();
  $entry5->set_editable(false);
  $box6->pack_start($entry5,true,true,10);
  $entry5->show();

  $box7 = &new GtkHButtonBox();
  $box7->set_layout(GTK_BUTTONBOX_SPREAD);
  $imgdetbox->pack_start($box7,true,true,10);
  $box7->show();
  $button1 = &new GtkButton('Search');
  $button1->connect_object('clicked', 'srch_img',$entry1,$entry2,$entry3,$entry4,$entry5);
  $box7->pack_start($button1);
  $button1->show();
  $button2 = &new GtkButton('Close');
  $button2->connect_object('clicked', 'hide_box', $imgdetbox);
  $box7->pack_start($button2);
  $button2->show();
  $button3 = &new GtkButton('Next');
  $button3->connect_object('clicked', 'srch_img_next',$entry1,$entry2,$entry3,$entry4,$entry5);
  $box7->pack_start($button3);
  $button3->show();
  $button4 = &new GtkButton('Clear');
  $butto! n4->connect_object('clicked', 'clr_img',$entry1,$entry2,$entry3,$entry4,$entry5);
  $box7->pack_start($button4);
  $button4->show();
 }
 else
  $imgdetbox2->show();

 function srch_img($widget1,$widget2,$widget3,$widget4,$widget5)
 {
  global $j;
  global $flag;
  global $result;
  global $conn;

  $name1 = $widget1->get_text();
  $query1 = "SELECT name,id,descpr,path,entry FROM image WHERE name REGEXP '^$name1'";
  $result = mysql_query($query1,$conn);

  $aff=mysql_num_rows($result);

  if($aff!="0")
  {
   if($j < 1)
   {
    list($name,$imgid,$imgdesc,$path,$dat) = mysql_fetch_row($result);

    $widget1->set_text($name);
    $widget2->set_text($imgid);
    $widget3->set_text($imgdesc);
    $widget4->set_text($path);
    $widget5->set_text($dat);
    $j++;
   }
   else
   {
    $message=msg_box ("Message", 0, "Use Next Button to scroll", "OK", 1);
    $message->show;
   }
  }
  else
  {
   $message=msg_box ("Message", 0, "No matches found", "OK", 1);
   $message->show;
  }

  return true;
 }

 function srch_img_next($widget1,$widget2,$widget3,$widget4,$widget5)
 {
  global $i;
  global $flag;
  global $result;

  //$aff=mysql_num_rows($result1);
  if($j < mysql_num_rows($result))
  {
   list($name,$imgid,$desc,$path,$dat) = mysql_fetch_row($result);

   $widget1->set_text($name);
   $widget2->set_text($imgid);
   $widget3->set_text($desc);
   $widget4->set_text($path);
   $widget5->set_text($dat);
   $j++;
  }
  else
  {
   $message=msg_box ("Message", 0, "No more results. Use Search button for New search.", "OK", 1);
   $message->show;
   $widget1->delete_text(0,-1);
   $widget2->delete_text(0,-1);
   $widget3->delete_text(0,-1);
   $widget4->delete_text(0,-1);
   $widget5->delete_text(0,-1);
   $j=0;
  }

  return true;
 }

 function clr_img($widget1,$widget2,$widget3,$widget4,$widget5)
 {
  $widget1->delete_text(0,-1);
  $widget2->delete_text(0,-1);
  $widget3->delete_text(0,-1);
  $widget4->delete_text(0,-1);
  $widget5->delete_text(0,-1);
  $j=0;
 }
}

When I am running the first function ie srch_scr() it is running well but in the second case ie search for image(srch_img()), I am getting error saying $result is not a valid MySql result resource. I am relatively new to php. Is it that we cannot run two queries on the same file?? Please help.

Thanx.

Shalabh Raizada.


My Presence
Click onthe image to chat with me

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux