Jump to content

Links not working


munky334

Recommended Posts

: Hi there , I'm hoping that someone will be able to help me with a

: problem that I'm experiencing with this PHP script.

:

: The code itself isn’t working for me. When I copy and paste it into

: a php file and upload I get the main table but the edit and remove

: links do not show up. The add contacts link also doesn't work. I'm

: not to sure where I'm going wrong? Perhaps someone can advise.

:

: I'm using PHP version 5.2.6 with standard wamp server configuration

:

: Thanking you in advance

:

:

: <html>

: <head>

: <title>Address Book</title>

: </head>

: <body>

: <?php

: // Connects to your Database

: mysql_connect("localhost", "root") or die(mysql_error());

: mysql_select_db("address") or die(mysql_error());

: // Add a Contact

: if ( $mode=="add")

: {

: Print '<h2>Add Contact</h2>

: <p>

: <form action=';

: echo $PHP_SELF;

: Print '

: method=post>

: <table>

: <tr><td>Name:</td><td><input type="text" name="name" /></td></tr>

: <tr><td>Phone:</td><td><input type="text" name="phone" /></td></tr>

: <tr><td>Email:</td><td><input type="text" name="email" /></td></tr>

: <tr><td colspan="2" align="center"><input type="submit" /></td></tr>

: <input type=hidden name=mode value=added>

: </table>

: </form> <p>';

: }

:

: if ( $mode=="added")

: {

: mysql_query ("INSERT INTO address (name, phone, email) VALUES

: ('$name', '$phone', '$email')");

: }

: //Updating data

: if ( $mode=="edit")

: {

: Print '<h2>Edit Contact</h2>

: <p>

: <form action=';

: echo $PHP_SELF;

: Print '

: method=post>

: <table>

: <tr><td>Name:</td><td><input type="text" value="';

: Print $name;

: print '" name="name" /></td></tr>

: <tr><td>Phone:</td><td><input type="text" value="';

: Print $phone;

: print '" name="phone" /></td></tr>

: <tr><td>Email:</td><td><input type="text" value="';

: Print $email;

: print '" name="email" /></td></tr>

: <tr><td colspan="2" align="center"><input type="submit" /></td></tr>

: <input type=hidden name=mode value=edited>

: <input type=hidden name=id value=';

: Print $id;

: print '>

: </table>

: </form> <p>';

: }

:

: if ( $mode=="edited")

: {

: mysql_query ("UPDATE address SET name = '$name', phone = '$phone',

: email = '$email' WHERE id = $id");

: Print "Data Updated!<p>";

: }

: //Removing Data

: if ( $mode=="remove")

: {

: mysql_query ("DELETE FROM address where id=$id");

: Print "Entry has been removed <p>";

: }

: //Address Book

: $data = mysql_query("SELECT * FROM address ORDER BY name ASC")

: or die(mysql_error());

: Print "<h2>Address Book</h2><p>";

: Print "<table border cellpadding=3>";

: Print "<tr><th width=100>Name</th><th width=100>Phone</th><th

: width=200>Email</th><th width=100 colspan=2>Admin</th></tr>"; Print

: "<td colspan=5 align=right><a href=" .$_SERVER[’PHP_SELF’].

: "?mode=add>Add Contact</a></td>";

: while($info = mysql_fetch_array( $data ))

: {

: Print "<tr><td>".$info['name'] . "</td> ";

: Print "<td>".$info['phone'] . "</td> ";

: Print "<td> <a href=mailto:".$info['email'] . ">" .$info['email'] .

: "</a></td>";

: Print "<td><a href=" .$_SERVER[’PHP_SELF’]. "?id=" . $info['id']

: ."&name=" . $info['name'] . "&phone=" . $info['phone'] ."&email=" .

: $info['email'] . "&mode=edit>Edit</a></td>"; Print "<td><a href="

: .$_SERVER[’PHP_SELF’]. "?id=" . $info['id']

: ."&mode=remove>Remove</a></td></tr>";

: }

: Print "</table>";

: ?>

: </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.