Forum Moderators: coopster

Message Too Old, No Replies

need help posting data to mysql db

         

paul123456

12:27 am on Sep 12, 2004 (gmt 0)

10+ Year Member



hi

i have this code:

<?
error_reporting (0);

$host="#*$!xx";
$user="#*$!x";
$password="#*$!x";


// Connect to the database server
$link = mysql_connect($host,$user,$password);
if(!$link) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
// Select the jokes database
if (! @mysql_select_db("log") ) {
echo( "<P>Unable to locate the log " .
"database at this time.</P>" );
exit();
}

?>
<snip>


Add your problem<br>
<?
if ("SUBMIT" == $adderror) {
$sql = "INSERT INTO errors (name, error) VALUES ('$name', '$error')";
if (mysql_query($sql)) {
echo("<P>Your error has been added.</P>");
} else {
echo("<P>Error adding submitted error: " .
mysql_error() . "</P>");
}
}
?>
<br>
<form name="form1" method="post" action="<?php echo($PHP_SELF);?>">
Name:
<input type="text" name="name">
<br><br>Error:
<input name="error" type="text" size="40">
<br>
<br><input type=SUBMIT name="adderror" value="Add">
</form></td>
</tr>
</table>

</snip>

but when i load the page and enter the info into the fields then click the add button the form just refreshes and does not do nothing

please help thanks

[edited by: ergophobe at 1:03 am (utc) on Sep. 12, 2004]
[edit reason] snipped stylesheet and nested tables [/edit]

dkin

1:06 am on Sep 12, 2004 (gmt 0)

10+ Year Member



Just try chaning this

<?
if ("SUBMIT" == $adderror)

to this

if ($adderror)

let me know if that helps.

cheers

Zipper

2:03 am on Sep 12, 2004 (gmt 0)

10+ Year Member



to be more precise,

if($_POST['adderror'])

for cross platform compatibility. but $adderror would do in most systems.

paul123456

8:29 am on Sep 12, 2004 (gmt 0)

10+ Year Member



thanks yous

it worked :)