Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

PHP Undefined Index

omarsierra27

Recruit
Basic Member
Messages
1
Reaction score
0
Points
16
Pa tulong naman, lumalabas kasi "Undefined index: user in C:\wamp64\www\----\testform.php "

<?php

$lhost = "localhost";
$user = "root";
$pss = "";
$dbn = "testarea";

$conn = mysqli_connect ($lhost,$user,$pss);

if (!$conn)
{
die("Connection Failed" .mysqli_connect_error());
}


$sdb = mysqli_select_db ($conn,$dbn);

if (!$sdb)
{
die("No Database" .mysqli_error());
}

$sqlii = "INSERT INTO person (name,contact,email) VALUES ('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";

?>

<html>
<title>Test Area</title>
<body>
<form action="testform.php" method="post">
<input type="text" name="user"></br>
<input type="text" name="number"></br>
<input type="text" name="email">
<input type="submit" name="save" value="Save">
</form>
</body>
</html>

Image Attached.
View attachment 298625
 

Attachments

  • undefined error.PNG
    undefined error.PNG
    37.7 KB · Views: 30
hinahanap na kasi yong value ng

('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";

during loading, kaya nag error dahil walang value or hindi na declare

so dalawa choice mo,

mag lagay ka ng

error_reporting(0);

para di na lumabas ang mga error

or enclose mo sa if yong sa php


<?php

if(!empty($_POST['user'])){
$lhost = "localhost";
$user = "root";
$pss = "";
$dbn = "testarea";

$conn = mysqli_connect ($lhost,$user,$pss);

if (!$conn)
{
die("Connection Failed" .mysqli_connect_error());
}


$sdb = mysqli_select_db ($conn,$dbn);

if (!$sdb)
{
die("No Database" .mysqli_error());
}

$sqlii = "INSERT INTO person (name,contact,email) VALUES ('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";
}
?>
 
nilagay mo lang sa variable ($sqlii) yung sql query mo na INSERT... i-execute mo para maprocess at mailagay sa database mo..
 
maganda siguro if i seperate mo ung connection at operation

//Connection.php
Code:
<?php

$lhost = "localhost";
$user  = "root";
$pss   = "";
$dbn   = "testarea";

$conn = new mysqli($lhost, $user, $pss, $dbn);

if ($conn->connect_errno)
{
    exit('Connection failed' . $conn->connect_error);
}

?>

//Operation Process
Code:
<?php

require_once 'connection.php';

if (isset($_POST['save']))
{
    $user   = $_POST['user'];
    $number = $_POST['number'];
    $email  = $_POST['email'];
    
    $sql = "INSERT INTO person (name,contact,email) VALUES ('$user', '$number', '$email' )";
    $conn->query($sql);
}

?>
 
maganda siguro if i seperate mo ung connection at operation

//Connection.php
Code:
<?php

$lhost = "localhost";
$user  = "root";
$pss   = "";
$dbn   = "testarea";

$conn = new mysqli($lhost, $user, $pss, $dbn);

if ($conn->connect_errno)
{
    exit('Connection failed' . $conn->connect_error);
}

?>

//Operation Process
Code:
<?php

require_once 'connection.php';

if (isset($_POST['save']))
{
    $user   = $_POST['user'];
    $number = $_POST['number'];
    $email  = $_POST['email'];
    
    $sql = "INSERT INTO person (name,contact,email) VALUES ('$user', '$number', '$email' )";
    $conn->query($sql);
}

?>

dagdagan mo n lng nito.
$query = $conn->query($sql);
if($query){
echo "<script>alert('success!...');</script>";
}else{
echo "<script>alert('failed!...');</script>";
}
 
Pa tulong naman, lumalabas kasi "Undefined index: user in C:\wamp64\www\----\testform.php "

<?php

$lhost = "localhost";
$user = "root";
$pss = "";
$dbn = "testarea";

$conn = mysqli_connect ($lhost,$user,$pss);

if (!$conn)
{
die("Connection Failed" .mysqli_connect_error());
}


$sdb = mysqli_select_db ($conn,$dbn);

if (!$sdb)
{
die("No Database" .mysqli_error());
}

$sqlii = "INSERT INTO person (name,contact,email) VALUES ('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";

$query = mysqli_query($conn,$sqlii);

if($query){
echo "Record inserted!";
}else{
echo 'Mysql Error: '.mysqli_error();
}

mysqli_close($conn);

?>

<html>
<title>Test Area</title>
<body>
<form action="testform.php" method="post">
<input type="text" name="user"></br>
<input type="text" name="number"></br>
<input type="text" name="email">
<input type="submit" name="save" value="Save">
</form>
</body>
</html>

Image Attached.
View attachment 1174111

try mo yan ts, yung nka red..

- - - Updated - - -

Tsaka TS, pag irun mo yan ng wala kang variable na ipinasa sa POST mo, error talaga ang lumalabas.
 
Last edited:
mag if ka GAMIT KA NG empty na function::

/// ang ibig sabihn nian kaga
if(!emprty($_POST['user']){
dito mo lagay ung query mo.
}
 
Pa tulong naman, lumalabas kasi "Undefined index: user in C:\wamp64\www\----\testform.php "

<?php

$lhost = "localhost";
$user = "root";
$pss = "";
$dbn = "testarea";

$conn = mysqli_connect ($lhost,$user,$pss);

if (!$conn)
{
die("Connection Failed" .mysqli_connect_error());
}


$sdb = mysqli_select_db ($conn,$dbn);

if (!$sdb)
{
die("No Database" .mysqli_error());
}

$sqlii = "INSERT INTO person (name,contact,email) VALUES ('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";

?>

<html>
<title>Test Area</title>
<body>
<form action="testform.php" method="post">
<input type="text" name="user"></br>
<input type="text" name="number"></br>
<input type="text" name="email">
<input type="submit" name="save" value="Save">
</form>
</body>
</html>

Image Attached.
View attachment 1174111


From
Code:
$sqlii = "INSERT INTO person (name,contact,email) VALUES ('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";

To
Code:
if(isset($_POST['user']) && isset($_POST['number']) && isset($_POST['email']){

$sqlii = "INSERT INTO person (name,contact,email) VALUES ('".$_POST['user']."','".$_POST['number']."','".$_POST['email']."')";

}
 
Last edited:
Back
Top Bottom