Jump to content

Recommended Posts

I am new to php. I have come over from the darkside ASP/.net. My question how would i return the values from function to another page. My function is;

adminfunctions.php

[code]<?
require("connection.php");

function geteditcontent($inTable,$inId){
$sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$regionId=$row['regionID'];
$description=$row['description'];
$content=$row['content'];

return;
}

?>[/code]on my page I have

listcontent.php
[code]<?

include("../include/adminfunctions.php");
$fa =$_POST["fa"];
$id=$_POST["ItemId"];

  geteditcontent("webcontent_regions","$id");
?>

<form name="example" id="example" method="post" action="../include/formsubmit.php?mode=content">
<input type="hidden" name="id" value="<? echo $id; ?>" />
  <div align="left">
  <table width="100%" border="0">
  <tr>
    <td colspan="2" class="ListTableHeader" ><div align="center"><strong>Update Content</strong></div></td>
  </tr>
    <tr>
    <td class="Results" >Region Id:<? echo $id ?> <div align="left"></div>
Region Description:<? echo $description ?> <div align="left"></div></td>
  </tr>
 
  <tr>
    <td>
<textarea id="textarea1" name="test1" style="height: 100%; width: 100%;"><? echo $content ?>
</textarea></td>
  </tr>
</table>

  <input type="submit" name="Submit" value="Save Content">
  <input type="button" name="btnCancel" value="Cancel" onclick="JavaScript:history.back()" >
  </div>
</form>[/code]
(altered code)

adminfunctions.php
[code]
<?php
require("connection.php");

function geteditcontent($inTable,$inId){
$sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
  $info[] = $row;
}
return $info;
}
?>
[/code]

listcontent.php
[code]
<?php

include("../include/adminfunctions.php");
$fa =$_POST["fa"];
$id=$_POST["ItemId"];

  $info = geteditcontent("webcontent_regions","$id");
?>

<form name="example" id="example" method="post" action="../include/formsubmit.php?mode=content">
<input type="hidden" name="id" value="<? echo $id; ?>" />
  <div align="left">
  <table width="100%" border="0">
  <tr>
    <td colspan="2" class="ListTableHeader" ><div align="center"><strong>Update Content</strong></div></td>
  </tr>
    <tr>
    <td class="Results" >Region Id:<? echo $id ?> <div align="left"></div>
Region Description:<? echo $info[0]['description'] ?> <div align="left"></div></td>
  </tr>
 
  <tr>
    <td>
<textarea id="textarea1" name="test1" style="height: 100%; width: 100%;"><? echo $info[0]['content'] ?>
</textarea></td>
  </tr>
</table>

  <input type="submit" name="Submit" value="Save Content">
  <input type="button" name="btnCancel" value="Cancel" onclick="JavaScript:history.back()" >
  </div>
</form>[/code]


if you are expecting only one row returned, then you can change your function. remove the [] from $info (or just return $row instead of $info) and then in your form do $info['description'] instead of $info[0]['description'] etc..
my new code but still not working

adminfunctions.php

[code]<?
require("connection.php");

function geteditcontent($inTable,$inId){
$sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$info[] = $row;
}
return $info;
}

?>[/code]



listcontent.php

[code]<?
include("../include/adminfunctions.php");
$fa =$_POST["fa"];
$id=$_POST["ItemId"];

$info = geteditcontent("webcontent_regions","$id");
?>


<form name="example" id="example" method="post" action="../include/formsubmit.php?mode=content">
<input type="hidden" name="id" value="<? echo $id; ?>" />
  <div align="left">
  <table width="100%" border="0">
  <tr>
    <td colspan="2" class="ListTableHeader" ><div align="center"><strong>Update Content</strong></div></td>
  </tr>
    <tr>
    <td class="Results" >Region Id:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<? echo $id ?> <div align="left"></div>
Region Description:&nbsp;&nbsp;&nbsp;&nbsp;<? echo $info[0]['description'] ?> <div align="left"></div></td>
  </tr>
 
  <tr>
    <td>
<textarea id="textarea1" name="test1" style="height: 100%; width: 100%;"><? echo $info[0]['content'] ?>
</textarea></td>
  </tr>
</table>

  <input type="submit" name="Submit" value="Save Content">
  <input type="button" name="btnCancel" value="Cancel" onclick="JavaScript:history.back()" >
  </div>
</form>[/code]
add this to your function:

global $connection;

[code]
<?
require("connection.php");

function geteditcontent($inTable,$inId){
global $connection;
       
        $sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$info[] = $row;
}
return $info;
}

?>
[/code]
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.