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.
function calling problem
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: function calling problem
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