Hallo iedereen,
Ik heb nu dit.. maar ik krijg de volgende fout: Fatal error: Call to undefined function mysql_errorno() in /var/www/http/add.php on line 29 (13 zonder HTML)
Dit is mijn PHP script:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://
www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="add.css" />
</head>
<body>
<div id="divadd">
<?php
require("dbfeatures.php");
$dbConnection = connectdatabase();
opendatabase($dbConnection);
$addquery = "INSERT INTO phonebook (name, nr) VALUES ('".mysql_real_escape_string($_POST['addname'])."','".mysql_real_escape_string($_POST['addnr'])."')";
connectdatabase();
if (mysql_errorno() == 1062)
{
if (is_numeric($_POST['addnr']))
{
if (strlen($_POST['addnr']) > 7 && strlen($_POST['addnr']) < 14)
{
echo "Contact is added";
mysql_query($addquery, $dbConnection) or die (mysql_error() );
}
else
echo 'The number should be between 7 and 14 characters long, contact not added! We will sent you now back to the home page.';
}
else
echo 'Please enter a valid number, contact not added! We will sent you now back to the home page.';
}
else
echo 'This number is already in use';
mysql_close($dbConnection);
header('Refresh: 8; url=index.html');
?>
</div>
</body>
</html>
[size=xsmall]
Toevoeging op 18/11/2010 10:28:53:[/size]
Hallo iedereen,
Ik heb de oplossing:
<?php
require("dbfeatures.php");
$dbConnection = connectdatabase();
opendatabase($dbConnection);
$addquery = "INSERT INTO phonebook (name, nr) VALUES ('".mysql_real_escape_string($_POST['addname'])."','".mysql_real_escape_string($_POST['addnr'])."')";
connectdatabase();
if (mysql_errno() == 1062)
{
if (is_numeric($_POST['addnr']))
{
if (strlen($_POST['addnr']) > 7 && strlen($_POST['addnr']) < 14)
{
echo "Congratulations! Contact is added. We will sent you now back to the home page";
mysql_query($addquery, $dbConnection) or die (mysql_error() );
}
else
echo 'The number should be between 7 and 14 characters long, contact not added! We will sent you now back to the home page.';
}
else
echo 'Please enter a valid number, contact not added! We will sent you now back to the home page.';
}
else
echo 'This number is already in use, contact not added! We will sent you now back to the home page.';
mysql_close($dbConnection);
header('Refresh: 7; url=index.html');
?>
[size=xsmall]
Toevoeging op 18/11/2010 10:32:38:[/size]
Alleen schijnt de header rederect niet goed te zijn...
Refresh schijnt niet te kloppen, maar het werkt wel.
Iemand een ide?
En weet iemand hoe ik dit php script op de één pagina afhandel.
Nu link ik namelijk door naar deze pagina, maar dat is natuurlijk niet zo netjes.
Mijn invul pagina ziet er als volgt uit:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://
www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="body.css" />
<link rel="stylesheet" type="text/css" href="home.css" />
<link rel="stylesheet" type="text/css" href="searchbar.css" />
<link rel="stylesheet" type="text/css" href="buttons.css" />
<script type="text/javascript" src="formfocus.js"></script>
</head>
<body>
<div id="divpage">
<div id="divlogo">
<img src="/logo.png" alt="Image not available" id="logo" />
</div>
<div id="divsearch">
<form action="results.php" name="search" method="post">
<input type="text" name="searchbar" id="searchbar" /><input type="submit" value="Search" id="searchbutton" />
</form>
</div>
<div>
<hr id="line"/>
</div>
<div id="divadd">
<form action="add.php" name="add" method="post">
Name:<input type="text" name="addname" id="addname" maxlength="10" />Number:<input type="text" name="addnr" id="addnr" maxlength="12" /><input type="submit" value="Add" id="addbutton" />
</form>
</div>
</div>
</body>
</html>