hey,
i am trying to make a form that calls a function which sends the forms data to the mysql database. When I execute, I receive a blank page and the database does not contain the new data.
Here is the form:
<html>
<head>
<title></title>
</head>
<body>
<form action="function.php" method="post">
<input type="text" name="link_category"><br><br>
<input type="text" name="link_name"><br><br>
<input type="text" name="link_description"><br><br>
<input type="submit" value="send">
</form>
</body>
</html>
Here is the php function:
<html>
<head>
<title></title>
</head>
<body>
<?php
$link = mysql_connect("localhost", "user", "pass")
or die ("Could not connect to MySQL");
mysql_select_db ("links")
or die ("Could not select database");
$link_category = $_POST['link_category'];
$link_description = $_POST['link_description'];
$link_name = $_POST['link_name'];
$query = "insert into linktest ('link_category', 'link_description', 'link_name') values
('$link_category', '$link_description', '$link_name')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows().'link inserted in database.';
?>
Any suggestions would be appreciated.
</body>
</html>first make sure you have register_globals set to OFF, than do this
$link_category = $_POST["link_category"];
$link_description = $_POST["link_description"];
$link_name = $_POST["link_name"];I made the two changes you said. It still does not work. FYI: primary key is set to autoincrement. Would changing this have any positive effect on the result?Firstly, always add the or die(mysql_error()) after any query until you have it all working.
I think you will find that your query is failing because you are not specifying the autoincrement field. Even though you are not assigning a value you still have to reference it. Try this:
$query = "INSERT INTO linktest VALUES ('', '$link_category', '$link_description', '$link_name')";
Btw, please use the forum's [ php ] [ /php ] tags (no spaces) when posting code. Just makes it easier to debug. Ta.
i am trying to make a form that calls a function which sends the forms data to the mysql database. When I execute, I receive a blank page and the database does not contain the new data.
Here is the form:
<html>
<head>
<title></title>
</head>
<body>
<form action="function.php" method="post">
<input type="text" name="link_category"><br><br>
<input type="text" name="link_name"><br><br>
<input type="text" name="link_description"><br><br>
<input type="submit" value="send">
</form>
</body>
</html>
Here is the php function:
<html>
<head>
<title></title>
</head>
<body>
<?php
$link = mysql_connect("localhost", "user", "pass")
or die ("Could not connect to MySQL");
mysql_select_db ("links")
or die ("Could not select database");
$link_category = $_POST['link_category'];
$link_description = $_POST['link_description'];
$link_name = $_POST['link_name'];
$query = "insert into linktest ('link_category', 'link_description', 'link_name') values
('$link_category', '$link_description', '$link_name')";
$result = mysql_query($query);
if ($result)
echo mysql_affected_rows().'link inserted in database.';
?>
Any suggestions would be appreciated.
</body>
</html>first make sure you have register_globals set to OFF, than do this
$link_category = $_POST["link_category"];
$link_description = $_POST["link_description"];
$link_name = $_POST["link_name"];I made the two changes you said. It still does not work. FYI: primary key is set to autoincrement. Would changing this have any positive effect on the result?Firstly, always add the or die(mysql_error()) after any query until you have it all working.
I think you will find that your query is failing because you are not specifying the autoincrement field. Even though you are not assigning a value you still have to reference it. Try this:
$query = "INSERT INTO linktest VALUES ('', '$link_category', '$link_description', '$link_name')";
Btw, please use the forum's [ php ] [ /php ] tags (no spaces) when posting code. Just makes it easier to debug. Ta.