I have writen some code in php for user registration but if i click on submit button It is not writing in database.Please help me. Here is my code...
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register - Vatsal Technosoft Messenger</title>
<link href="Style/regstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<div id="outer">
<div id="companyname"></div>
<div class="container">
<div id="formcontainer">
<h3>Registration Form </h3>
<form name="register_form" action="" method="post">
<?php
if( isset($_POST['register']) AND
isset($_POST['username']) AND
isset($_POST['password']) AND
isset($_POST['firstname']) AND
isset($_POST['lastname']) AND
isset($_POST['contact1']) AND
isset($_POST['address']) AND
isset($_POST['jobtitle'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$con1 = $_POST['contact1'];
$con2 = $_POST['contact2'];
$email = $_POST['email'];
$address = $_POST['address'];
$jobtitle = $_POST['jobtitle'];
if( empty($username) or
empty($password) or
empty($fname) or
empty($lname) or
empty($con1) or
empty($email) or
empty($address) or
empty($jobtitle)) {
$message = "All Information Is neccessary";
} else {
$sql = mysql_query("INSERT INTO users VALUES (``,` $username `,` $password `,` $fname `,` $lname `,` $con1 `,` $address `,` $jobtitle `)");
if($sql) {
$message = "OK....!";
} else {
$message = "BAD";
}
}
echo "<div class='box'> $message </div>";
}
?>
<div id="formtext">
User Name : <input type="text" name="username" style="width:200px;" autocomplete="off"/>
Passwrod : <input type="password" name="password" autocomplete="off" style="width:200px;"/>
<br /><br />
First Name : <input type="text" name="firstname" style="width:200px;" autocomplete="off" />
Last Name : <input type="text" name="lastname" autocomplete = "off" style = " width:200px; "/>
<br /><br />
Contact(1) : <input type="text" name="contact1" autocomplete="off" style="width:200px;" />
Contact(2) : <input type="text" name="contact2" autocomplete="off" style="width:200px;"/>
<br /><br />
E-mail ID : <input type="text" name="email" autocomplete="off" style="width:300px;"/>
<br /><br />
Address :<br />
<textarea name="address" cols="25" rows="5" autocomplete="off" style="background: #333;color: #fff;border-radius:5px;border: 0px; margin-top:-20px;" placehoder="Address"></textarea>
<br /><br />
Job Title : <input type="text" name="jobtitle" autocomplete="off" style="width:215px;"/>
<br /><br /><br />
<input type="button" name="back" value="Back" style="width:100px; margin-left:95px;"/>
<input type="reset" name="reset" value="Reset" style="width:100px; margin-left:45px;"/>
<input type="submit" name="register" value="Register" style="width:100px; margin-left:45px;"/>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Your issue is probably this line:
$sql = mysql_query("INSERT INTO users VALUES (``,` $username `,` $password `,` $fname `,` $lname `,` $con1 `,` $address `,` $jobtitle `)");
It is recommended to always declare your column names in the INSERT statement like this:
$sql = mysql_query("INSERT INTO `users` (`col1` , `col1` , `col3`) VALUES ('val1' , 'val2' , 'val3')");
Related
I am using postgreSQL, PHP, and an HTML form. The form is a simple scholarship application. My connection script seems to work fine because when I click submit on the HTML form it echos "connected" and doesn't die, however no data from the form is transferred to my table. Please any guidance.
My PHP connection script: connect.php
try {
$dbConn = new PDO('pgsql:host=' . DB_HOST . ';'
. 'port=' . DB_PORT . ';'
. 'dbname=' . DB_NAME . ';'
. 'user=' . DB_USER . ';'
. 'password=' . DB_PASS);
$dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set error mode to exception
echo “Connected”;
} catch (PDOException $e) {
$fileName = basename($e->getFile(), ".php"); // File that triggers the exception
$lineNumber = $e->getLine(); // Line number that triggers the exception
die("[$fileName][$lineNumber] Database connect failed: " . $e->getMessage() . '<br/>');
}
?>
My PHP submission script: form.php
<?php
require 'connect.php';
$sid = $_POST['sid'];
$firstName = $_POST['fname'];
$preferredName = $_POST['pname'];
$lastName = $_POST['lname'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$inSchool = $_POST['inSchool'];
$gDate = $_POST['gDate'];
$gpa = $_POST['gpa'];
$essay = $_POST['essay'];
$submit = $_POST['submit'];
if ($sid = ''){
$query = 'insert into student(firstname,lastname,prefname,address,city,state,zip,phone,email) values (?,?,?,?,?,?,?,?,?)';
$statement = $dbConn->prepare($query);
$statement->execute([$firstname, $lastname,$preferredname,$address,$city,$state,$zip,$phone,$email]);
}
else{
$query = 'insert into student(firstname,lastname,prefname,address,city,state,zip,phone,email) values (?,?,?,?,?,?,?,?,?)';
$statement = $dbConn->prepare($query);
$statement->execute([$firstname, $lastname,$preferredname,$address,$city,$state,$zip,$phone,$email]);
}
$query = 'select sid from student where firstname = ? and lastname = ? limit 1';
$statement = $dbConn->prepare($query);
$statement->execute([$firstname, $lastname,$preferredname,$address,$city,$state,$zip,$phone,$email]);
$results = $statement->fetch();
echo $results[0];
?>
My HTML Form: Application.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="Style.css">
<title>Application</title>
</head>
<body>
<form action="form.php" method="post">
<header>
<img class="logo" src="" alt="logo">
<div>Asterisks Corporation Scholarship Application</div>
</header>
<p class="general">Please fill in all information to apply for the Asterisk's Scholarship.<p>
First Name:
<input type="text" size="15" name="fname" required />
Preferred Name:
<input type="text" size="15" name="pname" >
Last Name:
<input type="text" size="15" name="lname" required />
<p class="newSection">Contact Information</p>
Address:
<input type="text" size="50" name="address" required />
City:
<input type="text" size="15" name="city" required />
State:
<input type="text" size="15" name="state" required />
Zip Code:
<input type="text" size="1" name="zip" placeholder="####" required /><br><br>
Phone Number:
<input type="text" size="10" name="phone" placeholder="(###)-###-###">
Email Address:
<input type="text" size="50" name="email" required />
<p class="newSection">Academic Information</p>
Are you currently enrolled in school?
<input type="checkbox" id="Yes" name="yesBox">
<label for="Yes">Yes</label>
<input type="checkbox" id="No" name="noBox">
<label for="No">No</label><br><br>
What school are you enrolled?
<input type="text" size="50" name="schoolsEnrolled"><br><br>
What is/was your date of Graduation?
<input type="date" name="graduationDate"><br><br>
GPA
<input type="text" size="1" name="gpa">
<p class="newSection">What institutions have you applied?</p>
<input type="text" name="" value="" id="school" name="schoolsApplied">
<button onclick="addToList()" type="button" name="button" id="addButton">Add School</button><br>
<ul id="schoolList"></ul>
<p class="newSection">Please write a small essay as to why you should receive this scholarship and what your plans are after graduation.</p>
<textarea id="essay" style="width: 500px; height: 200px;" alignment="left" onkeyup="wordCounter(),wordsRemaining()" name="essay"></textarea>
<div>
300 Words Minimum & 500 Words Maximum
<div> Word Count: <span id="wordCount">0</span></div>
<div> Words Remaining: <span id="wordsRemaining">0</span></div>
</div>
<p class="newSection">Please confirm each of the following:</p>
<input type="checkbox" id="Transcript" name="transcriptConfirm" required />
<label for="Transcript">I have sent in all of my transcripts</label><br>
<input type="checkbox" id="Schools" name="schoolConfirm" required />
<label for="Schools">All schools that I am considering are in the US</label><br>
<input type="checkbox" id="Awards" name="awardConfirm" required />
<label for="Awards">I understand that the award is $5,000 per year for four years</label><br>
<input type="checkbox" id="Confirm" name="amountConfirm" required />
<label for="Confirm">I have received confirmation that my recommenders have emailed their letters to the Scholarship's Coordinator</label><br><br>
Please type your signature in the text box below: <br><br>
<input type="text" size="20" name="signature" required />
<div><br>
<input type="submit" value ="Submit" name="submit">
<input type="reset" value="Start Over" onclick="MinMax()">
</div>
<script>
function addToList(){
let school= document.getElementById("school").value;
document.getElementById("schoolList").innerHTML += ('<li>'+ school+'</li>');
};
function wordCounter(text){
var count= document.getElementById("wordCount");
var input= document.getElementById("essay");
var text=essay.value.split(' ');
var wordCount = text.length;
count.innerText=wordCount
}
function wordsRemaining(text){
var count= document.getElementById("wordCount");
var input= document.getElementById("essay");
var remaining = document.getElementById("wordsRemaining");
var text=essay.value.split(' ');
var wordCount = text.length;
remaining.innerText=300-wordCount
}
</script>
</form>
</body>
</html>
This is the code for saving the information into mysql database from a FORM.
In the HTML section the form is being handled i.e. retrieving required data from user.
In the PHP section storing data has been handled.
But the problem is it doesn't store data.
I'm using XAMPP server.
<html>
<head>
<title>signup</title>
<link rel="stylesheet" href="css/insert.css" />
</head>
<body>
<div class="maindiv">
<!--HTML form -->
<div class="form_div">
<div class="title"><h2>Insert Data In Database Using PHP.</h2> </div>
<form action="signup.php" method="post"> <!-- method can be set POST for hiding values in URL-->
<h2>Form</h2>
<label>Name:</label>
<br />
<input class="input" type="text" name="name" value="" />
<br />
<label>Email:</label><br />
<input class="input" type="text" name="mail" value="" />
<br />
<label>Phone:</label><br />
<input class="input" type="text" name="phone" value="" />
<br />
<label>Password:</label><br />
<input class="input" type="text" name="pass" value="" />
<br />
<label>Address:</label><br />
<textarea rows="5" cols="25" name="add"></textarea>
<br />
<input class="submit" type="submit" name="submit" value="Insert" />
<?php
//Establishing Connection with Server
$connection = mysql_connect("localhost", "root", "buet2010");
//Selecting Database from Server
$db = mysql_select_db("tanni", $connection);
if(isset($_POST['submit'])){
//Fetching variables of the form which travels in URL
$name = $_POST['name'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$pass = $_POST['pass'];
$add = $_POST['add'];
if($name !=''||$email !=''){
//Insert Query of SQL
$query = mysql_query($db, "INSERT INTO user (name, mail, phone, pass, add)VALUES('$name', '$mail', '$phone', '$pass', '$add')");
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
//Closing Connection with Server
mysql_close($connection);
?>
</form>
</div>
</div>
</body>
I don't understand what can be the problem.
Thanks all. I got the problem.
Actually the sequence of the column in my database was not matching with the query in php code.
I have solved this by changing the variable sequence in the query which is maintained in the database.
$query = mysql_query("INSERT INTO user (`name`, `mail`, `pass`, `address`, `phone`)VALUES('".$name."', '".$mail."', '".$pass."', '".$address."', '".$phone."')");
Here is the code and it will work for your..
I have passed connection link in your mysql_query. and used PHP_SELF for current page.
<html>
<head>
<title>signup</title>
<link rel="stylesheet" href="css/insert.css" />
</head>
<body>
<div class="maindiv">
<!--HTML form -->
<div class="form_div">
<div class="title"><h2>Insert Data In Database Using PHP.</h2> </div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <!-- method can be set POST for hiding values in URL-->
<h2>Form</h2>
<label>Name:</label>
<br />
<input class="input" type="text" name="name" value="" />
<br />
<label>Email:</label><br />
<input class="input" type="text" name="mail" value="" />
<br />
<label>Phone:</label><br />
<input class="input" type="text" name="phone" value="" />
<br />
<label>Password:</label><br />
<input class="input" type="text" name="pass" value="" />
<br />
<label>Address:</label><br />
<textarea rows="5" cols="25" name="add"></textarea>
<br />
<input class="submit" type="submit" name="submit" value="Insert" />
<?php
//Establishing Connection with Server
$connection = mysql_connect("localhost", "root", "buet2010");
//Selecting Database from Server
$db = mysql_select_db("tanni", $connection);
if(isset($_POST['submit'])){
//Fetching variables of the form which travels in URL
$name = $_POST['name'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$pass = $_POST['pass'];
$add = $_POST['add'];
if($name !=''||$email !=''){
//Insert Query of SQL
$query = mysql_query($db, "INSERT INTO user (name, mail, phone, pass, add)VALUES('$name', '$mail', '$phone', '$pass', '$add')",$connection);
echo "<br/><br/><span>Data Inserted successfully...!!</span>";
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
//Closing Connection with Server
mysql_close($connection);
?>
</form>
</div>
</div>
</body>
I can not figure out what i missed here in my code. i if else statement is working because i can see my form and after submitting i suppose to see message after tag. How would i know if submit button is respond or not.
<?php
$output_form = true;
$fname = "";
$lname = "";
$address1 ="";
$address2 ="";
$city = "";
$state = "";
$zipcode = "";
if (isset($_POST['submit'])) {
print_r($_POST);
$fname = trim($_POST["firstName"]);
$lname = trim($_POST['lastName']);
$address1 = trim($_POST['address1']);
$address2 = trim($_POST['address2']);
$city = trim($_POST['city']);
$state = trim($_POST['state']);
$zipcode = trim($_POST['zipcode']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Assignment 3 </title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
if ($output_form) {
?>
<h1>Enter your information</h1>
<form name="userform" action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<p>First Name: <input name="firstName" type="text" value="<?= $fname ?>"></p>
<p>Last Name: <input name="lastName" type="text" value="<?= $lname ?>"></p>
<p>Address 1: <input name="address1" type="text" value="<?= $address1 ?>"></p>
<p>Address 2: <input name="address2" value="<?= $address2 ?>" type="text" ></p>
<p>City: <input name="city" type="text" value="<?= $city ?>"></p>
<p>State: <input name="state" type="text" value="<?= $state ?>"></p>
<p>Zip Code: <input name="zipcode" type="number" value="<?= $zipcode ?>"></p>
<input class="button" name="submit" type="button" value="Button">
</form>
<?php
} else {
?>
<h2>Your information is:</h2>
<p class="result">
Name: <?= $fname.' '.$lname ?><br>
Street Address: <?= $address1 ?><br>
City, State: <?=$city.' '.$state ?>
</p>
<?php
}
?>
</body>
</html>
Make your input type submit
<input class="button" name="submit" type="button" value="Button">
Should be
<input class="button" name="submit" type="submit" value="Button">
I'm trying to get the information submitted by the user to store with a cookie, and redisplay when a user hits 'edit' on the preview page. For example if a user enters "jhon" as name and hits submit, then sees a preview and sees they misspelled their name they can hit edit and all the information they entered is still there, and they only have to fix their name.
Form code:
<!doctype html>
<?php
$cookie_name = "first";
$cookie_value = "$first";
setcookie($cookie_name, $cookie_value, time()+3600*60*24*7);
?>
<html>
<head>
<title>Contact Information</title>
<style type="text/css">
</style>
<link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="content">
<h1>Please Answer the Following Questions</h1>
<form method="POST" action="form_preview.php">
<label for="first">First Name: </label>
<input type="textarea" name="first" />
<br /><br />
<label for="last">Last Name: </label>
<input type="textarea" name="last" />
<br /><br />
<label for="first">Email: </label>
<input type="textarea" name="email" />
<br /><br />
<label for="last">Phone Number: </label>
<input type="textarea" name="phone" />
<br /><br />
<input type="submit" name="submit" value="Preview Answers" />
</form>
</div>
</div>
</body>
</html>
Preview code:
<!doctype xhtml>
<html>
<head>
<title>Preview</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="container">
<div id="content">
<?php
$first = $last = $email = $phone = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$first = test_input($_POST["first"]);
$last = test_input($_POST["last"]);
$email = test_input($_POST["email"]);
$phone = test_input($_POST["phone"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
echo "<h1>Personal Information:</h1>";
echo "First Name: ";
echo $first;
echo "<br><br>";
echo "Last Name: ";
echo $last;
echo "<br><br>";
echo "Email: ";
echo $email;
echo "<br><br>";
echo "Phone Number: ";
echo $phone;
echo "<br><br>";
?>
<form method="post" action="form_entry.php">
<input type="submit" name="edit" value="Edit" />
</form>
<form method="post" action="form_confirmed.php">
<input type="submit" name="confirm" value="Finish" />
</form>
</div>
</div>
</body>
</html>
This question is relating to 2 php scripts.
The first script is called pick_modcontact.php where I choose a contact (from a contact book like phone book), then posts to the script show_modcontact.php When I click the submit button on the form on pick.modcontact.php. As a result of submitting the form I am then taken to show_modcontact.php. As the variables are not present the user is directed back to pick_modcontact.php
I can not work out how to correct the code so that it will show the results of the script show_modcontact.php
This script shows all contacts in a database which is an "address book" this part works fine. please see below.
Name:pick_modcontact.php
if ($_SESSION['valid'] != "yes") {
header( "Location: contact_menu.php");
exit;
}
$db_name = "testDB";
$table_name = "my_contacts";
$connection = #mysql_connect("localhost", "admin", "user") or die(mysql_error());
$db = #mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT id, f_name, l_name FROM $table_name ORDER BY f_name";
$result = #mysql_query($sql, $connection) or die(mysql_error());
$num = #mysql_num_rows($result);
if ($num < 1) {
$display_block = "<p><em>Sorry No Results!</em></p>";
} else {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$f_name = $row['f_name'];
$l_name = $row['l_name'];
$option_block .= "<option value\"$id\">$f_name, $l_name</option>";
}
$display_block = "<form method=\"POST\" action=\"show_modcontact.php\">
<p><strong>Contact:</strong>
<select name=\"id\">$option_block</select>
<input type=\"submit\" name=\"submit\" value=\"Select This Contact\"></p>
</form>";
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify A Contact</title>
</head>
<body>
<h1>My Contact Management System</h1>
<h2><em>Modify a Contact</em></h2>
<p>Select a contact from the list below, to modify the contact's record.</p>
<? echo "$display_block"; ?>
<br>
<p>Return to Main Menu</p>
</body>
</html>
This script is for modifying the contact: named show_modcontact.php
<?php
if (!$_POST['id']) {
header( "Location: pick_modcontact.php");
exit;
} else {
session_start();
}
if ($_SESSION['valid'] != "yes") {
header( "Location: pick_modcontact.php");
exit;
}
$db_name = "testDB";
$table_name = "my_contacts";
$connection = #mysql_connect("localhost", "admin", "pass") or die(mysql_error());
$db = #mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT f_name, l_name, address1, address2, address3, postcode, prim_tel, sec_tel, email, birthday FROM $table_name WHERE id = '" . $_POST['id'] . "'";
$result = #mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$f_name = $row['f_name'];
$l_name = $row['l_name'];
$address1 = $row['address1'];
$address2 = $row['address2'];
$address3 = $row['address3'];
$country = $row['country'];
$prim_tel = $row['prim_tel'];
$sec_tel = $row['sec_tel'];
$email = $row['email'];
$birthday = $row['birthday'];
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify A Contact</title>
</head>
<body>
<form action="do_modcontact.php" method="post">
<input type="text" name="id" value="<? echo $_POST['id']; ?>" />
<table cellpadding="5" cellspacing="3">
<tr>
<th>Name & Address Information</th>
<th> Other Contact / Personal Information</th>
</tr>
<tr>
<td align="top">
<p><strong>First Name:</strong><br />
<input type="text" name="f_name" value="<? echo "$f_name"; ?>" size="35" maxlength="75" /></p>
<p><strong>Last Name:</strong><br />
<input type="text" name="l_name" value="<? echo "$l_name"; ?>" size="35" maxlength="75" /></p>
<p><strong>Address1:</strong><br />
<input type="text" name="f_name" value="<? echo "$address1"; ?>" size="35" maxlength="75" /></p>
<p><strong>Address2:</strong><br />
<input type="text" name="f_name" value="<? echo "$address2"; ?>" size="35" maxlength="75" /></p>
<p><strong>Address3:</strong><br />
<input type="text" name="f_name" value="<? echo "$address3"; ?>" size="35" maxlength="75" /> </p>
<p><strong>Postcode:</strong><br />
<input type="text" name="f_name" value="<? echo "$postcode"; ?>" size="35" maxlength="75" /></p>
<p><strong>Country:</strong><br />
<input type="text" name="f_name" value="<? echo "$country"; ?>" size="35" maxlength="75" /> </p>
<p><strong>First Name:</strong><br />
<input type="text" name="f_name" value="<? echo "$f_name"; ?>" size="35" maxlength="75" /></p>
</td>
<td align="top">
<p><strong>Prim Tel:</strong><br />
<input type="text" name="f_name" value="<? echo "$prim_tel"; ?>" size="35" maxlength="75" /></p>
<p><strong>Sec Tel:</strong><br />
<input type="text" name="f_name" value="<? echo "$sec_tel"; ?>" size="35" maxlength="75" /></p>
<p><strong>Email:</strong><br />
<input type="text" name="f_name" value="<? echo "$email;" ?>" size="35" maxlength="75" /> </p>
<p><strong>Birthday:</strong><br />
<input type="text" name="f_name" value="<? echo "$birthday"; ?>" size="35" maxlength="75" /> </p>
</td>
</tr>
<tr>
<td align="center">
<p><input type="submit" name="submit" value="Update Contact" /></p>
<br />
<p>Retuen To Menu</p>
</td>
</tr>
</table>
</form>
</body>
</html>
note for site admin, I am re posting this question with the hope of someone else reading over it. older questions seem to go dead after a while.
I think you're missing an "=" sign on the value attribute here:
$option_block .= "<option value\"$id\">$f_name, $l_name</option>";
Maybe you meant this?
$option_block .= "<option value=\"$id\">$f_name, $l_name</option>";