Hi,
There's a form where user enters his name to retrieve other info (phone) entered by him earlier. Here's the html-code:
the php-code is as follows:HTML Code:<form action="retrieve.php" name="secondForm" id="secondForm" method=post> <input name="name" class="required" type=text ><br> <input type="submit" > </form>
the problem is, that when a user enters a non-existing name and submits it, he gets mysql warning and error. How do I make it that he get a message that no such entry exits without showing him an underfind error from mysql? I know it's something simple but I cannot solve it myself.PHP Code:<?php
$username="root";
$password="123456";
$database="phonebook";
//connect to database
mysql_connect(localhost,$username);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");
$name=$_POST['name'];
//perform query
$query = "select * from contact where name='$name'";
$result=mysql_query($query) or die('Error, insert query failed');
//get result
$phone=mysql_result($result,0,"phonenumber");
echo "Your phone number is <b> $phone</b> ";
?>


Reply With Quote
Bookmarks