Jump to content

php script not working mysql


paullanesra

Recommended Posts

hi i am having a problem with a php script. i have 3 files index.php,  home.html.php, form.html.php.

home.html.php is working fine, if has a form that is submitting fine but when it submits i get a problem. maybe someone can help me out please i would be grateful as i am new. the is nothing wrong with anything else mysql database is running fine and there is no problem with connection.

 

index.php (you can ignore what is commented out)

 

<?php

include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

//$_GET['id'] is categoryid

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

{

include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

 

$id = mysqli_real_escape_string($link, $_GET['id']);

$sql = "SELECT businessid FROM businesscategory WHERE

          categoryid LIKE '$id'";   

  $result = mysqli_query($link, $sql);

  if ($result !='')

  {

$businessid = mysqli_fetch_array($result);

  $sql = "SELECT content FROM business WHERE

          id LIKE '$businessid'"; 

  $result = mysqli_query($link, $sql); 

  }

  if ($result !='') 

  {

  $content = mysqli_fetch_array($result);

  include 'form.html.php';

exit();

  }

 

/*

// The basic SELECT statement

$select = 'SELECT content';

$from  = ' FROM business';

$where  = ' WHERE TRUE';

 

$id =  mysqli_real_escape_string($link, $_GET['id']);

if ($category != '') // An owner is selected

{

$where .= " AND categoryid='$categoryid";

}

 

$categoryid =  mysqli_real_escape_string($link,

$_GET['category']);

if ($categoryid != '') // A category is selected

{

$from  .= ' INNER JOIN businesscategory ON id = business';

$where .= " AND categoryid='$categoryid'";

}

 

$text = mysqli_real_escape_string($link, $_GET['text']);

if ($text != '') // Some search text was specified

{

$where .= " AND content LIKE '%$text%'";

}

 

$result = mysqli_query($link, $select . $from . $where);

if (!$result)

{

$error = 'Error fetching businesses.';

include 'error.html.php';

exit();

}

 

while ($row = mysqli_fetch_array($result))

{

$businesses[] = array('id' => $row['id'], 'text' => $row['content']);

}

 

include 'form.html.php';

exit();

 

  */

 

 

 

 

 

 

$result = mysqli_query($link, 'SELECT id, name FROM category ORDER BY name');

if (!$result)

{

$error = 'Error fetching categories: ' . mysqli_error($link);

include 'error.html.php';

exit();

}

 

while ($row = mysqli_fetch_array($result))

{

$categories[] = array('id' => $row['id'], 'text' => $row['name']);

}

 

include 'home.html.php';

?>

 

form.html.php

 

<?php include_once $_SERVER['DOCUMENT_ROOT'] .

'/includes/helpers.inc.php'; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

  <meta http-equiv="content-type" content="text/html; charset=windows-1250">

  <meta name="generator" content="PSPad editor, www.pspad.com">

  <title>Business</title>

  </head>

  <body>

      it works

      <?php echo $content; ?>

  </body>

</html>

 

 

Link to comment
Share on other sites

sorry, there is no error message at all, all i get is "it works" from the form.html.php page. the objective is to retieve data from database and echo it out on form.html.php i am guessing the problem is in the top half of the index.php script.

 

index.php (you can ignore what is commented out)

 

<?php
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
//$_GET['id'] is categoryid
if (isset($_GET['id']))
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

$id = mysqli_real_escape_string($link, $_GET['id']);
$sql = "SELECT businessid FROM businesscategory WHERE
          categoryid LIKE '$id'";    
  $result = mysqli_query($link, $sql);
  if ($result !='')
  {
$businessid = mysqli_fetch_array($result);
  $sql = "SELECT content FROM business WHERE
          id LIKE '$businessid'";  
  $result = mysqli_query($link, $sql);  
  }
  if ($result !='')  
  {
  $content = mysqli_fetch_array($result);
  include 'form.html.php';
exit();
  } 
}  

/*
// The basic SELECT statement
$select = 'SELECT content';
$from   = ' FROM business';
$where  = ' WHERE TRUE';

$id =  mysqli_real_escape_string($link, $_GET['id']);
if ($category != '') // An owner is selected
{
	$where .= " AND categoryid='$categoryid";
}

$categoryid =  mysqli_real_escape_string($link,
		$_GET['category']);
if ($categoryid != '') // A category is selected
{
	$from  .= ' INNER JOIN businesscategory ON id = business';
	$where .= " AND categoryid='$categoryid'";
}

$text = mysqli_real_escape_string($link, $_GET['text']);
if ($text != '') // Some search text was specified
{
	$where .= " AND content LIKE '%$text%'";
}

$result = mysqli_query($link, $select . $from . $where);
if (!$result)
{
	$error = 'Error fetching businesses.';
	include 'error.html.php';
	exit();
}

while ($row = mysqli_fetch_array($result))
{
	$businesses[] = array('id' => $row['id'], 'text' => $row['content']);
}

include 'form.html.php';
exit();
}  
  
  */
  
  
  
  
  
  
$result = mysqli_query($link, 'SELECT id, name FROM category ORDER BY name');
if (!$result)
{
$error = 'Error fetching categories: ' . mysqli_error($link);
include 'error.html.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
$categories[] = array('id' => $row['id'], 'text' => $row['name']);
}

include 'home.html.php';
?>

 

form.html.php

<?php include_once $_SERVER['DOCUMENT_ROOT'] .
	'/includes/helpers.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>Business</title>
  </head>
  <body>
       it works
       <?php echo $content; ?>
  </body>
</html>

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.