MySQL Forums
Forum List  »  PHP

can't pass data to mysql
Posted by: sarah alegado
Date: June 24, 2005 04:51AM

i can't configure why dis code can't pass data to the mysql database. need help from the experts
<?php

// connect to the database

include('dbconnect.php');



$error = false;



// run this only, once the user has hit the "Add Contact" button

if (isset($_POST['addagent'])) {

// assign form inputs

$firstname = $_POST['firstname'];

$lastname = $_POST['lastname'];

$password = $_POST['password'];

$email = $_POST['email'];

$branch = $_POST['branch_location'];

$mydate=getdate();

// validate inputs

if ( !empty($firstname) && !empty($lastname) ) {

// add member to database

$query = "INSERT INTO user (_id,_password,branch_location,_emailadd,_fname,_lname,_logtime,_status) VALUES ('".$password."','".$branch."','".$firstname."','".$lastname."','".$email."','".$mydate."')";

//$result = $database->query($query);
$result = mysql_query($query, $connection);

//$database->disconnect();
mysql_close();

$message = "\"".$firstname." ".$lastname."\" has been successfully added.";

echo "<script>alert('naa');</script>";

echo "<script>location.replace('listagents.php');</script>";
// Header("Location: listagents.php");

exit;

}

else {

$error = true; // input validation failed

}

}

?>

<html>

<head>

<title>Add a Contact</title>

</head>

<body>

Add a Contact | <a href="listagents.php">My Contacts</a>

<h1>Add a Contact</h1>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<?php

if ( !empty($message) ) {

echo '<span style="color:green">',$message,'</span><br><br>',"\n";

}

?>

<?php

if ( $error && empty($firstname) ) {

echo '<span style="color:red">Error! Please enter a first name.</span><br>',"\n";

}

?>

<p>First name:

<input name="firstname" type="text" value="<?php echo $firstname; ?>">

<br>

<?php

if ( $error && empty($lastname) ) {

echo '<span style="color:red">Error! Please enter a last name.</span><br>',"\n";

}

?>

Last name:

<input name="lastname" type="text" value="<?php echo $lastname; ?>">

<br>

<br>

<?php

if ( $error && empty($password) ) {

echo '<span style="color:red">Error! Please enter a password.</span><br>',"\n";

}

?> Password:

<input name="password" type="text" value="<?php echo $password; ?>">

<br>

<?php

if ( $error && empty($email) ) {

echo '<span style="color:red">Error! Please enter a email.</span><br>',"\n";

}

?>
E-Mail:

<input name="email" type="text" value="<?php echo $email; ?>">

<br>

<br>
Branch:

<select name="branch">
<?php $query = "SELECT _location FROM branch ORDER BY _location ASC";

$result = mysql_query($query, $connection);

$num_rows = mysql_num_rows($result);

if ($num_rows){
while ($myrow = mysql_fetch_row($result)){
if ($_POST['branch_location'] == $myrow[0]) {
$sel= ' selected';
}
else
{
$sel = '';
}
echo "<OPTION".$sel.">$myrow[0]</OPTION>";
}
}
?>
</select>
<br>



<input type="submit" name="addagent" value="Add Contact">

</form>

</body>

</html>

Options: ReplyQuote


Subject
Written By
Posted
can't pass data to mysql
June 24, 2005 04:51AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.