function calling problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nadeem14375
Forum Newbie
Posts: 23
Joined: Sat Oct 30, 2010 2:11 am

function calling problem

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: function calling problem

Post by social_experiment »

On the book.php you will have something similar to the example below

Code: Select all

<?php
 show_contacts();
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply