Page 1 of 1

function calling problem

Posted: Wed Jul 06, 2011 2:51 pm
by nadeem14375
Dear all,

I am new to php. I want to place buttons / links on page to insert (add), delete, and display on one page. for display I have the following function in book.php.

<?php
session_start();
include('config.php'); // for mysql connection

$page = 'index.php';

function show_contacts()
{
$get = mysql_query("SELECT name, num FROM phonebook");

if ($get==0)
{
echo 'The phone book is empty.';
}
else
{
while ($get_row = mysql_fetch_assoc($get))
{
echo $get_row['name'].'</br>';
}
}
header( 'location:'.$page);
}
?>

I want to call this function from a link on index.php. here is my index.php.

<?php
include'book.php';
?>
<h1> Phone Book </h1>
<form action="add_contacts.php" method="POST">
Contact Name: <input name="name" type="text" />
Number: <input name="num" type="text" />
<input type="submit" value="Add"/>

<a href="book.php"> Show Contacts </a>

show_contacts();
</form>

I am new to php, and don't know what to do and how to call a function, and what kind of strategy to adopt?

please guide me.

Re: function calling problem

Posted: Wed Jul 06, 2011 4:40 pm
by social_experiment
On the book.php you will have something similar to the example below

Code: Select all

<?php
 show_contacts();
?>