Forum Moderators: coopster

Message Too Old, No Replies

Can't get data to post to Mysql

         

outdoorxtreme1

7:49 pm on Mar 20, 2006 (gmt 0)

10+ Year Member



What am I doing wrong with this code? I cant get my field values to post to my database. Can someone please help me. thanks.

// Create an empty array to hold the error messages.
$arrErrors = array();
//Only validate if the Submit button was clicked.
if (!empty($_POST['Submit'])) {
// Each time there's an error, add an error message to the error array
// using the field name as the key.

if (count($arrErrors) == 0) {
// If the error array is empty, there were no errors.
// Insert form processing here.

$host = " ";
$user = " ";
$pass = " ";
$dbname = " ";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$sql_query = mysql_query("INSERT INTO trip_log(triptype, author) VALUES ('$triptype', '$author')")
or die (mysql_error());

header("Location: /index.php?page=Trip_Log");

} else {

// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p><img src="/uploads/images/triangle_error.gif" width="16" height="16" hspace="5" alt="">Please check the following and try again/p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}

echo '<style>';
echo 'label {

}';

echo '.formerror {
border: 1px solid red;
background-color : #FFCCCC;
width: auto;
padding: 0px 0;
}';

echo '.errortext {
padding-left: 80px;
font: bold smaller sans-serif;
}';
echo '</style>';

echo '<form method="post" action="',$_SERVER['PHP_SELF'],'?page=Test"';
echo '<input type="hidden" name="triptype" value="ATV" />';
echo '<p';if (!empty($arrErrors['author'])); echo '>';
echo '<label for="Trip Report Author">Trip Report Author/label><br />';
echo '<input name="author" type="text" id="author" size="29" maxlength="50" value="',$_POST['author'],'" />';
if (!empty($arrErrors['author'])) echo '<img src="/uploads/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><br />';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';

dreamcatcher

7:52 pm on Mar 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I assume its because you have register_globals OFF?

Before this..

$sql_query = mysql_query("INSERT INTO trip_log(triptype, author) VALUES ('$triptype', '$author')")
or die (mysql_error());

add this..

$triptype = mysql_real_escape_string($_POST['triptype']);
$author = mysql_real_escape_string($_POST['author']);

dc

outdoorxtreme1

8:20 pm on Mar 20, 2006 (gmt 0)

10+ Year Member



This worked for the author field but not the hidden triptype. Why is this?