samanj Posted March 21, 2020 Share Posted March 21, 2020 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/310336-sending-to-mysql-database-but-nothing-received/ Share on other sites More sharing options...
requinix Posted March 21, 2020 Share Posted March 21, 2020 $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? Quote Link to comment https://forums.phpfreaks.com/topic/310336-sending-to-mysql-database-but-nothing-received/#findComment-1575647 Share on other sites More sharing options...
samanj Posted March 21, 2020 Author Share Posted March 21, 2020 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 Quote Link to comment https://forums.phpfreaks.com/topic/310336-sending-to-mysql-database-but-nothing-received/#findComment-1575652 Share on other sites More sharing options...
samanj Posted March 21, 2020 Author Share Posted March 21, 2020 (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 March 21, 2020 by samanj Quote Link to comment https://forums.phpfreaks.com/topic/310336-sending-to-mysql-database-but-nothing-received/#findComment-1575653 Share on other sites More sharing options...
ginerjm Posted March 21, 2020 Share Posted March 21, 2020 It means you either didn't do it or did it wrong. The access and permissions for your data base are incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/310336-sending-to-mysql-database-but-nothing-received/#findComment-1575655 Share on other sites More sharing options...
samanj Posted April 2, 2020 Author Share Posted April 2, 2020 Update on this, I started from scratch and worked bit by bit and finally got it to work 👍 Thanks for the feedback. Quote Link to comment https://forums.phpfreaks.com/topic/310336-sending-to-mysql-database-but-nothing-received/#findComment-1576174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.