Problem with form select menu ....
Posted: Tue Sep 21, 2004 10:03 am
feyd | Please use
feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Ok this code wont work for me. It should enable the dropdown in the form to pick which table the data in the form is added to. It should either go to the table "cichilds" or the table "websites". Doesnt work at alll for me. Any help much appreciated:Code: Select all
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Add Sql</title>
</head>
<body>
<?php
$user="*********";
$pass="*********";
$db="garethna_websitelinks";
$link2=@mysql_connect("localhost",$user, $pass);
if (! $link2){
die ("Couldnt connect to mysql:".mysql_error());
}
print "<h2>Successfully connected to server</h2>\n\n<br/>";
if (!empty ($_REQUEST['name'])&&
!empty ($_REQUEST['link'])&&
!empty ($_REQUEST['scribe'])&&
!empty ($_REQUEST['scriber'])&&
!empty ($_REQUEST['scriberemail'])){
//check user input here!
$dberror="";
$ret=add_to_database($_REQUEST['name'],
$_REQUEST['link'],
$_REQUEST['scribe'],
$_REQUEST['scriber'],
$_REQUEST['select'],
$_REQUEST['scriberemail'], $dberror);
if (! $ret) {
print "Error: $dberror<br/>\n";
}else{
print "Thankyou very much!<br/>\n";
}
}else {
write_form();
}
function add_to_database($name, $link, $scribe, $scriber, $scriberemail, &$dberror){
$name=mysql_real_escape_string($name);
$link=mysql_real_escape_string($link);
$scribe=mysql_real_escape_string($scribe);
$scriber=mysql_real_escape_string($scriber);
$select=mysql_real_escape_string($select);
$scriberemail=mysql_real_escape_string($scriberemail);
$link2=mysql_pconnect("localhost", "*********", "*********");
if (! $link2){
$dberror=mysqlerror();
return false;
}
if (! mysql_select_db("garethna_websitelinks", $link2)){
$dberror=mysqlerror();
return false;
}
$query="INSERT INTO $select (name, link, scribe, scriber, scriberemail)
values('$name', '$link', '$scribe', '$scriber', '$scriberemail')";
if (! mysql_query($query, $link2)){
$dberror=mysql_error();
return false;
}
return true;
}
function write_form(){
print <<<EOF
<form method="post" action = "{$_SERVER['PHP_SELF']}">
<p><input type="text" name="name"/>
Name</p>
<p><input type="text" name="link"/>
Website address</p>
<p><input type="text" name="scribe"/>
Site info</p>
<p><input type="text" name="scriber"/>
Your name</p>
<p><input type="text" name="scriberemail"/>
Your email</p>
<select name="select">
<option>cichilds</option>
<option>websites</option>
</select>
<p><input type="submit" value = "Sumbit it!"/></p>
</form>
EOF;
}
?>
</body>
</html>feyd | Please use
Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
[color=darkgreen][b]feyd[/b] | removed username/password[/color]