I started making site for songs. It is lyrics site and I wanted a search engine that works something like picture below.
It should works with URL.
<form action="#" method="POST">
<input type="text" name="search"/>
<input type="submit" name="submit" value="Submit">
</form>
<?php
require "connection-to.php";
$notFound = "";
$song = "";
if(isset($_POST['submit'])){
$search = mysqli_real_escape_string($conn, $_POST['search']);
$search = strtolower($search);
$sql = "SELECT * FROM `music` WHERE `name` = '" . $search . "'";
$query = mysqli_query($conn, $sql);
$numRows = mysqli_num_rows($query);
if($numRows != 0){
while($row = mysqli_fetch_array($query)){
echo $row['lyrics'] . "<br><br><br>";
}
} else {
echo $search . " Was Not Found.";
}
}
?>
You don't want send a POST request. Change
<form action="#" method="POST">
to
<form action="" method="GET">
Then you can retrive it with $_GET['search'] instead of $_POST['search'].
Related
My assignment is to create two tables in phpMyAdmin, and then to create a simple form where the user can click a button and have the two tables displayed. I have the landing page for the assignment finished with header and search bar and button, but I'm having trouble figuring out how to bring the two tables in from the database and display them once the button is clicked.
I have had a tutor help with some of the code but I haven't been able to get it to work properly and would love any further help.
Here is the code I have now (the two separate php code chunks are two ways people tried to help me do it but I don't know which works or how to implement it):
<!DOCTYPE html>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {die("Connection Failed: " . $conn->connect_error);
}
echo "Connected Successfully";
?>
<html>
<head>
</head>
<body>
<h1>Health Club Patron and Class Information</h1>
<form name="contact-form" action="" method="post" id="contact-form">
<div class="form-group">
<label for="Search">Search</label>
<input type="text" class="form-control" search="your_name" placeholder="Search" required>
</div>
<button type="print" class="btn btn-primary" name="print" value="Print" id="submit_form">Print</button>
</form>
</body>
</html>
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is the password
mysql_select_db('hrmwaitrose');
$query = "SELECT * FROM employee"; //You don't need a ; like you do in SQL
$result = mysql_query($query);
echo "<table>"; // start a table tag in the HTML
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['name'] . "</td><td>" . $row['age'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysql_close(); //Make sure to close out the database connection
Try looking at examples on this website, good example's taken from W3 schools to learn with some simple examples.
https://www.w3schools.com/php/php_mysql_select.asp
And a form handling example in PHP https://www.w3schools.com/php/php_forms.asp
You setup a php file such as post.php then your form will post to that endpoint. Or if you are posting a PHP form to itself you use <?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> for the post address in the form. When learning, try taking these simpler like the example's below than building from that, so you get the basic idea.
Here's a few examples, this one just grabs the rows from the database.
<?php
$servername = "localhost"; // Server host
$username = "username"; // Database username
$password = "password"; // Database password
$dbname = "hrmwaitrose"; // Your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Select the rows name and age from employee
$sql = "SELECT name, age FROM employee";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo " - Name: " . $row["name"]. " " . $row["age"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Simple example post a form to PHP file a different URL, not posting to itself.
Filename: index.php
<html>
<body>
<form action="results.php" method="get">
Name: <input type="text" name="name"><br>
Age: <input type="text" name="age"><br>
<input type="submit">
</form>
</body>
</html>
Then your results.php contains
Filename: results.php
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["age"]; ?>
</body>
</html>
This is an example using a form posting to itself, instead of the example's above which post to another file. Using $_GET["name"] you are grabbing the post variable's from the URL and then you can query your database, unless you are using _POST. If your posting directly to the same file you would do something like this, which I think your question is asking.
<?php if (!empty($_POST)): ?>
Welcome, <?php echo htmlspecialchars($_POST["name"]); ?>!<br>
Your age is <?php echo htmlspecialchars($_POST["age"]); ?>.<br>
<?php else: ?>
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post">
Name: <input type="text" name="name"><br>
Age: <input type="text" name="age"><br>
<input type="submit">
</form>
<?php endif; ?>
this form is sending data to database but i need the query should also go to the two other ids someone said use smtp but i don't know how and where to add smtp in this form. please help thanks in advance
<?php
// Attention! Please read the following.
// It is important you do not edit pieces of code that aren't tagged as a configurable options identified by the following:
// Configuration option.
// Each option that is easily editable has a modified example given.
$error = '';
$name = '';
$email = '';
$organisation = '';
$phone = '';
$subject = '';
$comments = '';
//$verify = '';
if(isset($_POST['contactus'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$organisation = $_POST['name'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
//$verify = $_POST['verify'];
$servername = "localhost";
$username = "auweb";
$password = "auw3b";
$dbname = "auweb";
$useragent=$_SERVER['HTTP_USER_AGENT'];
$ip=$_SERVER['REMOTE_ADDR'];
//echo $msg;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
}
$sql="";
if(empty($name)||empty($phone)||empty($email)||empty($subject)||empty($comments)){
$sql = "INSERT INTO `aki_logs` (`ts`, `name`, `email`, `phone`, `state`, `course`, `useragent`, `ip`, `status`)VALUES (now(), '$name', '$email', '$phone', '$comments', '$subject', '$useragent', '$ip', 'Error');";
//echo 'Please enter all the data';
header('location:index.php');
}
else{
$sql = "INSERT INTO `aki_logs` (`ts`, `name`, `email`, `phone`, `state`, `course`, `useragent`, `ip`, `status`)VALUES (now(), '$name', '$email', '$phone', '$comments', '$subject', '$useragent', '$ip', 'Success');";
}
$conn->query($sql);
$conn->close();
//$to="admissions2#ansaluniversity.edu.in,siddhartha#digidarts.com";
//$to='admissions2#ansaluniversity.edu.in';
#date_default_timezone_set('Asia/Kolkata');
#session_start();
unset($_POST['formname']); unset($_POST['submit']);
$csv = implode('","', $_POST);
$csv = '"'.date("d-m-Y").'","'. date("H:i:s") .'","' . $csv . '"' . "\r\n";
$file = '../../data/'. basename( __DIR__ ) .'.csv';
#file_put_contents($file, $csv, FILE_APPEND);
// Configuration option.
// You may change the error messages below.
// e.g. $error = 'Attention! This is a customised error message!';
if(trim($name) == '') {
$error = '<div class="error_message">Attention! You must enter your name.</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.</div>';
// Configuration option.
// Remove the // tags below to active phone number.
} else if(!is_numeric($phone)) {
// $error = '<div class="error_message">Attention! Phone number can only contain digits.</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
if(trim($organisation) == '') {
$error = '<div class="error_message">Attention! Please enter a subject.</div>';
} else if(trim($comments) == '') {
$error = '<div class="error_message">Attention! Please enter your message.</div>';
}// else if(trim($verify) == '') {
// $error = '<div class="error_message">Attention! Please enter the verification number.</div>';
//} else if(trim($verify) != '4') {
// $error = '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
//}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "";
$address = "mk#gmail.com, mk2#gmail.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_organisation = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $organisation, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
// Configuration option.
// RIf you active phone number, swap the tags of $e-reply below to include phone number.
$e_reply = "You can contact $name via email, $email or via phone $phone";
//$e_reply = "You can contact $name via email, $email";
$msg = $e_body . $e_content . $e_reply;
if(mail($address, $e_organisation, $msg, "From: 'enquiry#gmail.com'\r\nReply-To: $email\r\nReturn-Path: $email\r\n"))
{
// Email has sent successfully, echo a success page.
echo "<div id='succsess_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
} else echo "Error. Mail not sent";
}
}
if(!isset($_POST['contactus']) || $error != '') // Do not edit.
{
?>
<?php echo $error; ?>
<fieldset>
<legend>Please fill in the following form to contact us</legend>
<form method="post" action="#succsess_page">
<div class="row">
<div class="col-md-6">
<label for=name accesskey=U><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="<?php echo $name; ?>" />
<br />
<label for=email accesskey=E><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="<?php echo $email; ?>" />
<br />
<label for=phone accesskey=P><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="<?php echo $phone; ?>" />
</div><!--COL-FORM HALF-->
<div class="col-md-6">
<label for=subject accesskey=S><span class="required">*</span> Subject</label>
<select name="subject" id="subject">
<option value="B. A. (Hons) - Liberal Arts">B. A. (Hons) - Liberal Arts</option>
</select>
<br />
<label for=comments accesskey=C><span class="required">*</span> Query</label>
<textarea name="comments" cols="30" rows="3" id="comments"><?php echo $comments; ?></textarea>
<hr />
<!--<p><span class="required">*</span> Are you human?</p>
<label for=verify accesskey=V> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="<?php echo $verify; ?>" /><br /><br />-->
<input name="contactus" type="submit" class="submit" id="contactus" value="Submit" />
</div>
</div>
</form>
</fieldset>
<?php }
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
If you should send an email after form submitting, you can use the php "mail()" function (http://php.net/manual/en/function.mail.php).
Or, if you wanna use SMTP protocol you should integrate in your project a plugins like PHPMailer. See ya!
I am working with a comment posting system for my web. Here everything work well. But in case of reply of each comment, reply work perfectly for last/new submitted comment.
When I go to reply others comment it's submit name and show it but cannot submit textarea of form.
*(1) If i replace my reply form at the end of page and visible with css for test then reply work but reply button cannot slide below to show reply form for each comment.
*(2) And if i replace my reply from just after reply of comment then reply work for 1st comment.
Show as below in post.php
So I think my problem is in my post.php page to replace in my reply form or any anything else.
here is my post.php
<script type='text/javascript'>
$(function(){
$("a.reply").click(function() {
var id = $(this).attr("id");
$("#parent_id").attr("value", id);
});
});
</script>
<script>
//showReplyBox
$('a.reply').livequery("click", function(e){
var getpID = $(this).attr('id').replace('','');
//$('.commentBox').hide();
$("#reply_here-"+getpID).show();
});
</script>
</head>
<?php
include("db.php");
function submitComments($tutid2){
//This is submit main post form.
}
?>
<?
function getComments($tutid){
global $dbh;
//fetch all comments from database where the qazi_id number is the one you are asking for
$results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$tutid' ORDER BY id DESC LIMIT 5") or die(mysqli_error($dbh));
echo'<div class="comments"><div id="updates"><div class="content"><comment>';
// Show only main comment
while($row = mysqli_fetch_array($results))
{ $id = $row['id'];
$qazi_id = $row['qazi_id'];
$likes = $row['likes'];
$username = $row['username'];
$img = $row['img'];
$description = $row['description'];
$url = $row['url'];
$parent_id = $row['parent_id'];
$date = $row['date'];
echo'<div class="comment">
<div class="cdomment_cheder">';
echo'<p class="name">'.$username.' Says:</p>';
echo'<span class="cdomment_time">'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
if ($img=="") {echo '';}
else echo'<br><img src="comimage/'.$img.'"/>';
echo '</div>';
//delete
echo'<div class="delete" align="right">Delete</div>';
//reply
echo'<div class="reply_box">Reply</div>';
//Likes
echo'';
//Reply form
echo'<div id="loader"></div><div class="reply_here" id="reply_here-'.$id.'" style="display:none;">
<form action="" method="post" id="repfrm" enctype="multipart/form-data">
<fieldset id="cmntfs">
<legend class="pyct">Your comment</legend>
<input type="hidden" name="username" tabindex="1" id="author" value="'.$username.'"/>
<input type="hidden" name="url" tabindex="2" id="url" value="" />
<div id="maintbox">
<textarea name="replycom" rows="2" tabindex="4" id="replycom" value=""></textarea>
</div>
<input type="hidden" name="parent_id" id="parent_id" value="0" />
<input type="hidden" name="tutid2" id="tutid" value="'.$tutid2.'" />
<button type="submit" name="submit" value="" tabindex="5" id="submit" class="repfrm">Post Reply</button>
</fieldset>
</form>
</div>';
// Show Reply of each comment
$query = "SELECT * FROM comments_reply WHERE parent_id ='".$id."'";
$res = mysqli_query($dbh,$query);
while($row = mysqli_fetch_array($res))
{ $id = $row['id'];
$qazi_id = $row['qazi_id'];
$likes = $row['likes'];
$username = $row['username'];
$img = $row['img'];
$description = $row['description'];
$url = $row['url'];
$parent_id = $row['parent_id'];
$date = $row['date'];
echo' <div class="rcontent"><replycomment><ul>
<div class="comment">
<div class="cdomment_cheder">';
if ($url=="") {
echo'<p class="name">'.$username.' Says:</p>'; }
else echo'<p class="name">'.$username.' Says:</p>';
echo'<span class="cdomment_time">'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
if ($img=="") {echo '';}
else echo'<br><img src="comimage/'.$img.'"/>';
echo '</div>';
//delete
echo'<div class="delete" align="right">Delete</div>';
echo'</ul><replycomment></div>';
} //reply while close
*(2) And if i replace my reply from here then reply work for 1st comment.
} //comment while close
*(1) If i replace my reply form here and visible with css for test then reply work but reply button cannot slide below to show reply form for each comment.
echo'</div><comment></div>';
} //fuction close
?>
I have this sign-in page...
<!doctype html>
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<form action="signin_process.php" method="post">
Name: <input type="text" name="name">
<br />
SID: <input type="text" name="sid">
<br />
Nick Name: <input type="text" name="nn">
<br />
Email: <input type="text" name="email">
<br />
Password: <input type="text" name="pw">
<br />
<input type="submit" value="Login">
</form>
</body>
</html>
The signin_process.php file...
<!doctype html>
<html>
<head>
<title>Signin_process</title>
</head>
<body>
<?php
include ("connection.php");
$name = $_POST['name'];
$sid = $_POST['sid'];
$nn = $_POST['nn'];
$em = $_POST['email'];
$pw = $_POST['pw'];
$result = mysqli_query($con, "SELECT * FROM student_table WHERE SID='$sid'") or die('Query failed');
if(mysqli_num_rows($result)){
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Invalied SID')
window.location.href='welcome.php';
</SCRIPT>");
}
$result = mysqli_query($con, "SELECT * FROM student_table WHERE nickname='$nn'") or die('Query failed');
if(mysqli_num_rows($result)){
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Nickname Takken!')
window.location.href='welcome.php';
</SCRIPT>");
}
$result = mysqli_query($con, "SELECT * FROM student_table WHERE email='$em'") or die('Query failed');
if(mysqli_num_rows($result)){
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Email already in use!')
window.location.href='welcome.php';
</SCRIPT>");
}
?>
</body>
</html>
Now if SID, Nick name or email is not valid, i want to redirect to the sign-in page and the field values will be there which were given earlier. So that in don't have to input all the values all over again. Like we see in many sites, we just had to change the input that was not excepted and submit again.
Thanks!
You can use like this:
if ($_POST['name'] == '') {
echo "<script type='text/javascript'>window.history.back();</script>";
}
By this way field values will be there which were given earlier.
<?php
session_start();
if(isset($_POST['nam']) && (isset($_POST['sid']) && (isset($_POST['nn'])){
if(($_POST['name']=== 'user')&& ($_POST['sid']==='sid')&&($_POST['nn']==='sid')){
echo "correct";
$_SESSION['us'] = "YES";
$_SESSION['sid'] = "YES";
$_SESSION['nn'] = "YES";
header("location: userpage.php"); //directs to user area
}else {
echo "Wronge Password/Name/Nickname";
$_SESSION['us'] = $_POST['name'];
$_SESSION['sid'] = $_POST['sid'];
$_SESSION['nn'] = $_POST['nn'];
header("location: userpage.php"); //userpage redirects to this page
}}
?>
<!doctype html>
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<form action="" method="post">
Name: <input type="text" name="name" <?php echo isset($_SESSION['us']) ? $_SESSION['us'] : ""; ?> >
<br />
SID: <input type="text" name="sid" <?php echo isset($_SESSION['sid']) ? $_SESSION['sid'] : ""; ?> >
<br />
Nick Name: <input type="text" name="nn" <?php echo isset($_SESSION['sid']) ? $_SESSION['sid'] : ""; ?> >
</form>
</body>
</html>
A basic example:
Your login form:
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<ul>
<?php
$errors = isset($_SESSION['errors']) && is_array($_SESSION['errors']) ? $_SESSION['errors'] : [];
foreach ($errors as $error):
?>
<li><?php print $error; ?></li>
<?php endforeach; ?>
</ul>
<form action="signin_process.php" method="post">
<label for="name">Name: </label>
<input type="text" id="name" name="name" value="<?php print !isset($_SESSION['name']) ?: $_SESSION['name']; ?>" />
<label for="sid">SID: </label>
<input type="text" id="sid" name="sid" value="<?php print !isset($_SESSION['sid']) ?: $_SESSION['sid']; ?>" />
<label for="nn">Nick Name: </label>
<input type="text" id="nn" name="nn" value="<?php print !isset($_SESSION['nn']) ?: $_SESSION['nn']; ?>" />
<label for="email">Email: </label>
<input type="text" id="email" name="email" value="<?php print !isset($_SESSION['email']) ?: $_SESSION['email']; ?>" />
<label for="pw">Password: </label>
<input type="text" id="pw" name="pw" value="<?php print !isset($_SESSION['pw']) ?: $_SESSION['pw']; ?>" />
<input type="submit" name="login" value="Login">
</form>
</body>
</html>
Your PHP form submission:
<?php
session_start();
include ("connection.php");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_SESSION['name'] = mysqli_real_escape_string($con, $_POST['name']);
$sid = $_SESSION['sid'] = mysqli_real_escape_string($con, $_POST['sid']);
$nn = $_SESSION['nn'] = mysqli_real_escape_string($con, $_POST['nn']);
$em = $_SESSION['email'] = mysqli_real_escape_string($con, $_POST['email']);
$pw = $_SESSION['pw'] = mysqli_real_escape_string($con, $_POST['pw']);
$_SESSION['errors'] = [];
$result = mysqli_query($con, "SELECT * FROM student_table WHERE SID='$sid'") or die('Query failed');
if (mysqli_num_rows($result) > 0) {
$_SESSION['errors'][] = 'Invalid SID.';
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
}
$result = mysqli_query($con, "SELECT * FROM student_table WHERE nickname='$nn'") or die('Query failed');
if (mysqli_num_rows($result) > 0) {
$_SESSION['errors'][] = 'Nickname already in use.';
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
}
$result = mysqli_query($con, "SELECT * FROM student_table WHERE email='$em'") or die('Query failed');
if (mysqli_num_rows($result) > 0) {
$_SESSION['errors'][] = 'E-mail already in use.';
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
}
}
header('Location: index.php');
exit();
?>
That should work.
P.S. You should look into prepared statements and input filtering. Safety should always come first.
I have two problems:
How do I close the window once I Have executed my PHP code which is a simple save textbox values to database?
How do I get my text boxes to align so they perfectly aligned currently one is more indented than the other DEMO?
Here's the PHP code that saves data into my database once saved I want the current window to close:
<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">
Permit or Deny: <input align= center type="text" name="Permit_or_Deny" value=""><br>
Level <input type="text" name="Level" value=""><br>
<p><input id="submit" name="submit" type="submit" value="Permit Or Deny Submit Buutton" /></p>
</form>
<?
if ((isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))) {
//first name or last name set, continue-->
$Permit_or_Deny = $_POST['Permit_or_Deny'];
$Level = $_POST['Level'];
$db =& JFactory::getDBO();
$query = "INSERT INTO tp_newedit (Permit_or_Deny, Level) VALUES ('" . $Permit_or_Deny . "','" . $Level . "');";
$db->setQuery($query);
$db->query();
} else {
echo '<h4>One Field Is Required!</h4>';
}
?>
For first part -
<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">
<div class="label" style="display:inline-block;width:200px"> Permit or Deny: </div><input align= center type="text" name="Permit_or_Deny" value=""/><br>
<div class="label" style="width:200px;display:inline-block;"> Level </div> <input type="text" name="Level" value=""><br>
<p><input id="submit" name="submit" type="submit" value="Permit Or Deny Submit Buutton" /></p>
</form>
For second part, place this on server side code-
<?php
/* ... SQL EXECUTION TO UPDATE DB ... */
echo "<script>window.close();</script>";
?>
Try window.close() of JavaScript:-
<?
if ((isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))) {
//first name or last name set, continue-->
$Permit_or_Deny = $_POST['Permit_or_Deny'];
$Level = $_POST['Level'];
$db =& JFactory::getDBO();
$query = "INSERT INTO tp_newedit (Permit_or_Deny, Level) VALUES ('" . $Permit_or_Deny . "','" . $Level . "');";
$db->setQuery($query);
$db->query();
echo "<script type='text/javascript'>";
echo "window.close();";
echo "</script>";
} else {
echo '<h4>One Field Is Required!</h4>';
}
?>