I have two php files, form and the results page. Form page accepts user info and the result pages inserts the information into the database and displays it.
form page code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Record Insertion Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
echo "<div style='font-size: large; font-family: sans-serif'><center><h1>
<p style='color: white; background-color: black'>Resume Generator</p></h1></center> </div>";
echo "Mandotary fields with <font color='red'>*</font> are required!";
?>
<form id="form1" name="form1" method="post" action="resumeinsert.php">
<fieldset>
<legend>Personal Details</legend>
<input type="hidden" name="id" id="id" />
<br class="clear" />
<label for="name"><font color="red">*</font> Name:</label><input type="text" name="name" id="name" />
<br class="clear" />
<label for="gender"><font color="red">*</font> Gender:</label>
<input type="radio" name="gender" value="Male" id="gender_0" />Male
<input type="radio" name="gender" value="Female" id="gender_1" />Female
<br class="clear" />
<label for="dateofbirth"><font color="red">*</font> Date of birth:</label><input type="text" name="dateofbirth" id="dateofbirth" />
<br class="clear" />
<label for="placeofbirth"><font color="red">*</font> Place of birth :</label><input type="text" name="placeofbirth" id="placeofbirth" />
<br class="clear" />
<label for="address"><font color="red">*</font> Address:</label><textarea name="address" id="address" cols="45" rows="5"></textarea>
<br class="clear" />
</fieldset>
<fieldset>
<legend><b>Educational Details</b></legend>
<label for="schoolname"><font color="red">*</font> School name:</label><input type="text" name="schoolname" id="schoolname" size=50 />
<br class="clear" />
<label for="qualification"><font color="red">*</font> Qualification(s):</label><textarea name="qualification" id="qualification" cols="45" rows="5"></textarea>
<br class="clear" />
<label for="skills1"><font color="red">*</font> Skills 1:</label><textarea name="skills1" id="skills1" cols="45" rows="5"></textarea>
<br class="clear" />
<label for="skills2">Skills 2:</label><textarea name="skills2" id="skills2" cols="45" rows="5"></textarea>
<br class="clear" />
</fieldset>
<fieldset><legend><b>Other Details</b></legend>
<label for="awards">Awards:</label><textarea name="awards" id="awards" cols="45" rows="5"></textarea>
<br class="clear" />
<label for="Volunteer">Volunteer:</label><textarea name="Volunteer" id="Volunteer" cols="45" rows="5"></textarea>
<br class="clear" />
<input type="submit" name="submit" id="submit" value="Submit" />
<br class="clear" />
</fieldset>
</form>
</body>
</html>
resumeinsert.php page code:
<?php
$mysqli = mysqli_connect("localhost", "hecton", "ccna", "joomladb");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$id = $_POST['id'];
$name = $_POST['name'];
$gender = $_POST['gender'];
$dateofbirth = $_POST['dateofbirth'];
$placeofbirth = $_POST['placeofbirth'];
$address = $_POST['address'];
$schoolname = $_POST['schoolname'];
$qualification = $_POST['qualification'];
$skills1 = $_POST['skills1'];
$skills2 = $_POST['skills2'];
$awards = $_POST['awards'];
$Volunteer = $_POST['Volunteer'];
$query = " INSERT INTO j71mi_resumeinfo ( id, name, gender, dateofbirth, placeofbirth, address, schoolname, qualification, skills1, skills2, awards, Volunteer ) VALUES ( '$id', '$name', '$gender', '$dateofbirth', '$placeofbirth', '$address', '$schoolname', '$qualification', '$skills1', '$skills2', '$awards', '$Volunteer' ) ";
$result = mysqli_query($mysqli, $query);
if ($result === TRUE) {
echo "A record has been successfully inserted into the database!.";
echo "<b><h1><center>My Resume</h1></b></center>";
echo "<div style='font-size: large; font-family: sans-serif'>
<p style='color: white; background-color: black'>Personal Details</p></div>";
echo "<br>";
echo "<b>Name:</b>".$_POST['name'];
echo "<br>";
echo "<b>Gender:</b>".$_POST['gender'];
echo "<br>";
echo "<b>Date of Birth:</b>".$_POST['dateofbirth'];
echo "<br>";
echo "<b>Place of Birth:</b>".$_POST['placeofbirth'];
echo "<br>";
echo "<b>Home Address:</b>".$_POST['address'];
echo "<div style='font-size: large; font-family: sans-serif'>
<p style='color: white; background-color: black'>Educational Details</p></div>";
echo "<br>";
echo "<b>School Name:</b>".$_POST['schoolname'];
echo "<br>";
echo "<b>Qualification(s):</b>".$_POST['qualification'];
echo "<br>";
echo "<b>Skill 1:</b>".$_POST['skills1'];
echo "<br>";
echo "<b>Skill 2:</b>".$_POST['skills2'];
echo "<br>";
echo "<div style='font-size: large; font-family: sans-serif'>
<p style='color: white; background-color: black'>Other Details</p></div>";
echo "<br>";
echo "<b>Award(s):</b>".$_POST['awards'];
echo "<br>";
echo "<b>Volunteer Activity:</b>".$_POST['Volunteer'];
echo "<br>";
echo "<br>";
echo "<b><h5><center>End of Resume</h5></b></center>";
} else {
printf("Could not insert record: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);
}
?>
My problem is that user sometimes submit the form without even filling out all the fields and it displays " Name: ", which contains nothing.
How can I make the users to fill out the missing required fields after they click submit button with a red text next to the missing fields ? So that empty fields are not sent to database.
2.Some fields are set to NULL in the database, which means the field is optional. How can I not display that specific field in display page if user enters nothing in the form?
You have to validate the form. Use simple checks to determine if fields are filled correctly. Check for empty, alphanumeric, and what ever else you need. It would probably be best to check in the front end before you send the data over to the server. Here are some examples to get you started:
JS Form validation
http://www.w3schools.com/js/js_form_validation.asp
JS Form validation
http://www.tizag.com/javascriptT/javascriptform.php
PHP Form validation
http://www.w3schools.com/php/php_form_validation.asp
Check out these examples and implement something similar to this. Even if you end up validating the form in JS don't forget to implement the bare minimum checks in PHP.
Related
Im having some trouble uploading an image with php to phpmyadmin.
Here is my markup so far.
<form method="post">
<p>Event Date<span> - eg "23" for the 23rd</span><br /> <input type="text" name="eventDate" maxlength="2" required /> </p>
<p>Event Month<span> - eg "Mar" for March</span> <br /><input type="text" name="eventMonth" maxlength="3" required /> </p>
<p>Artist Image <br /><input type="file" name="artistImage" required /> </p>
<p>Artist Name <br /><input type="text" name="artistName" maxlength="30" required /> </p>
<p>Location <br /><input type="text" name="location" maxlength="30" required /> </p>
<p>Price <br /><input type="text" name="price" maxlength="10" required /> </p>
<p>Time <br /><input type="text" name="time" maxlength="10" required /> </p>
<input id="eventSubmit" type="submit" name="submitEvent" />
</form>
and here is my php code
`
if(isset($_POST['submitEvent'])){
$addEventDate = $_POST['eventDate'];
$addEventMonth = $_POST['eventMonth'];
$addEventName = $_POST['artistName'];
$addEventLocation = $_POST['location'];
$addEventPrice = $_POST['price'];
$addEventTime = $_POST['time'];
$addEventImg = $_FILES['artistImage']['name'];
$temp_name1 = $_FILES['artistImage']['tmp_name'];
move_uploaded_file($temp_name1, "img/$addEventImg");
$ticket= 1;
$insert_product = "INSERT INTO events (eventDate,eventMonth,artistImg,artistName,location,price,time,buyTicket) VALUES ('$addEventDate','$addEventMonth','$addEventImg','$addEventName','$addEventLocation','$addEventPrice','$addEventTime','$ticket')";
$run_product = mysqli_query($con,$insert_product);
echo mysqli_error($con);
if($run_product){
echo "<script>alert('Product has been inserted.');</script>";
echo "<script>window.open('admin.php','_self');</script>";
}
}
?>`
I have set the database up to take the image as a blob here is a picture of my database
and this is the code that is rendering the products onto the events page.
<?php
$get_events = "select * from events";
$run_events = mysqli_query($con,$get_events);
while($row_events = mysqli_fetch_array($run_events)){
$eventDate = $row_events['eventDate'];
$eventMonth = $row_events['eventMonth'];
$artistImg = $row_events['artistImg'];
$artistName = $row_events['artistName'];
$location = $row_events['location'];
$price = $row_events['price'];
$time = $row_events['time'];
$buyTicket = $row_events['buyTicket'];
echo "
<div class='eventBox'>
<div class='dateBanner'>
<p><span>$eventDate</span><br />$eventMonth</p>
</div>
<img src='img/$artistImg' alt='event image' />
<div class='eventDetails'>
<h2>$artistName</h2>
<p><span>Location</span> <br /> $location<br /><br /><span>Ticket Price</span> <br /> £$price<br /><br /><span>Time</span> <br />$time<br /><br /></p>
</div>
<div class='PurchaseTicket'>
<h3>Buy Ticket</h3>
</div>
</div>
";
}
?>
This works for everything apart from the image. The image just displays the alt tag not the actual image. It also doesn't save the image in the folder either.
If anyone could help I'd really appreciate it!!
Thanks
is it possible for me to do an auto increment number in a sequential text that can be display in PHP and HTML, for example;
SKP/SH/1(AUTO_INCREMENT)/2017
SKP/SH/2/2017
Only the number is increase, and the SKP/SH/""/2017 is fixed.
Thanks in advance, appreciate your help!
side note: I already set primary key and auto increment in mysql (separated with 2 column for ID and CODE)
HTML:
<form name=b onsubmit="return check()" action="form.php" method="post">
Nama Program: <br />
<textarea required name="program" cols="50" rows="10"></textarea><br />
<p></p>
Tarikh Program Mula: <br />
<input required name="tarikhmula" type="text" class="datepicker">
<p></p>
Tarikh Program Tamat: <br />
<input required name="tarikhtamat" type="text" class="datepicker">
<p></p>
Sebut Harga Bilangan: <br />
<p></p>
Kod Sebut Harga: <br />
<input required name="kodsebutharga" type="text" value="SKP/SH/2017" />
<p></p>
Tarikh Iklan Dibuka: <br />
<input required name="iklanmula" type="text" class="datepicker">
<p></p>
Tarikh Iklan Ditutup: <br />
<input required name="iklantamat" type="text" class="datepicker">
<p></p>
Nama Pegawai Penyelaras: <br />
<input required name="namapegawai" type="text" />
<p></p>
Anggaran Harga Jabatan: <br />
<input required name="anggaranharga" type="text" id="number" pattern="[0-9]*">
<p></p>
<input name="" type="submit" /><input name="" type="reset" value="Clear" />
</form>
</body>
</html>
PHP:
<?php
require("config.php");
$link =mysqli_connect($h,$u,$p,$db);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
error_reporting(E_ALL ^ E_DEPRECATED);
$query = "insert into atas50 (program, tarikhmula, tarikhtamat, namapegawai, anggaranharga, iklanmula, iklantamat) values ('$_POST[program]','$_POST[tarikhmula]','$_POST[tarikhtamat]','$_POST[namapegawai]','$_POST[anggaranharga]','$_POST[iklanmula]','$_POST[iklantamat]')";
if (mysqli_query($link, $query)) {
//echo "New record created successfully";
$message = "New record created successfully";
echo "<script type='text/javascript'>alert('$message');</script>";
header( "refresh:0; url=view.php" );
} else {
echo "Error: " . $query . "<br>" . mysqli_error($link);
}
mysqli_close($link);
?>
Something like this should work (pseudo-code):
$counter = 1;
while ($row = fetch_from_database()) {
echo 'SKP/SH'+$counter+'/2017';
$counter++;
}
Note that this is entirely pseudo-code, and you'll have to implement it as you need.
im having a problem when trying to implement a edit page in php.
Getting items from the database doesent pose any problem, yet trying to update it tells me that i have missed a field and trying to skip the check just leaves me with a unedited table.
To explain more, there is a page that directs to this one while passing on a id (propertyID) veriable and from that we use it to grab the desired variables.
Can anyone look at the code and tell me what i have done wrong, i have prevously got a similar page working and am getting quite flustered trying to figure out why this one isent.
<?php
// Start sessions
include('includes/security.inc.php');
authorise();
if (!isset($_GET['propertyID']) || !is_numeric($_GET['propertyID']))
{
header('Location:./houselist.php');
}
else
{
// Include connection file
include('includes/connection.inc.php');
// Get details
connect();
$propertyID = $_GET['propertyID'];
$sql = "SELECT * FROM Properties WHERE propertyID='$propertyID' LIMIT 1";
$result = #mysql_query($sql) or die('Unable to run query');
$record = mysql_fetch_object($result);
mysql_close();
// Check to see if the form has been submitted
if (isset($_POST['submit']))
{
// Check to see all fields have been completed
$address = $_POST['address'];
$categoryID = $_POST['categoryID'];
$price = $_POST['price'];
$landlordName = $_POST['landlordName'];
$img = $_POST['img'];
$description= $_POST['description'];
if (!empty($address) && !empty($categoryID) && !empty($price) && !empty($landlordName) && !empty($img) && !empty($description))
{
// Create an SQL query to add the comment
$sql = "UPDATE property SET propertyID = '$propertyID', img = '$img', address = '$address', price = '$price', landlordName = '$landlordName', description = '$description' WHERE propertyID = $propertyID";
// Connect to the database
connect();
// Run the query and store the result in a variable
$result = mysql_query($sql) or die("Could not run query1");
// Close connection to the database
mysql_close();
// Check if query was successful
if ($result)
{
$message = '<div class="success"><p>You have successfully edited Article details.</p><p>Please Click Here to view the Animal list.</p></div>';
}
else
{
$message = '<div class="error"><p>There was an error editing details, please try again</p></div>';
}
}
else
{
$message = '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
}
}
?>
<!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 rel="stylesheet" type="text/css" href="css/960.css"/>
<link rel="stylesheet" type="text/css" href="css/demo.css"/>
<link rel="stylesheet" type="text/css" href="css/960_24_col.css"/>
<link rel="stylesheet" type="text/css" href="css/reset.css"/>
<link rel="stylesheet" type="text/css" href="css/text.css"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<title>Complete Property Solutions</title>
<title>Homescreen - Complete Property Solutions</title>
</head>
<body>
<div class="container_24" id="container">
<div class="grid_24" id="banner">
<img src="img/banner.png" width="960" height="92" />
</div>
<div class="grid_18" id="nav" align="right">
<ul id="topnav">
<li>Home</li>
<li>Properties</li>
<li>Landlords</li>
<li>Tenants</li>
<li>Logout</li>
</ul>
</div>
<div class="grid_6" id="search" align="right">
<form action="search.php" method="GET">
<input type="text" name="term" size="15">
<input type="submit" value="Search">
</form>
</div>
</div>
<div class="container_24" id="container" align="center">
<div id="container">
<form id="PropertyEdit" name="PropertyEdit" method="post" action="<? echo $_SERVER['PHP_SELF'] . "?propertyID=" . $propertyID; ?>">
<input type="hidden" name="propertyID" id="propertyID" value="<?php echo $propertyID; ?>" />
<?php
if (isset($message))
{
echo $message;
}
else
{
?>
<div class="label"><label for="propertyID"></label></div>
<div class="input"><input type="hidden" name="propertyID" id="propertyID" tabindex="1" value="<? echo $record->propertyID; ?>" /></div>
<br />
<div class="label"><label for="categoryID">Category</label></div>
<div class="input"><input type="text" name="categoryID" id="categoryID" tabindex="1" value="<? echo $record->categoryID; ?>" /></div>
<br />
<div class="label">
<label for="address">Address:</label></div>
<div class="input"><input type="text" name="address" id="address" tabindex="1" value="<? echo $record->address; ?>" /></div>
<br />
<div class="label"><label for="price">Price:</label></div>
<div class="input"><input type="text" name="Price" id="price" tabindex="3" value="<? echo $record->price; ?>" /></div>
<div class="label"><label for="landlordName">Landlord</label></div>
<div class="input"><input type="text" name="landlordName" id="landlordName" tabindex="1" value="<? echo $record->landlordName; ?>" /></div>
<br />
<div class="label"><label for="img">Image</label></div>
<div class="input"><input type="text" name="img" id="img" tabindex="1" value="<? echo $record->img; ?>" /></div>
<br />
<div class="label"><label for="description">Description:</label></div>
<div class="input"><textarea name="description" id="description" cols="50" rows="10" tabindex="5"><? echo $record->description; ?></textarea></div>
<br />
<div class="label"> </div>
<div class="input">
<input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
<input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />
</div>
<p class="normal">Click Here to Return to the Home page</p>
<?php
}
?>
</form> </div>
</div>
</body>
</html>
<?php
}
?>
my best guess for the problem would revolve around
// Check to see if the form has been submitted
if (isset($_POST['submit']))
{
// Check to see all fields have been completed
$address = $_POST['address'];
$categoryID = $_POST['categoryID'];
$price = $_POST['price'];
$landlordName = $_POST['landlordName'];
$img = $_POST['img'];
$description= $_POST['description'];
if (!empty($address) && !empty($categoryID) && !empty($price) && !empty($landlordName) && !empty($img) && !empty($description))
{
// Create an SQL query to add the comment
$sql = "UPDATE property SET propertyID = '$propertyID', img = '$img', address = '$address', price = '$price', landlordName = '$landlordName', description = '$description' WHERE propertyID = $propertyID";
// Connect to the database
connect();
// Run the query and store the result in a variable
$result = mysql_query($sql) or die("Could not run query1");
// Close connection to the database
mysql_close();
// Check if query was successful
if ($result)
{
$message = '<div class="success"><p>You have successfully edited Article details.</p><p>Please Click Here to view the Animal list.</p></div>';
}
else
{
$message = '<div class="error"><p>There was an error editing details, please try again</p></div>';
}
}
else
{
$message = '<div class="error"><p>Please make sure you fill all fields in before submitting the form.</p></div>';
}
}
And the below section, my problem is that im not sure where exactly
<div class="container_24" id="container" align="center">
<div id="container">
<form id="PropertyEdit" name="PropertyEdit" method="post" action="<? echo $_SERVER['PHP_SELF'] . "?propertyID=" . $propertyID; ?>">
<input type="hidden" name="propertyID" id="propertyID" value="<?php echo $propertyID; ?>" />
<?php
if (isset($message))
{
echo $message;
}
else
{
?>
<div class="label"><label for="propertyID"></label></div>
<div class="input"><input type="hidden" name="propertyID" id="propertyID" tabindex="1" value="<? echo $record->propertyID; ?>" /></div>
<br />
<div class="label"><label for="categoryID">Category</label></div>
<div class="input"><input type="text" name="categoryID" id="categoryID" tabindex="1" value="<? echo $record->categoryID; ?>" /></div>
<br />
<div class="label">
<label for="address">Address:</label></div>
<div class="input"><input type="text" name="address" id="address" tabindex="1" value="<? echo $record->address; ?>" /></div>
<br />
<div class="label"><label for="price">Price:</label></div>
<div class="input"><input type="text" name="Price" id="price" tabindex="3" value="<? echo $record->price; ?>" /></div>
<div class="label"><label for="landlordName">Landlord</label></div>
<div class="input"><input type="text" name="landlordName" id="landlordName" tabindex="1" value="<? echo $record->landlordName; ?>" /></div>
<br />
<div class="label"><label for="img">Image</label></div>
<div class="input"><input type="text" name="img" id="img" tabindex="1" value="<? echo $record->img; ?>" /></div>
<br />
<div class="label"><label for="description">Description:</label></div>
<div class="input"><textarea name="description" id="description" cols="50" rows="10" tabindex="5"><? echo $record->description; ?></textarea></div>
<br />
<div class="label"> </div>
<div class="input">
<input type="reset" name="reset" id="reset" value="Reset" tabindex="6" />
<input type="submit" name="submit" id="submit" value="Submit" tabindex="7" />
This code is just refreshing my page. I cant see any errors. Maybe someone else can see the error here in code? I have the same code in two other pages and they do UPDATE.
The code below is in one page:
<body>
<?php
$query=mysqli_connect("localhost","user","","mydb") or die ("Ne moga da se svyrja s bazata danni.");
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['submit']))
{
$datetime=$_POST['datetime'];
$vlekach_teltur=$_POST['vlekach_teltur'];
$driver1=$_POST['driver1'];
$telnomer=$_POST['telnomer'];
$belejka=$_POST['belejka'];
$user=$_POST['user'];
mysqli_set_charset($query,"utf8");
$sql="update teltur set datetime = '$datetime', vlekach_teltur = '$vlekach_teltur', driver1 = '$driver1', telnomer = '$telnomer', belejka = '$belejka', user = '$user' where id='$id'";
$query3 = mysqli_query($query, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error(), E_USER_ERROR);
if(mysqli_query($query3, $sql)){
echo "
<!DOCTYPE html>
<script>
function redir()
{
alert('Успешен запис!');
window.location.assign('index.php');
}
</script>
<body onload='redir();'></body>";
}
else{
echo "Не успешен запис, свържете се с администратора $query3. " . mysqli_error($query);
}
}
mysqli_set_charset($query,"utf8");
$sql2="select * from teltur where id='$id'";
$query1=mysqli_query($query, $sql2);
$query2=mysqli_fetch_array($query1);
?>
<h3 style="text-align:center;">Редакция на телефони Турция</h3>
<form id="docContainer" class="fb-toplabel fb-100-item-column selected- object" enctype="multipart/form-data" method="post" action="">
<div id="section1" class="section">
<div id="column1" class="column ui-sortable">
<div class="fb-grouplabel">
<p>Дата<input type="text" id="datetime" name="datetime" value="<?php echo $query2['datetime']; ?>"/>
<label id="datecheckalert" style="color: red; font-style: italic;"> </label></p>
</div>
<p>Влекач:
<input type="text" name="typeahead" class="typeahead tt-query" autocomplete="on" spellcheck="false" value="<?php echo $query2['vlekach_teltur']; ?>">
</p>
<div id="scrollable-dropdown-menu">
<p>Шофьор:
<input type="text" name="driver1" class="driver1 tt-query" autocomplete="on" spellcheck="false" value="<?php echo $query2['driver1']; ?>">
</p>
</div>
<div id="scrollable-dropdown-menu">
<p>Телефонен номер:
<input type="text" name="telnomer" class="telnomer tt-query" autocomplete="on" spellcheck="false" value="<?php echo $query2['telnomer']; ?>"/>
</p>
</div>
<p>Забележка:
<input type="text" name="belejka" value="<?php echo $query2['belejka']; ?>"/>
</p>
<p>Потребител:
<select id="user" name="user">
<option value="<?php echo $query2['user']; ?>"><?php echo $query2['user']; ?></option>
</select></p>
<p align="center">
<input type="submit" value="ЗАПИС" />
</p>
</div>
</div>
<?php
}
?>
</form>
</body>
I have error reporting as you see but no errors found.
Yeah im so stupid, i missed to name the Submit button.
<input type="submit" value="ЗАПИС" />
Changed to this code: <input type="submit" name="submit" value="ЗАПИС" />
I spend tree hours and after make a post here i found it by my self.
Can some one just delete this thread?
I need your help. So the problem is that I've done some coding but I don't know why it doesn't work when page loads. But when I trigger any button (Save Info Modification Or Cancel Info Modification) it works.
php code :
if(isset($_POST['nametb']) && isset($_POST['usernametb']) && isset($_POST['emailtb']) && isset($_POST['confirmtb']) && isset($_POST['abouttb']) && isset($_POST['interesttb']) && isset($_POST['dreamtb']) && isset($_POST['liketb']) && isset($_POST['schooltb']) && isset($_POST['schoolyrtb']) && isset($_POST['occupationtb']) && isset($_POST['occupationyrtb'])){
$select_info = "SELECT * from user_info WHERE id='$user_id'";
if($select_info_run = #mysql_query($select_info)){
$namedb = mysql_result($select_info_run, 0, 'name');
$usernamedb = mysql_result($select_info_run, 0, 'username');
$emaildb = mysql_result($select_info_run, 0, 'email');
$confirmdb = mysql_result($select_info_run, 0, 'email');
$aboutdb = mysql_result($select_info_run, 0, 'about');
$interestdb = mysql_result($select_info_run, 0, 'interest');
$dreamdb = mysql_result($select_info_run, 0, 'dream');
$likedb = mysql_result($select_info_run, 0, 'like');
$schooldb = mysql_result($select_info_run, 0, 'school');
$schoolyrdb = mysql_result($select_info_run, 0, 'schoolyr');
$occupationdb = mysql_result($select_info_run, 0, 'occupation');
$occupationyrdb = mysql_result($select_info_run, 0, 'occupationyr');
}
else{
echo 'Server down :(';
}
}
else{
echo server down :(';
}
html code :
<form action="<?php if(isset($current_file)){ echo $current_file; } ?>" method="POST">
<fieldset id="fieldset1">
<legend style="font-family: Ubuntu; font-size:20px;">Info</legend>
<label id="name" title="Name" for="textbox1">Name :</label>
<label id="username" title="UserName" for="textbox2">UserName :</label>
<label id="email" title="Email" for="textbox3">Email :</label>
<label id="confirm" title="Confirm Email" for="textbox4">Confirm :</label>
<br />
<input type="text" id="textbox1" name="nametb" value="<?php if(isset($namedb)){ echo $namedb; } ?>" />
<input type="text" id="textbox2" name="usernametb" value="<?php if(isset($usernamedb)){ echo $usernamedb; } ?>" />
<input type="text" id="textbox3" name="emailtb" value="<?php if(isset($emaildb)){ echo $emaildb; } ?>" />
<input type="text" id="textbox4" name="confirmtb" value="<?php if(isset($confirmdb)){ echo $confirmdb; } ?>" />
<br /><br />
<div id="hrln"><hr /></div>
<label id="about" title="About you" for="textarea1">About :</label>
<label id="interest" title="You are interested in?" for="textarea2">Interested in :</label>
<br />
<textarea id="textarea1" name="abouttb"><?php if(isset($aboutdb)){ echo $aboutdb; } ?></textarea>
<textarea id="textarea2" name="interesttb"><?php if(isset($interestdb)){ echo $interestdb; } ?></textarea>
<br /><br /><br /><br /><br /><hr />
<label id="dream" title="Your Dream?" for="textarea3">Dream :</label>
<label id="like" title="What do you like?" for="textarea4">You like :</label>
<br />
<textarea id="textarea3" name="dreamtb"><?php if(isset($dreamdb)){ echo $dreamdb; } ?></textarea>
<textarea id="textarea4" name="liketb"><?php if(isset($likedb)){ echo $likedb; } ?></textarea>
<br /><br /><br /><br /><br /><hr />
<label id="education" title="Your school" for="textbox5">School | University :</label>
<label id="educationyr" title="Year" for="textbox6">Year :</label>
<br />
<input type="text" name="schooltb" id="textbox5" value="<?php if(isset($schooldb)){ echo $schooldb; } ?>" />
<input type="text" name="schoolyrtb" id="textbox6" value="<?php if(isset($schoolyrdb)){ echo $schoolyrdb; } ?>" />
<br /><br /><hr />
<label id="occupation" title="Occupation" for="textbox7">Occupation :</label>
<label id="occupationyr" title="Year" for="textbox6">Year :</label>
<br />
<input type="text" id="textbox7" name="occupationtb" value="<?php if(isset($occupationdb)){ echo $occupationdb; } ?>" />
<input type="text" id="textbox8" name="occupationyrtb" value="<?php if(isset($occupationyrdb)){ echo $occupationyrdb; } ?>" />
<br /><br /><hr />
<label id="passwords" title="For Security Purpose" for="textbox9">Password :</label>
<input type="password" id="textbox9" name="passwordstb" />
<input type="submit" value="Save Info Modification" name="save" id="button1" />
<input type="submit" value="Cancel Info Modification" name="cancel" id="button2" />
</fieldset>
</form>
Do you want the form to display? Then, get rid of that echo in the last "else". Then the form will display. When a user clicks the submit button, the form will post that information to the page.
Also, your 2nd "else{ echo server down :('; }" is missing a quote before 'server down :(';
The key to your problems is what I call "isolation": you need to isolate what is causing the issue. I recommend the "comment-out-code-and-refresh-page" technique if you're pressed for time. But it's far better to analyze and interpret your code and UNDERSTAND why it's not doing what you want.
It runs when you click the buttons because of this:
if(isset($_POST['nametb']) && isset($_POST['usernametb']) && isset($_POST['emailtb']) &&
isset($_POST['confirmtb']) && isset($_POST['abouttb']) && isset($_POST['interesttb']) &&
isset($_POST['dreamtb']) && isset($_POST['liketb']) && isset($_POST['schooltb']) &&
isset($_POST['schoolyrtb']) && isset($_POST['occupationtb']) &&
isset($_POST['occupationyrtb'])){
Your if statement is checking if anything in the POST array is set before doing anything.
This is sent by the form when you click a submit button (which is either button, it seems).
If you are trying to populate the fields on page load, you need to move your SELECT statement an related code outside of that if statement. Since it seems you would be using this form to update database data, you should put your INSERT/UPDATE statements inside the if statement so that they won't run until you click the submit button (pending other logical operations to take into account WHICH button was pressed.).