munky334 Posted October 16, 2008 Share Posted October 16, 2008 : 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> Quote Link to comment Share on other sites More sharing options...
burnside Posted October 16, 2008 Share Posted October 16, 2008 I can't see any link's <a href="myscript.php?action=edit">EDIT</a> <?php if($_GET['action'] == "edit" ) { // edit stuff here } ?> i could be wrong though. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 16, 2008 Share Posted October 16, 2008 The first thing i notice is that in this part: <a href=" .$_SERVER[’PHP_SELF’] You're using some strange type of quote - possibly generated in Word. You should be using normal single quotes ('). And what's with the colons at the start of every line of your post? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.