0

I need helping fetching the URLs I have stored in my database and opening a new page.

I am using a dynamic drop down menu for users to select a category and company. Once a user selects category(parent table) the child table opens up. The user then can click the submit button to open that page.

This is my child table

CREATE TABLE `companies` (
`comp_id` int(10) unsigned NOT NULL auto_increment,
`comp_name` text NOT NULL,
`comp_cat_id` mediumint(8) unsigned NOT NULL,
`comp_url` varchar(512) NOT NULL,
PRIMARY KEY (`comp_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=128;

My form code is

<form id="form1" name="form1" method="post" action="">
        <select size=1 name="Parent" id="Parent" onchange="WA_FilterAndPopulateSubList(Child_WAJA,MM_findObj('Parent'),MM_findObj('Child'),0,0,false,': ')">
          <option value="">Please Select Below</option>
          <?php
do {  
?>
          <option value="<?php echo $row_Parent['cat_id']?>"><?php echo $row_Parent['cat_name']?></option>
          <?php
} while ($row_Parent = mysql_fetch_assoc($Parent));
  $rows = mysql_num_rows($Parent);
  if($rows > 0) {
      mysql_data_seek($Parent, 0);
	  $row_Parent = mysql_fetch_assoc($Parent);
  }
?>
        </select>
      </form>
      <p>&nbsp;</p>
    </div>
    
    
    <div class="stepone">
    <h3> Step Two:</h3>
    <p> Choose a Company <strong><em>(Optional) </em></strong></p>
    <form id="form2" name="form2" method="post" action="">
      <select  size=1 name="Child" id="Child">
        <option>Please Select a Company</option>
      </select>
      <input type="image" src="images/global images/gobutton.png" name="go" id="go" value="Submit" />
    </form>
    <p>&nbsp;</p>
    </div>

I cant figure out what PHP code I need to put in the action to call my 'comp_url' row and open a new page.

I have come up with

action="<?php echo <a href={'$row_Child['comp_url']}'/a>?>">

But it doesn't work

Please let me know if you need more information.

I am new to all this.

Thanks again!!

2
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by cwarn23
0

The action= only works in the <form> tag and would be as follows

action="<?php echo $row_Child['comp_url']; ?>">
0

I did that but then I get this error message

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/content/h/o/m/homepagesdfw/html/mysavings.php on line 395

I used webassist for my dynamic dropdowns and it put this code (line 392-396)

<?php
mysql_free_result($Parent);

mysql_free_result($Child);
?>

Removing that code doesn't fix anything.

I don't know if this will help, its the entire code for the dropdown.

<?php require_once('Connections/vendorshomepages.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_vendorshomepages, $vendorshomepages);
$query_Parent = "SELECT * FROM categories";
$Parent = mysql_query($query_Parent, $vendorshomepages) or die(mysql_error());
$row_Parent = mysql_fetch_assoc($Parent);
$totalRows_Parent = mysql_num_rows($Parent);

mysql_select_db($database_vendorshomepages, $vendorshomepages);
$query_Child = "SELECT * FROM companies";
$Child = mysql_query($query_Child, $vendorshomepages) or die(mysql_error());
$row_Child = mysql_fetch_assoc($Child);
$totalRows_Child = mysql_num_rows($Child);


<?php
if ($row_Child)     {
  echo "<SC" . "RIPT>\n";
  echo "var WAJA = new Array();\n";

  $oldmainid = 0;
  $newmainid = $row_Child["comp_cat_id"];
  if ($oldmainid == $newmainid)    {
    $oldmainid = "";
  }
  $n = 0;
  while ($row_Child)     {
    if ($oldmainid != $newmainid)     {
      echo "WAJA[".$n."] = new Array();\n";
      echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";
      $m = 1;
    }

    echo "WAJA[".$n."][".$m."] = new Array();\n";
    echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_Child["comp_id"])."'".";\n";
    echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_Child["comp_name"])."'".";\n";

    $m++;
    if ($oldmainid == 0)      {
      $oldmainid = $newmainid;
    }
    $oldmainid = $newmainid;
    $row_Child = mysql_fetch_assoc($Child);
    if ($row_Child)     {
      $newmainid = $row_Child["comp_cat_id"];
    }
    if ($oldmainid != $newmainid)     {
      $n++;
    }
  }

  echo "var Child_WAJA = WAJA;\n";
  echo "WAJA = null;\n";
  echo "</SC" . "RIPT>\n";
}
function WA_DD_Replace($startStr)  {
  $startStr = str_replace("'", "|WA|", $startStr);
  $startStr = str_replace("\\", "\\\\", $startStr);
  $startStr = preg_replace("/[\r\n]{1,}/", " ", $startStr);
  return $startStr;
}
?>


<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function WA_ClientSideReplace(theval,findvar,repvar)     {
  var retval = "";
  while (theval.indexOf(findvar) >= 0)    {
    retval += theval.substring(0,theval.indexOf(findvar));
    retval += repvar;
    theval = theval.substring(theval.indexOf(findvar) + String(findvar).length);
  }
  retval += theval;
  if (retval == "" && theval.indexOf(findvar) < 0)    {
    retval = theval;
  }
  return retval;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function WA_UnloadList(thelist,leavevals,bottomnum)    {
  while (thelist.options.length > leavevals+bottomnum)     {
    if (thelist.options[leavevals])     {
      thelist.options[leavevals] = null;
    }
  }
  return leavevals;
}

function WA_FilterAndPopulateSubList(thearray,sourceselect,targetselect,leaveval,bottomleave,usesource,delimiter)     {
  if (bottomleave > 0)     {
    leaveArray = new Array(bottomleave);
    if (targetselect.options.length >= bottomleave)     {
      for (var m=0; m<bottomleave; m++)     {
        leavetext = targetselect.options[(targetselect.options.length - bottomleave + m)].text;
        leavevalue  = targetselect.options[(targetselect.options.length - bottomleave + m)].value;
        leaveArray[m] = new Array(leavevalue,leavetext);
      }
    }
    else     {
      for (var m=0; m<bottomleave; m++)     {
        leavetext = "";
        leavevalue  = "";
        leaveArray[m] = new Array(leavevalue,leavetext);
      }
    }
  }  
  startid = WA_UnloadList(targetselect,leaveval,0);
  mainids = new Array();
  if (usesource)    maintext = new Array();
  for (var j=0; j<sourceselect.options.length; j++)     {
    if (sourceselect.options[j].selected)     {
      mainids[mainids.length] = sourceselect.options[j].value;
      if (usesource)     maintext[maintext.length] = sourceselect.options[j].text + delimiter;
    }
  }
  for (var i=0; i<thearray.length; i++)     {
    goodid = false;
    for (var h=0; h<mainids.length; h++)     {
      if (thearray[i][0] == mainids[h])     {
        goodid = true;
        break;
      }
    }
    if (goodid)     {
      theBox = targetselect;
      theLength = parseInt(theBox.options.length);
      theServices = thearray[i].length + startid;
      var l=1;
      for (var k=startid; k<theServices; k++)     {
        if (l == thearray[i].length)     break;
        theBox.options[k] = new Option();
        theBox.options[k].value = thearray[i][l][0];
        if (usesource)     theBox.options[k].text = maintext[h] + WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
        else               theBox.options[k].text = WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
        l++;
      }
      startid = k;
    }
  }
  if (bottomleave > 0)     {
    for (var n=0; n<leaveArray.length; n++)     {
      targetselect.options[startid+n] = new Option();
      targetselect.options[startid+n].value = leaveArray[n][0];
      targetselect.options[startid+n].text  = leaveArray[n][1];
    }
  }
  for (var l=0; l < targetselect.options.length; l++)    {
    targetselect.options[l].selected = false;
  }
  if (targetselect.options.length > 0)     {
    targetselect.options[0].selected = true;
  }
}
>
  
<h6> Follow these simple steps to get started!</h6>
  
 

  <div id="steps">
  
    <div class="stepone">
      <h4> Step One: </h4>
      <p>Choose a Category</p>
      <form id="form1" name="form1" method="post" action="">
        <select size=1 name="Parent" id="Parent" onchange="WA_FilterAndPopulateSubList(Child_WAJA,MM_findObj('Parent'),MM_findObj('Child'),0,0,false,': ')">
          <option value="">Please Select Below</option>
          <?php
do {  
?>
          <option value="<?php echo $row_Parent['cat_id']?>"><?php echo $row_Parent['cat_name']?></option>
          <?php
} while ($row_Parent = mysql_fetch_assoc($Parent));
  $rows = mysql_num_rows($Parent);
  if($rows > 0) {
      mysql_data_seek($Parent, 0);
	  $row_Parent = mysql_fetch_assoc($Parent);
  }
?>
        </select>
      </form>
      <p>&nbsp;</p>
    </div>
    
    
    <div class="stepone">
    <h3> Step Two:</h3>
    <p> Choose a Company <strong><em>(Optional) </em></strong></p>
    <form id="form2" name="form2" method="post" action="<?php echo $row_Child['comp_url']; ?>">
      <select  size=1 name="Child" id="Child">
        <option>Please Select a Company</option>
      </select>
      <input type="image" src="images/global images/gobutton.png" name="go" id="go" value="Submit" />
    </form>
    <p>&nbsp;</p>
    </div>


</body>
</html>
<?php
mysql_free_result($Parent);

mysql_free_result($Child);
?>
0

It means you have an error in your mysql syntax. Try in addition the following

<?php
mysql_free_result($Parent) or die(mysql_error());
 
mysql_free_result($Child) or die(mysql_error());
?>
0

It means you have an error in your mysql syntax. Try in addition the following

<?php
mysql_free_result($Parent) or die(mysql_error());
 
mysql_free_result($Child) or die(mysql_error());
?>

It means you have an error in your mysql syntax. Try in addition the following

<?php
mysql_free_result($Parent) or die(mysql_error());
 
mysql_free_result($Child) or die(mysql_error());
?>

That doesn't work.

the error keeps showing and it doesn't open a new page.

any other ideas?

Did I store the url the wrong way in mySQL?

CREATE TABLE `companies` (
`comp_id` int(10) unsigned NOT NULL auto_increment,
`comp_name` text NOT NULL,
`comp_cat_id` mediumint(8) unsigned NOT NULL,
`comp_url` varchar(512) NOT NULL,
PRIMARY KEY (`comp_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=128 ;


INSERT INTO `companies` VALUES(1, 'View All', 1, 'http://www.homepagesdfw.com/airconditionheating');

I'm new to all this so I'm not 100% on all the functions etc.

0

Then Perhaps you could try deleting the lines with the function mysql_free_result(). I have heard that it uses more cpu to free the result instead of ignoring the result.

0

Then Perhaps you could try deleting the lines with the function mysql_free_result(). I have heard that it uses more cpu to free the result instead of ignoring the result.

When I remove that it just doesn't give me an error. The page reloads and the dynamic dropdown menu stops working.

see yourself

http://homepagesdfw.com/mysavings

use username
tester

password
tester

0

Well generally that error is a problem with the sql syntax. Could you add after mysql_query() the term " or die(mysql_error());" So it would be like

$result = mysql_query($query) or die(mysql_error());

That usually picks out the obvious errors and make sure the mysql variable is a valid result. For example if you assign $result a string or integer then it will nolonger be a valid mysql query. So let us know of the result with the above modification if there are any additional errors reported.

0

Well generally that error is a problem with the sql syntax. Could you add after mysql_query() the term " or die(mysql_error());" So it would be like

$result = mysql_query($query) or die(mysql_error());

That usually picks out the obvious errors and make sure the mysql variable is a valid result. For example if you assign $result a string or integer then it will nolonger be a valid mysql query. So let us know of the result with the above modification if there are any additional errors reported.

where exactly do i need to put that script? Because its not working.

I re-inserted mysql_free_result()

The thing is the url in the browser never changes.

0

where exactly do i need to put that script? Because its not working.

I re-inserted mysql_free_result()

The thing is the url in the browser never changes.

If you add or die(mysql_error()); after the mysql_query() then it will show the true error.

0

If you add or die(mysql_error()); after the mysql_query() then it will show the true error.

Where do I insert the code

$result = mysql_query($query) or die(mysql_error());

Do I put in the body or put it before/after the code that is giving me a problem.

<?php echo $row_Child['comp_url']; ?>

When I put it in the body by itself it says Query empty

Can someone explain this more to me? Where exactly do I insert it?

0

For crying out loud just use the following

<?php require_once('Connections/vendorshomepages.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_vendorshomepages, $vendorshomepages);
$query_Parent = "SELECT * FROM categories";
$Parent = mysql_query($query_Parent, $vendorshomepages) or die(mysql_error());
$row_Parent = mysql_fetch_assoc($Parent);
$totalRows_Parent = mysql_num_rows($Parent);

mysql_select_db($database_vendorshomepages, $vendorshomepages);
$query_Child = "SELECT * FROM companies";
$Child = mysql_query($query_Child, $vendorshomepages) or die(mysql_error());
$row_Child = mysql_fetch_assoc($Child);
$totalRows_Child = mysql_num_rows($Child);


<?php
if ($row_Child)     {
  echo "<SC" . "RIPT>\n";
  echo "var WAJA = new Array();\n";

  $oldmainid = 0;
  $newmainid = $row_Child["comp_cat_id"];
  if ($oldmainid == $newmainid)    {
    $oldmainid = "";
  }
  $n = 0;
  while ($row_Child)     {
    if ($oldmainid != $newmainid)     {
      echo "WAJA[".$n."] = new Array();\n";
      echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";
      $m = 1;
    }

    echo "WAJA[".$n."][".$m."] = new Array();\n";
    echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_Child["comp_id"])."'".";\n";
    echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_Child["comp_name"])."'".";\n";

    $m++;
    if ($oldmainid == 0)      {
      $oldmainid = $newmainid;
    }
    $oldmainid = $newmainid;
    $row_Child = mysql_fetch_assoc($Child);
    if ($row_Child)     {
      $newmainid = $row_Child["comp_cat_id"];
    }
    if ($oldmainid != $newmainid)     {
      $n++;
    }
  }

  echo "var Child_WAJA = WAJA;\n";
  echo "WAJA = null;\n";
  echo "</SC" . "RIPT>\n";
}
function WA_DD_Replace($startStr)  {
  $startStr = str_replace("'", "|WA|", $startStr);
  $startStr = str_replace("\\", "\\\\", $startStr);
  $startStr = preg_replace("/[\r\n]{1,}/", " ", $startStr);
  return $startStr;
}
?>


<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function WA_ClientSideReplace(theval,findvar,repvar)     {
  var retval = "";
  while (theval.indexOf(findvar) >= 0)    {
    retval += theval.substring(0,theval.indexOf(findvar));
    retval += repvar;
    theval = theval.substring(theval.indexOf(findvar) + String(findvar).length);
  }
  retval += theval;
  if (retval == "" && theval.indexOf(findvar) < 0)    {
    retval = theval;
  }
  return retval;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function WA_UnloadList(thelist,leavevals,bottomnum)    {
  while (thelist.options.length > leavevals+bottomnum)     {
    if (thelist.options[leavevals])     {
      thelist.options[leavevals] = null;
    }
  }
  return leavevals;
}

function WA_FilterAndPopulateSubList(thearray,sourceselect,targetselect,leaveval,bottomleave,usesource,delimiter)     {
  if (bottomleave > 0)     {
    leaveArray = new Array(bottomleave);
    if (targetselect.options.length >= bottomleave)     {
      for (var m=0; m<bottomleave; m++)     {
        leavetext = targetselect.options[(targetselect.options.length - bottomleave + m)].text;
        leavevalue  = targetselect.options[(targetselect.options.length - bottomleave + m)].value;
        leaveArray[m] = new Array(leavevalue,leavetext);
      }
    }
    else     {
      for (var m=0; m<bottomleave; m++)     {
        leavetext = "";
        leavevalue  = "";
        leaveArray[m] = new Array(leavevalue,leavetext);
      }
    }
  }  
  startid = WA_UnloadList(targetselect,leaveval,0);
  mainids = new Array();
  if (usesource)    maintext = new Array();
  for (var j=0; j<sourceselect.options.length; j++)     {
    if (sourceselect.options[j].selected)     {
      mainids[mainids.length] = sourceselect.options[j].value;
      if (usesource)     maintext[maintext.length] = sourceselect.options[j].text + delimiter;
    }
  }
  for (var i=0; i<thearray.length; i++)     {
    goodid = false;
    for (var h=0; h<mainids.length; h++)     {
      if (thearray[i][0] == mainids[h])     {
        goodid = true;
        break;
      }
    }
    if (goodid)     {
      theBox = targetselect;
      theLength = parseInt(theBox.options.length);
      theServices = thearray[i].length + startid;
      var l=1;
      for (var k=startid; k<theServices; k++)     {
        if (l == thearray[i].length)     break;
        theBox.options[k] = new Option();
        theBox.options[k].value = thearray[i][l][0];
        if (usesource)     theBox.options[k].text = maintext[h] + WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
        else               theBox.options[k].text = WA_ClientSideReplace(thearray[i][l][1],"|WA|","'");
        l++;
      }
      startid = k;
    }
  }
  if (bottomleave > 0)     {
    for (var n=0; n<leaveArray.length; n++)     {
      targetselect.options[startid+n] = new Option();
      targetselect.options[startid+n].value = leaveArray[n][0];
      targetselect.options[startid+n].text  = leaveArray[n][1];
    }
  }
  for (var l=0; l < targetselect.options.length; l++)    {
    targetselect.options[l].selected = false;
  }
  if (targetselect.options.length > 0)     {
    targetselect.options[0].selected = true;
  }
}
>
  
<h6> Follow these simple steps to get started!</h6>
  
 

  <div id="steps">
  
    <div class="stepone">
      <h4> Step One: </h4>
      <p>Choose a Category</p>
      <form id="form1" name="form1" method="post" action="">
        <select size=1 name="Parent" id="Parent" onchange="WA_FilterAndPopulateSubList(Child_WAJA,MM_findObj('Parent'),MM_findObj('Child'),0,0,false,': ')">
          <option value="">Please Select Below</option>
          <?php
do {  
?>
          <option value="<?php echo $row_Parent['cat_id']?>"><?php echo $row_Parent['cat_name']?></option>
          <?php
} while ($row_Parent = mysql_fetch_assoc($Parent));
  $rows = mysql_num_rows($Parent);
  if($rows > 0) {
      mysql_data_seek($Parent, 0);
	  $row_Parent = mysql_fetch_assoc($Parent);
  }
?>
        </select>
      </form>
      <p>&nbsp;</p>
    </div>
    
    
    <div class="stepone">
    <h3> Step Two:</h3>
    <p> Choose a Company <strong><em>(Optional) </em></strong></p>
    <form id="form2" name="form2" method="post" action="<?php echo $row_Child['comp_url']; ?>">
      <select  size=1 name="Child" id="Child">
        <option>Please Select a Company</option>
      </select>
      <input type="image" src="images/global images/gobutton.png" name="go" id="go" value="Submit" />
    </form>
    <p>&nbsp;</p>
    </div>


</body>
</html>
<?php
die(mysql_error());
mysql_free_result($Parent);

mysql_free_result($Child);
?>

And the new errors are?

Edited by cwarn23: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.