insert into a SQL table [duplicate] - php

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 8 years ago.
Hi, I'm currently trying to add data into my SQL table using php I can't seem to see where I'm going wrong here, I'm getting the following errors:
Notice: Undefined index: ModuleId in N:\ftp\compc\d11os\Project\addModule.php on line 70
Notice: Undefined index: Title in N:\ftp\compc\d11os\Project\addModule.php on line 70
Notice: Undefined index: CreditLevel in N:\ftp\compc\d11os\Project\addModule.php on line 70
Notice: Undefined index: CreditPoints in N:\ftp\compc\d11os\Project\addModule.php on line 70
Notice: Undefined index: Status in N:\ftp\compc\d11os\Project\addModule.php on line 70
Warning: mysql_query(): Access denied for user ''#'localhost' (using password: NO) in N:\ftp\compc\d11os\Project\addModule.php on line 72
Warning: mysql_query(): A link to the server could not be established in N:\ftp\compc\d11os\Project\addModule.php on line 72
Here is the code I'm currently using:
<?php
if (isset($_POST['submit']) && $_POST['submit']=="Submit") {
$con=mysqli_connect("localhost","useername ","password ","databasename");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$insert = "INSERT INTO module (ModuleId, Title, CreditLevel, CreditPoints, Status, Award)
VALUES ('".$_POST['ModuleId']."','".$_POST['Title']."','".$_POST['CreditLevel']."','".$_POST['CreditPoints']."','".$_POST['Status']."','".$_POST['Award']."')";
$add_member = mysql_query($insert);
?>
Can someone please help? :/

You've used mysql_query() when you should be using mysqli_query() for a start.

Related

A PHP Error was encountered Severity: Warning Message: Undefined property: stdClass:: $cancelled [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Notice: Undefined property - how do I avoid that message in PHP?
(7 answers)
Closed 7 months ago.
I got this error message when running PHP Code Igniter project:
A PHP Error was encountered
Severity: Warning
Message: Undefined property: stdClass::$cancelled
Filename: transactions/transtable.php
Line Number: 38
Backtrace:
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\views\transactions\transtable.php
Line: 38
Function: _error_handler
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\application\controllers\Search.php
Line: 103
Function: view
File: C:\xampp\htdocs\mini-inventory-and-sales-management-system\index.php
Line: 315
Function: require_once
Here is transactions/transtable.php
Line Number: 38
<td><?=$get->cancelled ? 'cancelled' : 'Completed'?></td>
If you are trying to bring something from the database with the model from the controller, you should look that the name of the variable that you bring before assign to the response of the controller (in the controller), need to be named exactly the same as the column name in database.
f.e:
if($query = $this->some_model->getModels(){
foreach($query->result() as $res){
$row = new stdClass();
$row->first_data = $res->THE_SAME_AS_IN_DB; (it's case sensitive too)
}
}
And in the model i usually use raw queries, but if youre using the CI functions, its the same name as the column in db.
Maybe if you post more info about the error, i can be more exactly, but some of the most typical reason of that error is because the variable is empty, and you try to use it .

Notice: Undefined index: items in C:\xampp\htdocs\getsites\index.php on line 28 [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 1 year ago.
My PHP code: https://codeshare.io/0gjlqN
print_r($res['items'] ?: ''); Returning Data like: https://codeshare.io/j06b4g
But the errors are :
Notice: Undefined index: items in C:\xampp\htdocs\getsites\index.php on line 28
Notice: Undefined index: items in C:\xampp\htdocs\getsites\index.php on line 30
Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\getsites\index.php on line 34
Notice: Undefined index: items in C:\xampp\htdocs\getsites\index.php on line 28
Notice: Undefined index: items in C:\xampp\htdocs\getsites\index.php on line 30
Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\getsites\index.php on line 34

recieveing Undefined index trying to get the key [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Read JSON Data Using PHP [duplicate]
(5 answers)
Closed 3 years ago.
Hi I’m trying to recieve data and i get the error Notice: Undefined index:['my key']
my php codes:
$Username = $_REQUEST['username'];
$Password = $_REQUEST['password'];
the code i'm sending:
{
"username":"sss",
"password":"aaa"
}
exact error:
Notice: Undefined index: username in C:\xampp\htdocs\android.dev\first_page.php on line 33
Notice: Undefined index: password in C:\xampp\htdocs\android.dev\first_page.php on line 34

How to fix Undefined index: [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 3 years ago.
Notice: Undefined index: id_desafilter in D:\Sofwares\XAMPP
7.5.5.0\htdocs\project2\views\filterdata.php on line 45
Notice: Undefined index: status_krlfilter in D:\Sofwares\XAMPP
7.5.5.0\htdocs\project2\views\filterdata.php on line 46
that means that your variable may not be defined.
Use isset function.
You should wrap it into a condition like this :
if(!isset($id_desafilter)){
$id_desafilter = "WHAT_YOU_WANT";
}
else{
$id_desafilter = "WHAT_YOU_WANT";
}
This is how you can make sure your variable is define.
But please make sure to join your code to be helped
Have Fun :)

Trying to follow Google API guide to use phpmyadmin database to create markers [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 4 years ago.
I am trying to learn how to export from an Xampp phpmyadmin sql database to a google API to create markers.
I am trying to follow this guide:
https://developers.google.com/maps/solutions/store-locator/clothing-store-locator?csw=1
I get to the "Checking that XML output works" section.
I try to run my script by typing into my browser: http://localhost/projectgmaps/storelocator.php
This kicks out a page with:
*
Notice: Undefined index: lat in
C:\xampp\htdocs\projectgmaps\storelocator.php on line 4 Notice:
Undefined index: lng in C:\xampp\htdocs\projectgmaps\storelocator.php
on line 5 Notice: Undefined index: radius in
C:\xampp\htdocs\projectgmaps\storelocator.php on line 6 Fatal error:
Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\projectgmaps\storelocator.php:12 Stack trace: #0
{main} thrown in C:\xampp\htdocs\projectgmaps\storelocator.php on line
12
*
This is line 4,5,6:
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
and this is line 12:
$connection=mysql_connect (localhost, $username, $password);
Is anyone able to tell me what is wrong here?

Categories