I am making a simple attendance class system
I have this php code with radio buttons here.. now i put it in a table
I can only choose one radio button on the entire table instead of one radio button per registered account
<?php
session_start();
if(!isset($_SESSION["in"]))
{
header("Location: log.php");
}
?>
<!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>Attendance</title>
</head>
<body>
<center>
<br />
<?php
echo "Today is " . date("m/d/Y") . "<br><br><br><br>";
?>
<?php
$conn= new mysqli("localhost", "root", "", "dbform");
$sql = "SELECT * FROM tblusers";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table width='1300' border='6'>
<tr>
<th width='100'>ID</th>
<th width='100'>Lastname</th>
<th width='100'>Firstname</th>
<th width='100'>Sex</th>
<th width='100'>Attendance</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr> ";
echo "<td align='center'>2016" . $row['id'] . "</td>";
echo "<td align='center'>" . $row['lastname'] . "</td>";
echo "<td align='center'>" . $row['firstname'] . "</td>";
echo "<td align='center'>" . $row['sex'] . "</td>";
?>
<form method="post" action="Succes_Submit_Attendace.php" name="submit_attendance">
attendance =
<td align='center'> <label><input type="radio" name="attendance" value="present">Present</label>
<label><input type="radio" name="attendance" value="absent">Absent</label><br /><br />
<?php
$row['attendance'] ;
?> </td>
<?php
echo " </tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn->close();
?>
<br>
<br>
<input type="reset"> <input type="submit" value="Submit Attendance"></h4>
</form>
<div align="right">
<h3>Back</h2>
</div>
All the radio buttons are of same name so you need to group them by row id. Change the input type to below :
<label><input type="radio" name="attendance[<?php echo $row['id']; ?>]" value="present">Present</label>
<label><input type="radio" name="attendance[<?php echo $row['id']; ?>]" value="absent">Absent</label><br /> <br />
Also there are HTML errors in your code. Please fix them
Related
I have been trying to make an online gateway for my college, where staff can nominate students for particular post or prizes. I used php with css for front end and phpmyadmin for back end. But once i give the input(regno) to nominate a student, it doesn't update in the table. Can anyone help? This 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>NOMINATE ENTRIES</title>
<meta author="" content="">
<link rel="stylesheet" type="text/css" href="view.css" media="all">
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>Nominate Entries</a></h1>
<form name="form5" class="appnitro" method="post" action="test.php">
<div class="form_description">
<center><h2>Students Database</h2></center>
<p><center><font size='3'>
<?php
$con=mysqli_connect("localhost","staff","12345","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM `student` WHERE `Nominated` = 0");
echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Department   </th>
<th>Name       </th>
<th>Class   </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['RegNo'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
if(isset($_POST['submit']))
{
$regno = $_POST['regno'];
$reason = $_POST['reason'];
$sql = "UPDATE `mop`.`student` SET `Nominated` = \'1\' WHERE `student`.`RegNo` = 1106103;";}
mysqli_close($con);
?>
</center></font>
</p>
</div>
<b>Enter Register Number <font color='red'>*</font> </b> <input type="text" id="regno" name="regno"><br>
<b>Enter Reason <font color='red'>*</font> </b> <input type="text" id="reason" name="reason"><br>
<ul >
<center><li class="buttons">
<input type="hidden" name="form_id" value="768845" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center>
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
You didn't actually send your query.
$result = $connection -> query($sql);
// Or, since it is only an update
$connection -> query($sql);
Where $connection is the connection to your DB
i have changed the whole file like this sir. thanks all for ur input wanted to share it for others:
here is my form.php file:
<!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>NOMINATE ENTRIES</title>
<meta author="" content="">
<link rel="stylesheet" type="text/css" href="view.css" media="all">
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<h1><a>Nominate Entries</a></h1>
<form name="form" class="appnitro" method="post" action="test.php">
<div class="form_description">
<center><h2>Students Database</h2></center>
<p><center><font size='3'>
<?php
$con=mysqli_connect("localhost","staff","123456","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM student");
echo "<table border='1'>
<tr>
<th>Register No</th>
<th>Name       </th>
<th>Department   </th>
<th>Class   </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['RegNo'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Department'] . "</td>";
echo "<td>" . $row['Class'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</center></font>
</p>
</div>
<b>Enter Register Number <font color='red'>*</font> </b> <input type="text" name="regno"><p>
<b>Enter Reason <font color='red'>*</font> </b> <input type="text" name="reason"><p>
<ul >
<center><li class="buttons">
<input type="hidden" name="form_id" value="768845" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /></center>
</li>
</ul>
</form>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>
it refers to the test.php file and here is that file too:
<?php
$con=mysqli_connect("localhost","staff","123456","mop");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql1="UPDATE student SET Reason = '$_POST[reason]' WHERE RegNo ='$_POST[regno]'";
if (!mysqli_query($con,$sql1))
{
die('Error: ' . mysqli_error($con));
}
else
{
$sql2="INSERT INTO nominated select * from student where regno = '$_POST[regno]'";
if (!mysqli_query($con,$sql2))
{
die('Error: ' . mysqli_error($con));
}
else
{
$sql3="DELETE from student where regno = ".intval($_POST["regno"]);
if (!mysqli_query($con,$sql3))
{
die('Error: ' . mysqli_error($con));
}
}
}
header("location:form5_1.php");
mysqli_close($con);
?>
THIS IS MY CODE HERE I AM GETTING PROBLEM THIS IS A INPUT TYPE TAG AND NOT SELECTED DATA FROM DATABASE USING PHP.
here is first part of this code is html formatted ad second part is php
i want select data from database to data slect to same page as we see on the sopping cart sites
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>phpSelect</title>
</head>
<body>
Insert Age for search
<form action="#" method="post" >
<input type="text" id="val" name="resValue" />
<input type="submit" value="submit" /></form>
<?php
if(isset($_POST['submit']))
{
$res=$_POST['resValue'];
echo $res;
}
//echo $res;
$con=mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons where Age=25");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Try changing the SQL to this
SELECT * FROM Persons where Age='".mysql_escape_string($formValue['val'])."'
First issue I found on your code is here:
<input type="submit" value="submit" />
it should be:
<input type="submit" value="submit" name="submit" />
To be able to get the results. Below are the codes:
<?php
$query = "";
if(isset($_POST['submit']))
{
$res=$_POST['resValue'];
$query = " where Age='$res'"
}
//echo $res;
$con=mysqli_connect("localhost","root","","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons $query");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Change your select query to this one.
SELECT * FROM Persons where Age='".mysql_escape_string($_POST['val'])."'
In your problem the all value of form get by the name of all fields of form.\
so here should be
<input type="submit" name="submit" value="submit"/>
Because in $_POST['submit'] submit is same as button's name.
$result = mysqli_query($con,"SELECT * FROM Persons where Age="25");
Can someone take a look at this and maybe see why this is not updating my database?
It is a form that pulls data from my database and when I click the update button it SHOULD update the database, but it dosn't.
Is there a way to show if it is returning a error?
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Beerlist Admin</title>
</head>
<body>
<?php include '../beerlist/config.php'; ?>
<table border="0" width="95%" align="center" cellspacing="0" cellpadding="5">
<tr>
<?php
#///////////////////////////////////
#//////////// ALL BEERS/////////////
#///////////////////////////////////
$sql = "SELECT * FROM bottles ORDER BY name";
$mydata = mysql_query($sql,$con);
if (isset($_POST['update'])){
$UpdateQuery = "UPDATE bottles SET new='$_POST[new]', name='$_POST[name], style='$_POST[style], location='$_POST[location], size='$_POST[size], abv='$_POST[abv], number='$_POST[number], price='$_POST[price]' WHERE name='$_POST[hidden]'";
mysql_query ($UpdateQuery, $con);
};
while($record = mysql_fetch_array($mydata)){
echo "<form action=beerlist_admin.php method=post>";
echo "<td><input size=7 type=text name=new value=\"" . $record['new'] . "\" > ";
echo "<input type=text size=50 name=name value=\"" . $record['name'] . "\" >";
echo "<input type=text size=20 name=style value=\"" . $record['style'] . "\" >";
echo "<input type=text size=20 name=location value=\"" . $record['location'] . "\" >";
echo "<input type=text size=7 name=size value=\"" . $record['size'] . "\" >";
echo "<input type=text size=5 name=abv value=\"" . $record['abv'] . "\" >";
echo "<input type=text size=5 name=number value=\"" . $record['number'] . "\" >";
echo "<input type=text size=7 name=price value=\"" .$record['price'] . " \" >";
echo "<input type=hidden name=hidden value=" . $record['number'] . "\"> <input type=submit name=update value=update></td></tr>";
echo "</form>";
}
echo "</table>"
?>
</body>
</html>
First and foremost, mysql_* has been deprecated and you should consider migrating to MySQLi or PDO and be prepared for when mysql_* gets removed so your site does not stop working.
Your code is wide open to SQL Injection you should use mysql_real_escape_string($variable) to prevent that.
With a combination of sprintf you can further define what kind of variable you are expecting, for example:
%s - is meant to be used for string data.
%d - is meant to be used for numbers, and presented as a (signed) decimal number.
On your the below example I've used only %s as I am unsure of the data you're trying to insert and your database table field types.
Your UPDATE query is poorly written and may cause issues in different cases depending on the data you provide it with so you should always be using the mysql_error at least during the development process so you can debug this sort of errors and once you move to a live site make those errors get logged silently to file instead.
You don't need to always use echo to print every little piece of HTML, see how I've changed your WHILE code.
Also the way you're using the form within the table while it may work its not the correct way.
Since you have not posted the contents of config.php I can't tell if there is any issues in there as well.
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Beerlist Admin</title>
</head>
<body>
<?php
$con = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$con)
{
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('beerlist', $con);
if (!$db_selected)
{
die ('Can\'t use foo : ' . mysql_error());
}
?>
<table border="0" width="95%" align="center" cellspacing="0" cellpadding="5">
<?php
if (isset($_POST['update']))
{
$UpdateQuery = sprintf("UPDATE bottles
SET new='%s',
name='%s',
style='%s',
location='%s',
size='%s',
abv='%s',
number='%s',
price='%s'
WHERE name='%s'",
mysql_real_escape_string($_POST['new']),
mysql_real_escape_string($_POST['name']),
mysql_real_escape_string($_POST['style']),
mysql_real_escape_string($_POST['location']),
mysql_real_escape_string($_POST['size']),
mysql_real_escape_string($_POST['abv']),
mysql_real_escape_string($_POST['number']),
mysql_real_escape_string($_POST['price']),
mysql_real_escape_string($_POST['hidden']));
if (!mysql_query($UpdateQuery))
{
die('Invalid query: ' . mysql_error());
}
}
$sql = "SELECT *
FROM bottles
ORDER BY name";
$mydata = mysql_query($sql);
if (!$mydata)
{
die('Invalid query: ' . mysql_error());
}
while($record = mysql_fetch_array($mydata))
{
?>
<form action="beerlist_admin.php" method="post">
<tr><td>
<input size="7" type="text" name="new" value="<?php echo $record['new']; ?>">
<input type="text" size="50" name="name" value="<?php echo $record['name']; ?>">
<input type="text" size="20" name="style" value="<?php echo $record['style']; ?>">
<input type="text" size="20" name="location" value="<?php echo $record['location']; ?>">
<input type="text" size="7" name="size" value="<?php echo $record['size']; ?>">
<input type="text" size="5" name="abv" value="<?php echo $record['abv']; ?>">
<input type="text" size="5" name="number" value="<?php echo $record['number']; ?>">
<input type="text" size="7" name="price" value="<?php echo $record['price']; ?>">
<input type="hidden" name="hidden" value="<?php echo $record['number']; ?>">
<input type="submit" name="update" value="update">
</td></tr>
</form>
<?php
}
?>
</table>
</body>
</html>
In the below code the list box is getting populated with the values but when I select the corresponding list value and click search the table is not getting displayed. I have used the SELF_PHP for the form action here also the idea of this form is that the list will be having and id's populated while the loading of the page. When I select a list value and click on the search button it should display the table with the values of only that ambulance ID or id which has been selected in the list box. Please help me.
<!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 charset="utf-8">
<title>TPS Login Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<center>
<h2>Ambulance Activity Log</h2>
<hr>
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
View activity of ambulance:
<Select NAME="field">
<?php
include 'con.php';
$query = "SELECT amb_id FROM ambulance;";
$result = mysql_query($query) or die("Unable to retreive amb_id :".mysql_error());
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
echo"<option id=\"ambid\" value=$row[amb_id]>$row[amb_id]</option>";
}
}
?>
</Select>
<input class="btn btn-info" type="submit" name="search" value="Search" />
<input type="hidden" name="searching" value="yes" />
</form>
<?php
if(isset($_POST['submit']))
{
$id=getElementById('ambid') ;
$query = "SELECT * FROM log WHERE amb_id='$id' ORDER BY l_time DESC;";
$result = mysql_query($query) or die(mysql_error());
print "
<table border=\"5\" cellpadding=\"5\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#808080\" width=\"800\" text-align=\"center\" id=\"AutoNumber2\" bgcolor=\"#C0C0C0\">
<tr>
<td width=\"30\">Amb ID</td>
<td width=\"120\">Event Time</td>
<td width=\"50\">Description</td>
<td width=\"30\">Signal ID</td>
<td width=\"30\">Road No</td>
<td width=\"30\">Priority</td>
</tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "<tr>";
print "<td>" . $row['amb_id'] . "</td>";
print "<td>" . $row['l_time'] . "</td>";
print "<td>" . $row['l_event'] . "</td>";
print "<td>" . $row['t_sigid'] . "</td>";
print "<td>" . $row['l_roadno'] . "</td>";
print "<td>" . $row['e_priority'] . "</td>";
print "</tr>";
}
print "</table>";
print "</center>";
}
?>
</body>
</html>
Please help me.
Thanks in advance :)
Give the <select> Tag a better name . And quote your "$row[amb_id]". value=$row[amb_id] ! is wrong.
<select name="ambid" size="10">
....
{
echo"<option value=\"$row[amb_id]\">$row[amb_id]</option>";
}
</select>
After post you can get it with :
if(isset($_POST['submit']))
{
$id=$_POST['ambid'];
$query = "...
I have been on this for hours on end. When I get one thing working something else doesn't work. Well now my page is not loading to the one it is suppose to. It is loading to the content page and not the form page.I have the home page in for the users to enter in there username and passowrd and if they dont have one then they can register on the form. I put all the forms on there. I don't know what I am doing wrong. Like I said I been working on this for hours. Can someone help me thanks.
Its not loading to the form it skips right over it to the content page. So if you click on register to the form you wont see it. It will go to the content page.
Here are my codes
This one is form page..
<?php
function FormDisplay($strMessage="**All fields are required!"){
echo "<p><strong>".$strMessage."</strong></p>\n";
echo "<form action=\"".$PHP_SELF."\" method=\"post\">\n";
echo "<table width=\"300\" cellpadding=\"2\" cellspacing=\"2\">\n";
echo "<tr>\n";
echo " <td><strong>Username:</strong></td>\n";
echo " <td><input type=\"text\" name=\"username\" value=\"". $_POST['username']."\"/> \n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Password:</strong></td>\n";
echo " <td><input type=\"password\" name=\"password1\" />\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td nowrap=\"nowrap\"><strong>Repeat Password:</strong></td>\n";
echo " <td><input type=\"password\" name=\"password2\" /> \n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>First name:</strong></td>\n";
echo " <td><input type=\"text\" name=\"firstname\" value=\"". $_POST['firstname']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Last name:</strong></td>\n";
echo " <td><input type=\"text\" name=\"lastname\" value=\"". $_POST['lastname']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Email:</strong></td>\n";
echo " <td><input type=\"text\" name=\"email\" value=\"". $_POST['email']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Address:</strong></td>\n";
echo " <td><input type=\"text\" name=\"address\" value=\"". $_POST['address']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>City:</strong></td>\n";
echo " <td><input type=\"text\" name=\"city\" value=\"". $_POST['city']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>State:</strong></td>\n";
echo " <td><input type=\"text\" name=\"state\" value=\"". $_POST['state']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Zip:</strong></td>\n";
echo " <td><input type=\"text\" name=\"zip\" value=\"". $_POST['zip']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Phone:</strong></td>\n";
echo " <td><input type=\"text\" name=\"phone\" value=\"". $_POST['phone']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td> </td>\n";
echo " <td><input type=\"submit\" name=\"submit\" value=\"Sign up now!\". class=\"submit\" />\n";
echo "</tr>\n";
echo "<tr>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
if ($_POST['submit']!=""){
if ($_POST['username']==""||$_POST['password1']==""||$_POST['password2']==""||$_POST['firstname']==""||$_POST['lastname']==""||$_POST['address']==""||$_POST['email']==""||$_POST['city']==""||$_POST['state']==""||$_POST['zip']==""||$_POST['phone']=="");
$error=1;
}
else if ($_POST['password1']!=$_POST['password2']){
$error=2;
}
else{
$hostname="localhost";
$database="Contacts";
$mysql_login="Web_User";
$mysql_password="my1230";
if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
echo "error on connect";
}
else{
if (!(mysql_select_db($database,$db))){
echo mysql_error();
echo "<br>error on table connection";
}
else{
$SQL="Insert into tblUsers(username,password,firstname,lastname,email,address,city,state,zip, phone,signupDate)values)'".$_POST['username']."',PASSWORD('".$_POST['password1']."'),'".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['address']."','".$_POST['city']."','".$_POST['state']."','".$_POST['zip']."','".$_POST['phone']."',NOW())";
mysql_query($SQL);
if (is_numeric(mysql_insert_id())){
header("Location:member-content.php?name=".$_POST['username']);
}
else{
echo "Sorry, there was an error.Please try again ot contact the administrator";
}
mysql_close($db);//closeing out connection,done for now
}
}
}
?>
<!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=iso-8859-1" />
<link rel="style.css" type="text/css" >
<title>Members Only Framework::Signup page/title>
</head>
<body>
<hr />
<h2>Become a member of the coolest website on the net!</h2>
<hr />
<?php
if ($error==1){
FormDisplay("You did not enter all required fields");
}
elseif ($error==2){
FormDisplay("Your Passwords did not match");
}
else{
FormDisplay();
}
?>
</body>
</html>
This is the signin form:
<?php
include("config.php");
if ($_POST['username']==""|| $_POST['password']==""){
header("Location:member-home.php?mode=1");
}
else{
$hostname="localhost";
$database="contacts";
$mysql_login="Web_User";
$mysql_password="my1230";
if (!($db = mysql_connect($hostname, $mysql_login, $mysql_password))){
echo "error on connect";
}
else{
if (!(mysql_select_db($database,$db))){
echo mysql_error();
echo "<br>error on db connection";
}
}
$SQL="Select username from tblusers where username='".$_POST['username']."' AND password=PASSWORD('".$_POST['password']."')";
$resultSet=mysql_query($SQL);
if (mysql_num_rows($resultSet)>0){
$username=mysql_result($resultSet,0,"username");
header("Location:member-content.php?name=".$username);
}
else{
header("Location:member-home.php?mode=2");
}
}
?>
</body>
</html>
and this is the home:
<!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" />
<link href="style.css" type="text/css">
<title>Members Only Framework::Login Page</title>
</head>
<body>
<hr />
<h3>Welcome Members!!</h3>
<hr />
<p>Not a member yet? Click here to join!</p>
<?php
if ($_GET['mode']==1){
echo "<p style=\"color:red;\"><strong>Please enter your username and password!</strong></p>";
}
else if ($_GET['mode']==2){
echo "<p style=\"color:red;\"><strong>Sorry, there is no user with that name!</strong></p>";
}
else if ($_GET['mode']==3){
$username=$_GET['username'];
echo "<p style=\"color:red;\"><strong>".$username.".please login using the username and password</strong></p>";
}
?>
<p>Current members enter your username and password:</p>
<form action="member-signin.php" method="post">
<table width="200" cellpadding="2" cellspacing="2">
<tr>
<td><strong>Username:</strong></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><strong>Password:</strong></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Log in now!" class="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
You have a misplaced semicolon in your member-form.php:
if ($_POST['username']==""||$_POST['password1']==""||$_POST['password2']==""||$_POST['firstname']==""||$_POST['lastname']==""||$_POST['address']==""||$_POST['email']==""||$_POST['city']==""||$_POST['state']==""||$_POST['zip']==""||$_POST['phone']=="");
so you need to replace it with opening curly bracket.