Well, yet another undefined index appears :
I am trying to change a select row in a database, but so far it doesn't seem to work, I only get
Notice: Undefined index: EierID in C:\WampServer\www\Hundeklubben\ChangeO.php on line 19.
I have tried some fixes, but none worked.
<?php require_once('Connections/hundeklubb.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>Endring av eier</title>
<link rel="stylesheet" href="index.css" />
</head>
<body>
<?php
if(isset($_GET['EierID'])){ $name = $_GET['EierID']; }
//Tried with both $_GET and $_POST
?>
<?php
$UID = (int)$_GET['EierID'];
$query = mysql_query("SELECT * FROM eiere WHERE EierID = '$UID'") or die(mysql_error());
if(mysql_num_rows($query)>=1){
while($row = mysql_fetch_array($query)) {
$navn = $row['Navn'];
$bosted = $row['Bosted'];
}
?>
<form name="form1" action="update.php" method="POST" id="form1">
<input type="hidden" name="ID" value="<?=$UID;?>">
Navn: <input type="text" name="ud_navn" value="<?=$navn?>"><br>
Bosted: <input type="text" name="ud_bosted" value="<?=$bosted?>"><br>
<input type="Submit" value="Oppdater">
</form>
<?php
}else{
echo 'No entry found. Go back';
}
?>
<?php var_dump($UID); ?>
</body>
</html>
The var_dump gives me int 0. I'm not sure what it is supposed to be.
update.php
<?php require_once('Connections/hundeklubb.php'); ?>
<?php
$ud_ID = (int)$_POST["ID"];
$ud_navn = mysql_real_escape_string($_POST["ud_navn"]);
$ud_bosted = mysql_real_escape_string($_POST["ud_bosted"]);
$query="UPDATE eiere
SET navn = '$ud_navn', bosted = '$ud_bosted'
WHERE ID='$ud_ID'";
mysql_query($query)or die(mysql_error());
if(mysql_affected_rows()>=1){
echo "<p>($ud_ID) Record Updated<p>";
}else{
echo "<p>($ud_ID) Not Updated<p>";
}
?>
It is because $_GET['EierID'] is not set.
Try this :
$UID = isset($_GET['EierID'])?$_GET['EierID']:"";
In update.php also do the same thing : $ud_ID = isset($_POST["ID"])?$_POST["ID"]:"";
If your variable doesn't exist you will get an error trying to cast that int.
<?php
if(isset($_GET['EierID'])){
$name = $_GET['EierID'];
$UID = (int)$_GET['EierID'];
}else{
//set to 0 or any default value you want to set when EierID doesn't exists
$UID = 0;
}
?>
Related
I am trying to input and display the data on same page through mysqli but it shows an error "Couldn't fetch mysqli on line" and not unable to display the records.
<?php
$db=mysqli_connect("localhost","root","","abc") or die("Not connected".mysqli_error());
$database=mysqli_select_db($db,'abc') or die("Database not found".mysqli_error());
if(isset($_POST['submit'])){
$roll=$_POST['roll'];
$name=$_POST['name'];
$ins=mysqli_query($db,"insert into abc1 (roll,name)values('$roll','$name')");
}
mysqli_close($db);
?>
<!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>
<form method="post">
Roll No <input type="text" name="roll" />
Name <input type="text" name="name" />
<input type="submit" name="submit" value="Submit" />
</form>
<table><tr>
<td>Roll No.</td>
<td>Name</td>
</tr>
<?php $query=mysqli_query($db,"select * from abc1");
$result=mysqli_query($db,$query);
$id=0;
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
?>
<tr><td><?php echo $row['roll']; ?></td>
<td><?php echo $row['name']; ?></td>
<?php } ?>
</tr></table>
</body>
</html>
Any help would be appreciated.
Thanks in Advance
You are doing mysqli_query twice.
Try this.
$query = "select * from abc1";
$result = mysqli_query($db, $query);
You are calling mysqli_query function twice:
$query = mysqli_query($db,"select * from abc1");
$result = mysqli_query($db,$query);
Error: Couldn't fetch mysqli on line
Means, you are passing a a resource id in mysqli_fetch_array function instead of Query Statement. so you just need to use this as:
$query = "select * from abc1";
$result = mysqli_query($db,$query);
Side Note:
There is no need to connect db again:
$database=mysqli_select_db($db,'abc')
mysqli_connect() already connected your db.
I'm making a login screen using PHP. I have a HTML file and a PHP file. My HTML is
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="Loginscreen.css" />
<title>Inloggen</title>
</head>
<body>
<div id="login">
<div id="triangle"></div>
<h1>Inloggen</h1>
<form method="get" action="Control.php">
<input type="text" placeholder="Gebruikersnaam" name="log" required />
<input type="password" placeholder="Wachtwoord" name ="pas" required />
<input type="submit" value="Inloggen" />
</form>
</div>
</body>
</html>
And my PHP code:
<?php
$conn = oci_connect('test', 'test', 'test');
$username1 = $_GET['log'];
$password1 = $_GET['pas'];
$array = oci_parse($conn, "SELECT test_A, test_b FROM test WHERE test_A = '$username1' AND test_b = '$password1'");
$query = oci_execute($array);
$count = oci_fetch_row($array);
if($count > 1){
session_start();
$_SESSION['Login'] = "1";
header("Location: page1.html");
}
else {
?>
<script>
alert("Wrong username/password");
location.href = "Login.php";
</script>
<?php
session_start();
$_SESSION['Login'] = "";
}
?>
When I submit, the page is giving an error:
define() expects at least 2 parameters 1 given at line 3 from the php file
How do I fix this error?
I tried to set a define around the connection string, but then I gain the same error.
Function of define should be:
define('YOUR_CONST','YOUR_VALUE');
Reference:
http://php.net/manual/en/function.define.php
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 try to display the user log in to the memberadd.php where i want to add other members, however, it doesn't display, instead it is blank. I post both the member add code and the log in code, it has something to do how the memberadd php didn't received the variable from the other files?
this is the memberadd code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/chtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Web Programming :: Assignment 2" />
<meta name="Keywords" content="Web, programming" />
<title>Member Login</title>
</head>
<body>
<h1>My Member System</h1>
</body>
</html>
<?php
session_start();
require_once('sqlconnect.inc.php');
if(isset($_SESSION['membername']))
{
echo "<p>Welcome back". "<br />".$_SESSION['membername']."</p>";
$conn = #mysqli_connect($host,
$user,
$pswd,
$dbnm);
if (!$conn) {
echo "<p>Database connection failure</p>";
} else {
#mysqli_select_db($conn, $dbnm)
or die ("Database not available");
}
$query = "SELECT member_name FROM team";
$result = mysqli_query($conn, $query);
if(!$result) {
echo "<p>Error with: ", $query, "</p>";
} else {
echo "<table width='10%' border='1'>";
echo "<tr><th>Member</th></tr>";
while ($row = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>",$row["member_name"],"</td>";
echo "</tr>";
}
echo "</table>";
mysqli_free_result($result);
}
}
//
?>
below is the login page
<?php
session_start();
require_once('sqlconnect.inc.php');
if (isset($_POST["login"]))
{
$conn = #mysqli_connect($host, $user, $pswd);
if (!$conn) {
echo "<p>Database connection failure</p>";
} else {
$selectDatabase = #mysqli_select_db($conn,$dbnm)
or die("<p>The database is not available.</p>");
}
$email = $_POST['email'];
$passw = $_POST['password'];
$query = "SELECT member_email FROM team WHERE member_email = '$email' AND password = '$passw'";
$queryResult = #mysqli_query($conn,$query)
or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";
if(mysqli_num_rows($queryResult) == 0) //user is not found
{
header('Location: login.php');
}else{
if(mysqli_num_rows($queryResult) == 1)
{
echo ("<p>User is found, Successful login!</p>");
echo('<p>member add </p>');
echo('<p>List/Remove member </p>');
echo('<p>Log out </p>');
exit();
$query2 = "SELECT member_name FROM team WHERE member_email = '$email' AND password= '$passw'";
$queryResult2 = #mysqli_query($conn, $query2)
or die ("<p>Unable to execute query.</p>". "<p>Error code" . mysqli_errno($conn) .":" . mysqli_error($conn))."</p>";
$array = mysqli_fetch_row($queryResult2);
$_SESSION['membername'] = $array[0];
}
else
{
echo"<p>Email and password do not match</p>";
echo'<p>Home page </p>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/chtml-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="Web Programming :: Assignment 2" />
<meta name="Keywords" content="Web, programming" />
<title>Member Login</title>
</head>
<body>
<form id='login' action='login.php' method='POST'>
<fieldset >
<legend><h1>My Team System Log in Page</h1></legend>
<?php $email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_SANITIZE_STRING) : ''; ?>
<label for='email' >Email:</label>
<input type='text' name='email' id='email' maxlength="50" value="<?php echo $email; ?>" />
</div>
<br />
<div class="elements">
<label for='password' >Password:</label>
<input type='password' name='password' id='password' maxlength="50" />
</div>
<br />
<div class="submit">
<input type='submit' name='login' value='Login' />
<input type='reset' name='Submit' value='Clear' />
<br />
<div class="elements">
Home
</fieldset>
</form>
</body>
</html>
You set the session as membername but you then try to call name. As in, you should correct the bit where you display the user's name into $_SESSION['membername'].
Blank screen is usually a parse error...
echo "<p>Error with: ", $query, "</p>";
Should be
echo "<p>Error with: ".$query."</p>";
echo "<td>",$row["member_name"],"</td>";
Should be
echo "<td>".$row["member_name"]."</td>";
Well I can tell you about what I see:
You set the session of the member name like this
$_SESSION['membername'] = $array[0];
But in memberadd.php you retrieve it like this:
echo "<p>Welcome back". "<br />".$_SESSION['name']."</p>";
So you should change to the same name you set it to :
echo "<p>Welcome back". "<br />".$_SESSION['membername']."</p>";
3 errors I see -
1. your session_start() is not at the top/start of your code.
2. you echo before setting your session value
3. you use exit(); after your echo and before setting your session value.
also, you are wide open to sql injection, and you should hash your passwords.
I am sorry guys, I've made a mistake on the early file I did, which is the signup file where people registered, and I set the session name there ['name'] instead of ['membername']. Is all fine now.
I just need a reality check. This page is redirecting to the HTTP_HOST immediately without downloading data or processing the form. It was, at one time working. I broke something but I'm blind to it.
I'm hitting the page with a query that has 1 value pair, like this: http://Nitrofill.biz/tr/Nitrofill_Presentation?num=EV4ghF8p3
Can anybody help me spot the problem?
<?php session_start();
require_once('Connect.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>Nitrofill Document</title>
<?php
$sn=$_GET['num'];
echo $sn;
mysql_connect($hostname,$username, $password) OR die('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$selectSQL = "select * from `Presentations` where `serialnum` ='" . $sn ."'" ;
$result = mysql_query($selectSQL) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_BOTH);
$thedoc = urldecode($row['docurl']);
$therecip=urldecode($row['recipient']);
$thetracker=urldecode($row['tracker']);
$lastacc=urldecode($row['last_accessed']);
?>
</head>
<body>
<form id="notice" action="http://m3sglobal.com/gdform.php" method="post">
<input name="subject" value="<?php echo $therecip . " has viewed the document you sent them.";?> " />
<input type="hidden" name="redirect" value="<?php echo $thedoc ; ?>"/>
<label>Email:</label><input type="text" name="email" value="<?php echo $thetracker ; ?>"/>
<label>Comments:</label><textarea name="comments" cols="40" rows="5">
Document Viewed:<?php echo $thedoc ; ?>
When Accessed:<?php echo $lastacc ; ?>
</textarea>
<input type="submit" name="submit"/>
</form>
</body>
</html>
You're missing .php in the link you have posted. It needs to be
http://nitrofill.biz/tr/Nitrofill_Presentation.php?num=EV4ghF8p3