php connection ERROR

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

61 Replies - 1986 Views - Last Post: 15 May 2019 - 04:47 PM Rate Topic: -----

#16 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2875
  • View blog
  • Posts: 11,250
  • Joined: 03-December 12

Re: php connection ERROR

Posted 07 May 2019 - 11:11 AM

The issue you are running into, is the Head First PHP book is outdated at this point. The code can be converted, but all of the database code is now wrong.


Your current issue is simply because the password you are using, 197323, is not the password for root.
Was This Post Helpful? 0
  • +
  • -

#17 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2334
  • View blog
  • Posts: 7,111
  • Joined: 15-January 14

Re: php connection ERROR

Posted 07 May 2019 - 11:12 AM

MySQL is telling you that you cannot connect to the database because you are not authorized. That means you are not using the correct username and password to connect to MySQL. I don't know what the correct one is, because I didn't set it up. You should know that.
Was This Post Helpful? 0
  • +
  • -

#18 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 07 May 2019 - 11:27 AM

aha tnx for answers...does anyone know where can i look up about password?? and what is the best bok for php in 2019?? tnx for answers guys

This post has been edited by kretze: 07 May 2019 - 11:27 AM

Was This Post Helpful? 0
  • +
  • -

#19 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2334
  • View blog
  • Posts: 7,111
  • Joined: 15-January 14

Re: php connection ERROR

Posted 07 May 2019 - 12:58 PM

You configure the user accounts in MySQL. If you've set up a package like XAMPP, you should check their documentation to see how to add or change MySQL user accounts.
Was This Post Helpful? 0
  • +
  • -

#20 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 07 May 2019 - 02:56 PM

so if i have correct password this code wil work?? or i have to do something diferent??

This post has been edited by kretze: 07 May 2019 - 02:56 PM

Was This Post Helpful? 0
  • +
  • -

#21 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2334
  • View blog
  • Posts: 7,111
  • Joined: 15-January 14

Re: php connection ERROR

Posted 07 May 2019 - 05:19 PM

It looks like your query is missing a parenthesis
Was This Post Helpful? 0
  • +
  • -

#22 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 08 May 2019 - 04:06 AM

yes,,,its maybe because i did database in mysql workbench and not on php myadmin??
Was This Post Helpful? 0
  • +
  • -

#23 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4230
  • View blog
  • Posts: 13,411
  • Joined: 08-June 10

Re: php connection ERROR

Posted 08 May 2019 - 06:44 AM

Unlikely. The wrong password is the wrong password, no matter the programme.
Was This Post Helpful? 0
  • +
  • -

#24 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 08 May 2019 - 08:55 AM

hey guys now it works i didd it database on php myadmin and for password do just a blank space....now i have a another question..can anyone tell me what i nedd to do that $sql will be coorectly works?? i dont cause i dont know...

my pHP code now looks like that


<?php
	
	$dbuser='root';
	$dbpass='';
	$db='testdb';
	$db=new mysqli('localhost',$dbuser,$dbpass,$db) or die("unable to connect");

	$sql='INSERT INTO allien_abduction'.'(first_name,last_name,when_it_happend,how_long,how_many,allien_description,what_they_did,fang_spotted,other,email)'.
	'VALUES "sally","jones","3 day ago","2 days","four","green with six tencles","we just talk and pleyed with a dog","yes","i may seen your dog.contact me","[email protected]"())';

	

	
	

	echo "Enter data sucesfuly";
	



?>



Was This Post Helpful? 0
  • +
  • -

#25 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4230
  • View blog
  • Posts: 13,411
  • Joined: 08-June 10

Re: php connection ERROR

Posted 08 May 2019 - 09:08 AM

see https://php.net/mysqli
Was This Post Helpful? 0
  • +
  • -

#26 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2334
  • View blog
  • Posts: 7,111
  • Joined: 15-January 14

Re: php connection ERROR

Posted 08 May 2019 - 11:13 AM

Look at the syntax for an insert query and compare with what you have:

https://dev.mysql.co.../en/insert.html
Was This Post Helpful? 0
  • +
  • -

#27 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 08 May 2019 - 11:24 AM

tnx guys for all ponter and instruction im very grateful for thaht...now it works if anyone have problem with that i will post my pphp code thah anyone can look up(sory for my "english" im from europe)


<?php
	
	$dbuser='root';
	$dbpass='';
	$db='testdb';
	$db=new mysqli('localhost',$dbuser,$dbpass,$db) or die("unable to connect");

	$sql="INSERT INTO allien_abduction(first_name,last_name,when_it_happend,how_long,how_many,allien_description,what_they_did,fang_spotted,other,email)
	VALUES('dejan','horvat','4days ago','2 days','six','green with six tencles','we just talk and pleyed with a dog','yes','i may seen your dog.contact me','[email protected]');";
	if(mysqli_query($db, $sql)){
		echo"new created"
	}
	else{
		echo"ERROR".$sql."<br>".mysqli_error($db);
	}
	


?>


Was This Post Helpful? 0
  • +
  • -

#28 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 09 May 2019 - 08:44 AM

hey guys donw there is my sql database code an my php code can anyone tell me why i have undefined index error from 8-17 line?? what doesent working?? tnx forr help guys

sql db code
create table allien_abduction(
first_name varchar(30),
last_name varchar(30),
when_it_happend varchar(30),
how_long varchar(30),
how_many varchar(30),
allien_description varchar(100),
what_they_did varchar(100),
fang_spotted varchar(10),
other varchar(100),
email varchar(50)
);

insert into allien_abduction(first_name,last_name,when_it_happend,how_long,how_many,allien_description,what_they_did,fang_spotted,other,email)
values('sally','jones','3 day ago','2 days','four','green with six tencles','we just talk and pleyed with a dog','yes','i may seen your dog.contact me','[email protected]');

select *from allien_abduction;






php code

<?php
$dbuser='root';
$dbpass='';
$db='prvadb';

$db=new mysqli('localhost',$dbuser,$dbpass,$db) or die("unable to connect");

$firstName=mysqli_real_escape_string($db,$_POST['first_name']);
$last_name=mysqli_real_escape_string($db,$_POST['last_name']);
$when_it_happend=mysqli_real_escape_string($db,$_POST['when_it_happend']);
$how_long=mysqli_real_escape_string($db,$_POST['how_long']);
$how_many=mysqli_real_escape_string($db,$_POST['how_many']);
$allien_description=mysqli_real_escape_string($db,$_POST['allien_description']);
$what_they_did=mysqli_real_escape_string($db,$_POST['what_they_did']);
$fang_spotted=mysqli_real_escape_string($db,$_POST['fang_spotted']);
$email=mysqli_real_escape_string($db,$_POST['other']);
$other=mysqli_real_escape_string($db,$_POST['email']);

$sql="INSERT INTO allien_abduction(first_name,last_name,when_it_happend,how_long,how_many,allien_description,what_they_did,fang_spotted,other,email)
	VALUES('$firstName','$last_name','$when_it_happend','$how_long','$how_many','$allien_description','$what_they_did','$fang_spotted','$other','$email');";

	$result=mysqli_query($db, $sql);
	
echo 'Thanks for submitting the form.<br />';
echo 'You were abducted ' . $when_it_happend;
echo ' and were gone for ' . $how_long . '<br />';
echo 'Number of aliens: ' . $how_many . '<br />';
echo 'Describe them: ' . $allien_description . '<br />';
echo 'The aliens did this: ' . $what_they_did . '<br />';
echo 'Was Fang there? ' . $fang_spotted . '<br />';
echo 'Other comments: ' .$other . '<br />';
echo 'Your email address is ' . $email;





?>


Was This Post Helpful? 0
  • +
  • -

#29 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2875
  • View blog
  • Posts: 11,250
  • Joined: 03-December 12

Re: php connection ERROR

Posted 09 May 2019 - 08:48 AM

This is where you need to deviate from the book and learn about prepared statements.


If there is an undefined index, it means your form doesn’t match the variables.
Was This Post Helpful? 0
  • +
  • -

#30 kretze   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 22-October 18

Re: php connection ERROR

Posted 09 May 2019 - 08:56 AM

yea i know that doesent match...that php code is not from the book..i look up at this site https://stackoverflo...-query-function
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »