ok i have a form which is currentlylocated here:
www.sinerfy-media.com/New/addlink.html it has 4 fields (1 is a drop down menu) which are category(drop down menu), URL, title and description my code is here:
[code:1:412c5ca3c0]<?xml version="1.0" encoding="iso-8859-1"?>
<!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>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form name="form1" id="form1" method="post" action="">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="124">Category:</td>
<td width="376">
<select NAME="category">
<option selected value="Hosting">Hosting
<option value="SEO">SEO
<option value="Tutorials">Tutorials
<option value="Forums">Forums
<option value="Other">Other
</select>
</td>
</tr>
<tr>
<td>URL:</td>
<td><input name="textfield" type="text" value="http://" /></td>
</tr>
<tr>
<td>Text:</td>
<td><input type="text" name="text" /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="description"></textarea></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
<div align="center"><b>If you are not authorised to be here please use this link
to go to our homepage: <a href="index.html">home</a></b> </div>
</body>
</html>[/code:1:412c5ca3c0]
i want these fields to be written to the database when the submit button is clicked, i was told this would work to do that: [code:1:412c5ca3c0] $qry="INSERT INTO my_table (category, url, test, description) VALUES (\"$category\", \"$url\", \"$text\", \"$description\")"; [/code:1:412c5ca3c0]
But as i havnt learnt PHP yet i was wondering if anyone would be able to show me where to put it?
Cheers
tony
Comments
then inside a php file you would do something like this:
[code:1:720728b9d1]<?php
$category=$_POST['category'];
$url=$_POST['url'];
$test=$_POST['test'];
$description=$_POST['description'];
// connect to database using the mysql_connect function()
$db = mysql_connect("localhost","username","password");
//The function mysql_select_db() sets the current
//database to the one specified in this case "test"
mysql_select_db("test" ,$db);
$qry="INSERT INTO my_table (category, url, test, description) VALUES (\"$category\", \"$url\", \"$text\", \"$description\")";
//NOTE - IM NOT SURE IF THOSE SLASHES SHOULD BE THERE
?>
[/code:1:720728b9d1]
And i think thats it. im also just learning PHP so this code might be slightly/totally wrong, lol
The Royal Ram
<php echo $php_self; ?>
then it will use itself as the processor
The Royal Ram
then under the form copy and paste that bit of PHP i wrote
The Royal Ram
<?php echo $php_self; ?>
FORM HTML HERE
then your code here?
thanks ill have a go later if thats rite
[code:1:b1bf4724fa]<?xml version="1.0" encoding="iso-8859-1"?>
<!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>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form name="form1" id="form1" method="post" action="php echo $php_self; ?> ">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="124">Category:</td>
<td width="376">
<select NAME="category">
<option selected value="Hosting">Hosting
<option value="SEO">SEO
<option value="Tutorials">Tutorials
<option value="Forums">Forums
<option value="Other">Other
</select>
</td>
</tr>
<tr>
<td>URL:</td>
<td><input name="textfield" type="text" value="http://" /></td>
</tr>
<tr>
<td>Text:</td>
<td><input type="text" name="text" /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="description"></textarea></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form><br><br>
<?php
$category=$_POST['category'];
$url=$_POST['url'];
$test=$_POST['test'];
$description=$_POST['description'];
// connect to database using the mysql_connect function()
$db = mysql_connect("localhost","username","password");
//The function mysql_select_db() sets the current
//database to the one specified in this case "test"
mysql_select_db("test" ,$db);
$qry="INSERT INTO my_table (category, url, test, description) VALUES (\"$category\", \"$url\", \"$text\", \"$description\")";
//NOTE - IM NOT SURE IF THOSE SLASHES SHOULD BE THERE
echo 'There were no errors. All was succesful';
?> <br>
<div align="center"><b>If you are not authorised to be here please use this link
to go to our homepage: <a href="index.html">home</a></b> </div>
</body>
</html>[/code:1:b1bf4724fa]
This code might not be perfect because im not too sure about the PHP part of it. Try it
The Royal Ram
[code:1:a841d72f72]<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
[/code:1:a841d72f72] at the very top
ok it loads no mysql errors after i made a couple of changes
the problem comes when i fill in the fileds and hit submit
you can try it yourself
http://sinergy-media.com/New/addlink.php
fill in the fields hit submit and it comes up with a 404 error:
The requested URL /New/php echo $php_self; was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
it should be:
<?php echo $php_self; ?>
sorry about that - it was my mistake for typing it wrong above
The Royal Ram
but it didnt work thats why i had to change the top line
atleast it doesnt come up with any errors before or after the submit, im just working on getting the password thingy to work now
The Royal Ram