Please help me.. I don't know why there is no output in my PHP code.. Below is my index.php code
<html>
<body>
<form action="search.php" method="POST">
<input type="text" name"number" placeholder="Search...."><br/>
<input type = "submit" value="Search">
</form>
</body>
</html>
and this is my search.php.
<html>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("login");
$initial = mysql_real_escape_string($_POST['initial']);
$find_videos = mysql_query("SELECT * FROM `sigup` WHERE `initial` LIKE '%initial%'");
while($row = mysql_fetch_assoc($find_videos))
{
$name = $row['name'];
echo "$name<br/ >";
}
?>
</body>
</html>
mysql_query("SELECT * FROM `sigup` WHERE `initial` LIKE '%$initial%'");
<input type="text" name="initial" placeholder="Search....">
<html>
<body>
<form action="search.php" method="POST">
<input type="text" name="number" placeholder="Search...."><br/>
<input type = "submit" value="Search">
</form>
</body>
</html>
search.php
<html>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("login");
$initial = mysql_real_escape_string($_POST['number']);
$find_videos = mysql_query("SELECT * FROM sigup WHERE initial LIKE '%initial%'");
while($row = mysql_fetch_assoc($find_videos))
{
$name = $row['name'];
echo "$name";
}
?>
</body>
</html>
<html>
<body>
<form action="search.php" method="POST">
<input type="text" name="initial" placeholder="Search...."><br/>
<input type = "submit" value="Search">
</form>
</body>
</html>
search.php
<html>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("login");
$initial = mysql_real_escape_string($_POST['initial']);
$find_videos = mysql_query("SELECT * FROM `sigup` WHERE `initial` LIKE '%$initial%'");
while($row = mysql_fetch_assoc($find_videos))
{
$name = $row['name'];
echo "$name<br/ >";
}
?>
</body>
</html>
Related
Im trying to get the taskid variable from the url:
Long story short the database never updated trying to echo $tasked is blank and im not sure why.
I have looked over all of the suggestions and many different websites I do not see what i'm missing
http://domain.com/ubxtask/addnote.php?taskid=163994
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Note to Task</title>
</head>
<body>
<form action="" method="post">
<p>
<textarea name="notetoadd" rows="4" cols="50"></textarea>
</p>
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
<?php
if ( isset( $_POST['submit'] ) ) {
$servername = "localhost";
$username = "dbusr";
$password = "dbpass";
$dbname = "db";
$notetoadd = $_POST['notetoadd'];
if (isset($_GET["taskid"])) {
//$taskid = $_GET['taskid'];
echo $_GET["taskid"];
//echo $taskid;
}
$sql = "INSERT INTO tasknotestbl (tasknum, tasknote)
VALUES ('$taskid', '$notetoadd')";
if ($conn->query($sql) === TRUE) {
header('Location: http://domain.com/task/tasklist.php');
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
You should add the task id to your forms action, or it would be lost, if you submit the form
<form action="addnote.php?taskid=<?php echo $_GET['taskid']; ?>" method="post">
You can add hidden field to form with taskid and use post method:
<?php
if (empty($_GET['taskid'])) {
$taskid = '1';
}else{
$taskid = (int)$_GET['taskid'];
}
// your code submit code and
if (isset($_POST["taskid"])) {
echo $_POST["taskid"];
}
echo '<form action="" method="post">
<p><textarea name="notetoadd" rows="4" cols="50"></textarea></p>
<input type="hidden" name="taskid" value="'.$taskid.'" placeholder="taskID">
<input type="submit" value="Submit" name="submit">
</form>';
?>
Not able to figure out what is wrong. The connection is working fine. I used the same connection.php file to store data. But not able to pre populate in a different form. Please help.
This is the code i have written:
<?php
session_start();
if (!isset($_SESSION['email']))
header('location: index.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body>
<form action="app_script.php" method="POST">
<input class="form-control" placeholder="Name" name="name" required = "true" value="<?php require_once("connection.php"); $eventid = $_GET['ID'];$field = $_GET['Name'];$result = mysql_query("SELECT $field FROM `persons` WHERE `ID` = '$eventid' ");$row = mysql_fetch_array($result);echo $row[$field]; ?>">
<button type="submit" name="submit" class="btn btn-primary pull-right">Submit</button>
</form>
</body>
</html>
<?php
session_start();
if (!isset($_SESSION['email']))
header('location: index.php');
require_once("connection.php");
$eventid = $_GET['ID'];
$field = $_GET['Name'];
$result = mysql_query("SELECT $field FROM `persons` WHERE `ID` = '$eventid' ");
if(mysql_num_rows($result)>0)
{
$row = mysql_fetch_array($result);
$output = $row[$field]; // to populate
}
else
{
$output ='';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body>
<form action="app_script.php" method="POST">
<input class="form-control" placeholder="Name" name="name" required = "true"
value="<?php echo $output; ?>">
<button type="submit" name="submit" class="btn btn-primary pull-right">Submit</button>
</form>
</body>
</html>
Going to try to keep it short. I have a while loop in grid.php file to fill up a table as such...
<?php while($product = $products->fetch_assoc()) { ?>
<tr>
<td><?php echo $product['cd_id']?></td>
<td><?php echo $product['cd_title']?></td>
<td><?php echo $product['cd_musician_fname']?></td>
<td><?php echo $product['cd_musician_lname']?></td>
<td><?php echo $product['cd_price']?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php } ?>
If I click the first anchor tag takes me to a edit.php file and here is the head code for that file.
<?php include '_includes/db.php';
$cd_id = trim($_GET['id']);
$message = '';
include '_includes/connection.php';
if($db->connect_error){
$message = $db->connect_error;
}else{
$sql = "SELECT * FROM CD WHERE cd_id = $cd_id";
$result = $db->query($sql);
$row = $result->fetch_assoc();
if($db->error){
$message = $db->error;
}
}
?>
Now I will show the html of edit.php
<!-- Product Musician last name-->
<fieldset class="form-group">
<label for="cd_musician_lname">Musician's lirst name</label>
<input type="text" class="form-control" id="cd_musician_lname" name="cd_musician_lname" value="<?php echo $row['cd_musician_lname'];?>">
</fieldset>
<!-- End of Musician last name-->
<!-- Product price-->
<fieldset class="form-group">
<label for="cd_price">Product price</label>
<input type="text" class="form-control" id="cd_price" name="cd_price" value="<?php echo $row['cd_price'];?>">
</fieldset>
<!-- End of Product price-->
<!-- Form submit button-->
Update Record
<a class="btn btn-primary" href="index.php" role="button">Go Back Home</a>
I have the edit.php page working just fine but if I make changes in the fields and click the submit anchor tag I get all the fields of the row empty but the PK. Here is the code for the final edit_confirm.php file
<?php
include '_includes/db.php';
$cd_id = trim($_GET['id']);
$cd_title = $_POST['cd_title'];
$cd_musician_fname = $_POST['cd_musician_fname'];
$cd_musician_lname = $_POST['cd_musician_lname'];
$cd_price = $_POST['cd_price'];
$message = '';
include '_includes/connection.php';
if($db->connect_error){
die("Connection failed: ".$db->connect_error);
} else {
$sql = "UPDATE CD SET cd_title='".$cd_title."', cd_musician_fname='".
$cd_musician_fname."', cd_musician_lname='".
$cd_musician_lname."', cd_price='".$cd_price."' WHERE cd_id = $cd_id ";
$db->query($sql);
var_dump($sql);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include '_includes/main-head.php';?>
</head>
<body>
<?php include '_includes/main-navbar.php';?>
<div class="container">
<hr>
<?php
if($db->query($sql) === TRUE){ ?>
<h1>Record updated successfully.</h1>
<?php echo $cd_title; ?>
<?php echo $record->affected_rows ?>
<p> record was updated in the database.</p></br>
<?php } else { ?>
<p>Error updating the record: </p> <?php $db->error; ?>
<?php }; ?>
<hr>
<a class="btn btn-primary" href="index.php" role="button">Go Back Home</a>
</div>
<?php include '_includes/main-script.php';?>
</body>
</html>
If you notice in the edit_confirm.php I did a var_dump to see what are the values in the variables and it shows empty.
I need help with this.
Thank you in advance.
Man the better way to do this is make it simple to test if the record is updating or not
formsample.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>Untitled Document</title>
</head>
<body>
<?php
include("connection.php");
$id = $_GET['id'];
$query= "select * from clients where id = '$id'";
$sql = mysqli_query($connect, $query);
$result = mysqli_fetch_assoc($sql);
?>
<form action="process.php" method="post">
<input type="text" name="name" id="name" value="<?php echo $result['name'] ?>" />
<input type="text" name="email" id="email" value="<?php echo $result['email'] ?>" />
<input type="hidden" name="id" id="id" value="<?php echo $id?>" />
<input type="submit" />
</form>
</body>
</html>
process.php
<?php
include("connection.php");
$id = $_POST['id'];
$name = $_POST['name'];
$email= $_POST['email'];
$query = "UPDATE clients set name= '$name', email ='$email' where id = '$id'";
$sql = mysqli_query($connect, $query);
?>
Update Record
This is not the proper way to submit a form - it won't work at all.
You need to have a form opening and closing tag, the target address is in the action attribute of the form element, and the method is on there too and should be post for this form (method="POST"). In your code you have a link where you should have a submit input so it won't submit the data, it will just redirect you to that URL. You should have something like this:
<input type="submit" value="Update Record" />
http://www.w3schools.com/html/html_forms.asp
I really don't understand what I am doing here. I have this page profesor.php in which I want to insert some data into the database. After I submit the data from the form I want to be redirected to another page insert.php and display a message.
So I have profesor.php:
<?php
session_start();
if (isset($_SESSION['id'])) {
$fullname = $_SESSION['name'];
echo "<h1> Welcome " . $fullname . "</h1>";
} else {
$result = "You are not logged in yet";
}
if (isset($_POST['studname'])) {
include_once("dbConnect.php");
$studname = strip_tags($_POST['studname']);
$course = strip_tags($_POST['course']);
$grade = strip_tags($_POST['grade']);
$getStudidStm = "SELECT userid FROM users WHERE name = '$studname'";
$getStudidQuery = mysqli_query($dbCon, $getStudidStm);
$row = mysqli_fetch_row($getStudidQuery);
$studid = $row[0];
$_SESSION['studid'] = $studid;
$_SESSION['course'] = $course;
$_SESSION['grade'] = $grade;
header("Location: insert.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo $fullname ;?></title>
</head>
<body>
<div id="wrapper">
<h2>Insert new grade</h2>
<form id="insertForm" action="insert.php" method="post" enctype="multipart/form-data">
Student: <input type="text" name="studname" /> <br />
Course : <input type="text" name="course" /> <br />
Grade : <input type="text" name="grade" /> <br />
<input type="submit" value="Insert" name="Submit" />
</form></div>
</form>
</body>
</html>
and insert.php
<?php
session_start();
if (isset($_SESSION['studid'])) {
include_once("dbConnect.php");
$studid = $_SESSION['studid'];
$course = $_SESSION['course'];
$grade = $_SESSION['grade'];
echo $studid;
echo $course;
echo $grade;
}
My problem is that insert.php doesn't display anything. I really don't understand what I'm doing wrong. Need some help.
your problem is in your form:
<form id="insertForm" action="insert.php" [...]
you send data to insert.php but all the 'magic' with
$_SESSION['studid'] = $studid;
$_SESSION['course'] = $course;
$_SESSION['grade'] = $grade;
you keep in profesor.php
Just change action="insert.php" to action="profesor.php" and it should work fine.
I am trying to pass 2 variables to another page and 1 var is required. I don't know why my code is not working properly. Take a look pls.
Prova1.php :
<html>
<body>
<?php
echo htmlspecialchars($_SERVER["PHP_SELF"]);
$nameErr="";
$name="";
$url="Prova1.php";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (empty($_POST["name"])){
$nameErr = "Name is Required";
}else{
$url="active.php";
}
}
?>
<form method="post" action="<?php echo $url ?>" >
Name: <input type="text" name="name"/>* <?php echo $nameErr;?>
</br>
Email: <input type="text" name="email"/></br>
<input type="submit"/>
</form>
</body>
</html>
active.php :
<html>
<body>
Welcome <?php echo $_POST["name"]; ?> </br>
Your email is <?php echo $_POST["email"]; ?>
</body>
</html>
When the user fills in the required information, you should use a redirect, not another form, to go to active.php. You can pass variables using a session.
<?php
session_start();
if (isset($_POST['name']) && !empty($_POST['name']) {
$_SESSION['name'] = $_POST['name'];
$_SESSION['email'] = $_POST['email'];
header("Location: active.php");
} else {
$nameErr = '';
if (isset($_INPUT['submit'])) {
$nameErr = 'Name is required'];
}
?>
<html>
<body>
<form method="post" action="" >
Name: <input type="text" name="name" required/>* <?php echo $nameErr;?>
</br>
Email: <input type="text" name="email"/></br>
<input type="submit" name="submit"/>
</form>
</body>
</html>
<?php
}
Following your logic, I think your code should be something like this:
prova1.php
<html>
<style>
.error {color: #FF0000;}
</style>
<body>
<?php
echo htmlspecialchars($_SERVER["PHP_SELF"]);
$nameErr = "";
$name = "";
$url = "active.php";
if(isset($_GET['error'])){
if($_GET['error'] == 1){ //code for name error
$nameErr = "name is required";
}
}
?>
<form method="post" action="<?php echo $url ?>" >
Name: <input type="text" name="name"/>* <?php echo $nameErr; ?>
</br>
Email: <input type="text" name="email"/></br>
<input type="submit"/>
</form>
</body>
</html>
active.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
header("Location: prova1.php?error=1");
}
}else{
header("Location: prova1.php");
}
?>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?> </br>
Your email is <?php echo $_POST["email"]; ?>
</body>
</html>
proval.php
if(!isset($_POST['name']) || empty($_POST['name'])){
include 'form.php';
}else{
include 'active.php';
}
form.php
<html>
<body><?php
echo htmlspecialchars($_SERVER["PHP_SELF"]);
$nameErr="";
$name="";
if (isset($_POST["name"])){
$nameErr = "Name is Required";
}
?>
<form method="post">
Name: <input type="text" name="name"/>* <?php echo $nameErr;?>
</br>
Email: <input type="text" name="email"/></br>
<input type="submit"/>
</form>
</body>
</html>
active.php
<html>
<body>
Welcome <?php echo $_POST["name"]; ?> </br>
Your email is <?php echo $_POST["email"]; ?>
</body>
</html>