Jump to content
#FlattenTheCurve ×
samanj

Sending to mySQL database, but nothing received

Recommended Posts

Hi all,

I have made some code based on following online youtube video for making a HTML form send to mySQL database via PHP: https://youtu.be/qm4Eih_2p-M

The form I am making is hopefully going to help in the Hospital at which I work to speed patient referrals, so I am very keen on making it work.

I have made the HTML form and the database, which I do not think are the problem.

When I click 'Submit' on my HTML form, then my php file comes up with all the code written, rather than the message: "New referral sent succesfully".

Additionally, when I check the database via 'MyPHPAdmin' there is no data added to the database I have made.

I have been using Sublime and have spotted some mistakes here and there, but is there something glaringly obvious that I am doing wrong in my code that is stopping my form being sent to the database?

Thank you,
Saman

<?php

$patientname = | $_POST['patientname'];
$hospitalnumber = | $_POST['hospitalnumber'];
$DoB = | $_POST['DoB'];
$specialty = | $_POST['specialty'];
$otherspecialty = | $_POST['otherspecialty'];
$admissiondate = | $_POST['admissiondate'];
$referring = | $_POST['referring'];
$bleep = | $_POST['bleep'];
$Admission = | $_POST['Admission'];
$Illness = | $_POST['Illness'];
$Awareness = | $_POST['Awareness'];
$question = | $_POST['question'];
$history = | $_POST['history'];
$medications = | $_POST['medications'];
$examination = | $_POST['examination'];
$results = | $_POST['results'];
$diagnosis = | $_POST['diagnosis'];
$investigations = | $_POST['investigations'];

	$host = "localhost"
	$dbUsername = "root";
	$dbPassword = "xyzabc";
	$dbname = "GreenCard";

	$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);

	if (mysqli_connect_error()) {
		die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
	
	} else {
	$INSERT = "INSERT Into Greencard (patientname, hospitalnumber, DoB, specialty, otherspecialty, admissiondate, referring, bleep, Admission, Illness, Awareness, question, history, medications, examination, results, diagnosis, investigations) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

	//Prepare statement
	$stmt = $conn->prepare($INSERT);
	$stmt->bind_param("sisissssssssssssss", $patientname, $hospitalnumber, $DoB, $specialty, $otherspecialty, $admissiondate, $referring, $bleep, $Admission, $Illness, $Awareness, $question, $history, $medications, $examination, $results, $diagnosis, $investigations);
	$stmt->execute();
	echo "New referral sent successfully";
	}
	$stmt->close();
	$conn->close();

} else {
	echo "Make sure fields are completed";
	die();
}

?>

 

Share this post


Link to post
Share on other sites
$patientname = | $_POST['patientname'];

Why is there a pipe in here?

When you check for data, are you looking at everything in the table? Or just running a SELECT query for the data you expect to see?

Share this post


Link to post
Share on other sites

Thanks, I have removed the pipe from every line, including the one you have shown.

Now I am getting this when I submit:

Quote

Parse error: syntax error, unexpected '$dbUsername' (T_VARIABLE) in /Users/samanj/Sites/insert.php on line 23

Am I getting closer?

I am not very savvy in understanding what the SELECT query does, more just following the video.

I do expect to look for everything in the table when I submit the form and then check the database using PhPMyAdmin

Share this post


Link to post
Share on other sites
Posted (edited)

Latest update: have seemed to get this far:

Quote

Warning: mysqli::__construct(): (HY000/1045): Access denied for user ''@'localhost' (using password: YES) in /Users/samanj/Sites/insert.php on line 27
Connect Error(1045)Access denied for user ''@'localhost' (using password: YES)

Does this mean my password is incorrect? (Update: password is correct)

Maybe I am almost there...

Edited by samanj

Share this post


Link to post
Share on other sites

It means you either didn't do it or did it wrong.  The access and permissions for your data base  are incorrect.

Share this post


Link to post
Share on other sites

Update on this, I started from scratch and worked bit by bit and finally got it to work 👍

Thanks for the feedback.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.