Why Is My Database Result Empty. - Webmasters - Nairaland
Nairaland Forum › Science/Technology › Webmasters › Why Is My Database Result Empty. (1716 Views)
| Why Is My Database Result Empty. by charliebiz(op): 5:55pm On Dec 01, 2008 |
Please i want to know why my database result in the row is blank. When the information is entered, the number of row oincrease in the database but the result is coming out blank. Please i need urgent replies. Thanks in anticipation. |
| Re: Why Is My Database Result Empty. by yawatide(f): 6:17pm On Dec 01, 2008 |
how about we c ur code, and in particular your query string and a briefing on ur database structure? ![]() |
| Re: Why Is My Database Result Empty. by Seun(mod): 6:50pm On Dec 01, 2008 |
Insert statements do not return any values. |
| Re: Why Is My Database Result Empty. by charliebiz(op): 7:09pm On Dec 01, 2008 |
y is it not returning any value mr seun and how can i go round it or resolve it. This is my code <?php $con = mysql_connect("localhost","don't boder","don't boder" ;if (!$con) { die('could not connect: ' .mysql_error()); } mysql_select_db("kvmngcom_kiddiesvision", $con); $sql="insert into person (Surname, OtherNames, Dateofbirth, Sex, PermanentAddress, ContactAddress, StateofOrigin, LocalGovernmentArea, HomeTown, NameofParents, AddressOfParent, MaritalStatus, Nationality, ModeofIdentification, Number, ForeignersPermit, MobileNumber, MothermaidenName, Bank, Account, AccountName, AccountNumber, Years, Companyname, Address, Position, Name, GurantorsAddress) values ('$_post[Surname]','$_post[OtherNames]' ,'$_post[DateofBirth]','$_post[Sex]','$_post[PermanentAddress]','$_post[ContactAddress]','$_post[StateofOrigin]','$_post[LocalGovernmentArea]','$_post[HomeTown]','$_post[NameofParents]','$_post[AddressOfParent]','$_post[MaritalStatue]','$_post[Nationality]','$_post[ModeofIdentification]','$_post[Number]','$_post[ForeignersPermit]','$_post[MobileNumber]','$_post[MothermaidenName]','$_post[Bank]','$_post[Account]','$_post[AccountName]','$_post[AccountNumber]','$_post[Years]','$_post[Companyname]','$_post[Address]','$_post[Position]','$_post[Name]','$_post[GurantorsAddress]')"; if (!mysql_query($sql,$con)) { die('error:' . mysql_error()); } echo "your resume has been submitted"; mysql_close($con) ?> |
| Re: Why Is My Database Result Empty. by yawatide(f): 7:13pm On Dec 01, 2008 |
weeeelll, Assuming as you said that the aforementioned code is indeed adding data to your db, then the reason why you aren't getting anything no your pages is the very reason Seun stated above - you use SELECT and not INSERT to return database results on your page. For starters, just do a SELECT * FROM person in your code (you will have to connect to your DB the same way you did for INSERT) and refresh the concerned page to see everything. After that you can pick and choose what to display using the WHERE clause: [b]SELECT * FROM person WHERE Surname = 'charliebiz'; [/b]for instance. Please note, I haven't verified (and don't have the time to either) the syntax for the statement above but hopefully you can check that out for yourself if it crashes ![]() This might be of help: http://www.w3schools.com/PHP/php_mysql_select.asp |
| Re: Why Is My Database Result Empty. by charliebiz(op): 7:36pm On Dec 01, 2008 |
I tried checking the result of the form in the database using phpmyadmin. The rows incearse as i fill the form and sumbit it in the database but the rows are empty, no data displayed |
| Re: Why Is My Database Result Empty. by yawatide(f): 7:48pm On Dec 01, 2008 |
hmmm, na wa o. Within phpmyadmin, do a SELECT * FROM person where 1; in the SQL window. If that doesn't pull up anything, there is nothing I can do from my (remote) location. Sorry. |
| Re: Why Is My Database Result Empty. by charliebiz(op): 7:50pm On Dec 01, 2008 |
what does this error mean error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Surname, OtherNames, Dateofbirth, Sex, PermanentAddress, ContactAddress, Stateo' at line 1 |
| Re: Why Is My Database Result Empty. by yawatide(f): 8:35pm On Dec 01, 2008 |
it means you have a syntax error ![]() What statement did you try to run? Also, did you try my SELECT statement? |
| Re: Why Is My Database Result Empty. by OmniPotens(m): 10:08pm On Dec 01, 2008 |
@charliebiz See something you should do. Go to your PHPMyAdmin, check at the tables you created, does any of them have a space (%20 or   in between? Eg. Date of birth (not adviceable) try DOB (recommended). Those spaces could be causing you that error. More so, go get a PHP manual to help you out with those PHP and MySQL references you require. |
| Re: Why Is My Database Result Empty. by charliebiz(op): 10:27am On Dec 02, 2008 |
@Omnipotens Thanks. If u luk at the insert code that i posted, i made sure their was no space inbetween. What i am looking at now is the recommended formats like DOB instead of DateofBirth which i don't know if it is recommeded. Expecting your reply soon. |
| Re: Why Is My Database Result Empty. by OmniPotens(m): 11:04am On Dec 02, 2008 |
I saw your codes though I've not really tested them. What I'm saying is that you should look and check your PHPMyAdmin not the codes you pasted. Or, can you create a snapshot of your DB? I think looking at what you have there could also be of help. Check to see when I'm online on Y! then IM me. |
| Re: Why Is My Database Result Empty. by uspry1(f): 6:04pm On Dec 02, 2008 |
At your PHPMyAdmin screenshot at below should be look like this below: [img width=600 height=290]http://upload.wikimedia.org/wikipedia/commons/9/96/PhpMyAdmin_screenshot.png[/img] Based on what I read your mentioned PHP code you wrote above, I copy all fields of person here. You should able to create a new database at the empty field box of "Create new database", or click the existing database name: kvmngcom_kiddiesvision on the left side column that will prompt opening your specified database name mentioned here. Here is scripting for creating and inserting person data if you find incorrect database creation set-up, click "SQL" icon that will prompt a SQL query window popping up, you can delete the dialog textfield box saying "SELECT * FROM person where 1" to replace the following SQL code below (just copy and paste whole thing exact carefully) into the empty SQL query box.
Then hit "GO". You should have gotten your SQL query executed successfully creating and inserting your new Database Name: kvmngcom_kiddiesvision and your new Database table: person appears on the PHPMyAdmin window ---NO ERROR prompted. By the way you may edit/modify your fields of person i might left out, no problem. That's it! Good luck! |
| Re: Why Is My Database Result Empty. by charliebiz(op): 5:53pm On Dec 03, 2008 |
@Uspry Thank you 4 that, i will try it out. Work is almost done now. I am just coming from Ndu's place where he offered to help. Please everybody thank him for me, this is more than a forum. I am now working on th e tips and site he gave me, no string attached. Members should emulate. I know some people are also like that and i thanked other nairalanders who have also contributed and even given me their yahoo messagers id. Please, i just finished working on the Insert.php with the corrections Ndu gave to me, although i have seen such arrangement/codes in other sites but i refused to use it believing that the one i got from w3schools.com will work. Please can somebody point out the mistake i made in the Insert.php pasted below.i got the codes from w3schools. Just inquisitive. want to know if their codes are wrong, this is the second time i am having trouble using their codes. <?php $con = mysql_connect("localhost","peter","abc123" ;if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Thanks. |
| Re: Why Is My Database Result Empty. by yawatide(f): 6:22pm On Dec 03, 2008 |
What error are you getting? Also, what I like to do when doing DB stuff is to echo my sql query string. In other words, right below the $sql line, add 2 lines thus: echo $sql; exit; If you see the values you entered on the form, whose values are stored in "$POST", then at least you know that the values are being passed. Of course, I say this not knowing what your actual error is, so please post it here so that we can all be of better help. Lesson in general: It pays to actually understand what you are copying and pasting so that when you have issues, you don't say something to the effect that what you copied is wrong. The owners of w3cschools are human and so are capable of making mistakes but considering many go there for code, I doubt they would make an error that someone wouldn't immediately call them on. Why? Their reputation is at stake. |
| Re: Why Is My Database Result Empty. by charliebiz(op): 8:49pm On Dec 03, 2008 |
Please what about this error, where is it coming from and ho do i solve it. Is it from my database? error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,)' at line 3 |
| Re: Why Is My Database Result Empty. by yawatide(f): 9:18pm On Dec 03, 2008 |
I cd b wrong but it looks like u rnt capturing ur form fields (hence the commmas) and perhaps the table in question is set u such that it only accepts "not null" values. Again, I cd b wrong. |
| Re: Why Is My Database Result Empty. by xanadu: 6:35am On Dec 04, 2008 |
Hi Charliebiz, permit me to contribute to your thread. Please can somebody point out the mistake i made in the Insert.php pasted below.i got the codes from w3schools. Just inquisitive. want to know if their codes are wrong, this is the second time i am having trouble using their codes.I think you have a syntax error in the above. You have used the global $_POST, but perhaps with a wrong syntax. Specifically, take a look at this piece from your code: $sql="INSERT INTO Persons (FirstName, LastName, Age)Note that you have included the global $_POST within the quotes - it should be outside the quotes. Instead, your fieldnames should be in quotes between your square brackets. Also, you try concatenating - here's what I mean: $sql="INSERT INTO Persons (FirstName, LastName, Age)Try copying the above as it is and see how it goes. Hope this helps. |
| Re: Why Is My Database Result Empty. by yawatide(f): 1:00pm On Dec 04, 2008 |
xanadu, It is nice of you to do what you did. Kudos. I avoided this because the minute I saw the code, it wreaked of copy-and-paste from some website without full understanding of what the code does. Having said that, I would like to add that it isn't good coding practice to write the code the way he has. It is best (from a debugging, maintenance and readability standpoint) to assign those "POSTs" to a variable and call the variables instead. |
| Re: Why Is My Database Result Empty. by kehers(m): 1:13pm On Dec 04, 2008 |
As stressed by Yawa, php is not capturing your form fields. In other words the POST array values ($_POST[firstname]','$_POST[lastname]','$_POST[age], ) are returning empty fields. This can either be that the keys you used in the POST fields are different from the ones on the form. i.e probably your form input names are not firstname, lastname, age etc as you specified (which of course I doubt). The other reason (which I bet is ypur prob) is the one explained by xanadu. The POST values should be concatenated with the $sql string and not enclosed with it as he showed. To make things easier for you, you may want to declare new variables for the POST values like this $firstname = $_POST['firstname']; $sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$firstname', '$lastname', '$age')";But wait! What if you have over a hundred POST values? Here is a snippet to auto declare everyone of them, using the value keys foreach($_POST as $k => $v){That will declare each POST values with its key. i.e $_POST['firstname'] becomes $firstname etc. Hope that helps |
| Re: Why Is My Database Result Empty. by charliebiz(op): 4:20pm On Dec 04, 2008 |
Na wa for dis kind code. e just be like say somebody swear for the code not to work no matter the money wey a spent online and d time. i almost felt like committing ******* out of frustration but pick courage. na me and the code until i solve am, the small money wey no reach anything don almost finish na wawa oh. Make i thank efribodi weh done contribute. I say make i write in pigin to relief myself of the frustration and make i kon bring anoda matter wey my code de give me thru out today. My Y**** don dey pain me since the time wey me and dis code don dey shuk leg for trouser. Abeg which one kon be dis error error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; VALUES ('','','','','','','','','','','','','','','','','','','','','','','','' at line 1 make una see my code c=kon pick my yeye mistake. Make una no vex say i too dey disturb but person wey dey ask question no dey miss road.Me i don ask question tire not only question i don travel go some ppl office but e be like say i still dey miss road. I know charles (me) would vessi,venti,vecci. @ Omnipo Got your message and am still waiting. <?php $con = mysql_connect("localhost","noboda","noboda" ;if (!$con) { die ('could not connect: ' .mysql_error()); } mysql_select_db("noboda", $con); $Lastname=$_post['Lastname']; $Othernames=$_post['Othernames']; $Dob=$_post['Dob']; $Sex=$_post['Sex']; $Permanentaddress=$_post['Permanentaddress']; $Contactaddress=$_post['Contactaddress']; $Stateoforigin=$_post['Stateoforigin']; $LGA=$_post['LGA']; $Hometown=$_post['Hometown']; $Parentsname=$_post['Parentsname']; $Addressofparents=$_post['Addressofparents']; $Maritalstatus=$_post['Maritalstatus']; $Nationality=$_post['Nationality']; $Modeofidentity=$_post['Modeofidentity']; $Number=$_post['Number']; $Residentpermit=$_['Residentpermit']; $Mobilenumber=$_post['Mobilenumber']; $Mothermaiden=$_post['Mothermaiden']; $Bank=$_post['Bank']; $Accounttype=$_['Accounttype']; $Accountname=$_post['Accountname']; $Accountnumber=$_post['Accountnumber']; $Day=$_post['Day']; $Years=$_post['Years']; $Companyname=$_post['Companyname']; $Companyadd=$_post['Companyadd']; $Guarantorspos=$_post['Guarantorspos']; $Guarantorsname=$_post['Guarantorsname']; $Guarantorsadd=$_post['Guarantorsadd']; $sql="INSERT INTO person (Lastname, Othernames, Dob, Sex, Permanentaddress, Contactaddress, Stateoforigin, LGA, Hometown, Parentsname, Addressofparents, Maritalstatus, Nationality, Modeofidentity, Number, Residentpermit, Mobilenumber, Mothermaiden, Bank, Accounttype, Accountname, Accountnumber, Day, Years, Companyname, Companyadd, Guarantorspos, Guarantorsname, Guarantorsadd); VALUES ('$lastname','$Othernames','$Dob','$Sex','$Permanentaddress','$Contactaddress','$Permanentaddress','$Contactaddress','$Stateoforigin','$LGA','$Hometown','".$Parentsname."','$Addressofparents','".$Maritalstatus."','$Nationality','$ModeofIdentity','$Number','$Residentpermit','$Mobilenumber','$Mothermaiden','$Bank','$Accounttype','$Accountname','$Accountnumber','$Day','$Years','$Companyname','$Companyadd','$Guarantorspos','$Guarantorsname','$Guarantorsadd')"; if (!mysql_query($sql,$con)) { die('error:' . mysql_error()); } echo "your resume has been submitted"; mysql_close($con) ?> This code na WITCH. |
| Re: Why Is My Database Result Empty. by yawatide(f): 4:32pm On Dec 04, 2008 |
charliebiz, thatz the spirit! from experience, once you finally get this done, u will know it like the back of your hand (even when nepa takes light )So, I assume at this point that in order to see that you got blanks that you did what I said a few posts ago - do an echo of the sql variable and then add an exit. If this is true, then I think you should look at your form code. Do the names that you have given your form fields equal the names that you are assigning to your PHP vars? I think we should see your form as well. If it is too long, just post the first 5 or so form fields (the html code, that is). Unfortunately, at work I am in a JSP environment so I can't help and when I get home, I am too tired to do anything. This is definitely an area where human contact would help and am surprised no one has offered (or I guess they have but want money). Remember: Quitters never win. Winners never quit! ![]() |
| Re: Why Is My Database Result Empty. by charliebiz(op): 5:23pm On Dec 04, 2008 |
@yawatide Thanku feli feli much. I don do insert into database from my phpmyadmin and it worked. I think my problem will be from my form and the insert.php. I will try echoing it to see. Thanks Once more. My form code is actually long so i posted the first five. Here you are and thanks for the encouragementor .<td><span class="style7">Surname</span></td> <td bordercolor="#999999" bgcolor="#f4f4f4"><span class="style6"><input size="40" name="Lastname" /> </span></td></tr> <tr> <td><span class="style7">Other Names</span></td> <td bordercolor="#999999" bgcolor="#f4f4f4"><span class="style6"><input size="40" name="Othernames" /> </span></td></tr> <tr> <td class="style7">Date of Birth </td> <td bordercolor="#999999" bgcolor="#f4f4f4"><span class="style6"><input size="40" name="Dob" /> <span class="style9">yyyy/mm/dd</span> </span><span class="style2"></span></td></tr> <tr> <td><span class="style7">Sex</span><span class="style2"> :</span></td> <td bordercolor="#999999" bgcolor="#f4f4f4"><span class="style6"><span class="style2"><input type="radio" value="Male" name="Sex" /> Male</span> <span class="style2"><input type="radio" value="Female" name="Sex" /> Female</span></span></td></tr> <tr> <td><span class="style7">Permanent Address </span></td> <td bordercolor="#999999" bgcolor="#f4f4f4"><span class="style6"><textarea id="Permanent Address" name="Permanentaddress" rows="5" cols="30"></textarea></span></td></tr> <tr> <td><span class="style7">Contact Address </span></td> <td bordercolor="#999999" bgcolor="#f4f4f4"><span class="style6"><textarea id="Contact Address" name="Contactaddress" rows="5" cols="30"></textarea></span></td></tr> <tr> <td><span class="style7">State of Origin </span></td> <td bordercolor="#999999" bgcolor="#f4f4f4"><label><select id="State of Origin" name="Stateoforigin"> |
| Re: Why Is My Database Result Empty. by yawatide(f): 5:45pm On Dec 04, 2008 |
So, I am looking at your sql code and I think (i cd b wrong though) that I found the problem: $sql="INSERT INTO person (Lastname, Othernames, Dob, Sex, Permanentaddress, Contactaddress, Stateoforigin, LGA, Hometown, Parentsname, Addressofparents, Maritalstatus, Nationality, Modeofidentity, Number, Residentpermit, Mobilenumber, Mothermaiden, Bank, Accounttype, Accountname, Accountnumber, Day, Years, Companyname, Companyadd, Guarantorspos, Guarantorsname, Guarantorsadd);Focus on the bolded portion. Do you see the ";" there? It should be removed. Try that and get back to us. If that doesn't work, we try something else. There are other problems with your form code (not enough to make ur sql crash but enough to add some weight to your pages) and I also think you could use an extra table but thatz a lesson for another day. |
| Re: Why Is My Database Result Empty. by charliebiz(op): 7:16pm On Dec 04, 2008 |
i have already done that, thank you. I have finally take care of the errors but still the same trouble, No more error and no result. When submited, it is acknowledged but no data. |
| Re: Why Is My Database Result Empty. by yawatide(f): 7:22pm On Dec 04, 2008 |
next is to reduce ur form to 2 fields and try capturing/inserting only those 2 fields. If you can insert those, keep adding more and more until u hopefully find d problem. |
| Re: Why Is My Database Result Empty. by OmniPotens(m): 9:59am On Dec 05, 2008 |
I'm still surprised this hasn't been sorted out. @Yawa Thanks for the much help so far. @poster Was too busy to be online but will try to be there today. At least from 15:00. Check at me by then. |
| Re: Why Is My Database Result Empty. by charliebiz(op): 7:26pm On Dec 05, 2008 |
:DTHANK GOD OOOOO. PRAISE CHINEKE EVERYBODY. I HAVE BEEN COVERING MYSELF WITH THE BLOOD OF GOD, I EVEN WENT OF FASTING TO SOLVE THE PROBLEM THAT HAVE SEEN ME TRAVELLED, SPENT MONEY, GLUED TO THE INTERNET LIKE NEVER BEFORE UNDER HEAT AND SURROUNDED BY YAHOO YAHOO BOYS PRAISING THEIR HEROIC DUMPING SKILLS, TRYING TO SWEAT IT OUT. MY MOTHER EVEN PRAISED FOR ME LAST NIGHT WHEN SHE SAW HOW DEPRESSED I WAS TRYING TO SOLVE THE ALREADY SOLVE JUST THAT I WASN'T OBSERVANT ENOUGH TO SEE IT. I DON'T KNOW IF THIS IS THE PROBLEM BUT I AM GLAD IT SOVLED THE PROBLEM. I SPENT THE MONEY SUPPOSED TO BE USED FOR MY JOLIFICATION THIS CHRISTMAS TO BROWN ALMOST THROUGHT THE DAY FROM LAST WEEK TO THIS WEEK JUST FOR A SUM OF MONEY THAT IS EQUALL TO THE ONE I AM TO RECEIVE, IN ORDER WORDS I LEARNT BY FORCE. I WAS FORCE TO LEARN PHP/MYSQL FOR THE 2WEEKS AND I LIKE I STATED IN MY EARLIER POST, NO GIVING UP. I AM SURE YOUR ARE WAITING TO SEE THE ERROR I DETECTED, WAIT FOR IT, IT WILL SURPISE YOU, NOT EVEN THE PEOPLE THAT OFFERED TO HELP SAW IT THAT IS WHY I AM STILL IN DOUBT IF IT IS THE REAL PROBLEM. RIGHT NOW, I AM HAVING A CROCODILE SMILE, FROM EAR TO EAR. I EVEN FEEL LIKE GOING PEOTIC, A TALENT I ALMOST LEFT. NOW THIS IS THE PROBLEM, ![]() WAIT FOR IT, IT IS LOADING, ![]() LOADING, OK I AM SORRY BUT THAT IS THE JOY ASSOCIATED WITH CRACKING A CODE IF YOU LOOK AT MY $_post VALUE, YOU WILL SEE THAT IT WAS WRITTEN IN SMALL LETTERS $Lastname=$_post['Lastname'];I WAS FORTUNATE TO NOTICE IT AFTER FOLLOWING AN EXAMPLE ONLINE, LINE BY LINE. I WAS ABLE TO DO THIS BY TELLING MYSELF THAT I AM FAULTY SOMEWHERE, WHICH WAS HARD FOR ME AFTER SPENDING SO MUCH TIME FIXING MY EYES ON THE CODE FOR OVER 7 HOURS AND SEEING NOTHING. SO I CHANGED THE POST VALUES TO CAPITAL LETTERS LIKE THIS $Lastname=$_POST['Lastname']; $Othernames=$_POST['Othernames']; $Dob=$_POST['Dob']; $Sex=$_POST['Sex']; $Permanentaddress=$_POST['Permanentaddress']; $Contactaddress=$_POST['Contactaddress']; $Stateoforigin=$_POST['Stateoforigin']; $LGA=$_POST['LGA']; $Hometown=$_POST['Hometown']; $Parentsname=$_POST['Parentsname']; AND THAT SOLVED THE TWO WEEKS PROBLEM. PHEW! THAT WAS SUCH A HECTIC WORK. NOW I CAN TAKE MY REST AND SLEEP WITHOUT DREAMING OF CODES FOR THE NEXT MORNING. SPECIAL THANKS TO NDUAJ, YAWATIDE,OMNIPOTENS,KEHER,XEZEDU AND EVERYBODY THAT HAVE VIEWED THIS BOARD, GOD BLESS YOU ALL. UNTIL ANOTHER CODE COMES MY WAY, TAR TAR FOR NOW. ![]() |
| Re: Why Is My Database Result Empty. by OmniPotens(m): 7:46pm On Dec 05, 2008 |
Thank God for you. My little piece of code for you was on caps though I never noticed yours was on small letters. Ran it here and found the same error so started it all over again with fewer fields and they were actually responding. Thank God more again. I wish you many more codes ahead! |
| Re: Why Is My Database Result Empty. by internetpo(m): 5:35pm On Dec 10, 2008 |
what's going on here? ![]() |
| Re: Why Is My Database Result Empty. by bug24(m): 8:09pm On Dec 10, 2008 |
@internetpo his codes are submitting but are not displaying anything, the fields keep filling up but nothing in them, i think thats a new kind of dbase virus, heyyyy u;ve got a virus in your databaseeeeeeeeee. ![]() |
How To Insert Excel Data Into My Database • Will This Likely Overload My Server Or Crash My Database? • How Can I Link A Form In My Website To A Table In My Database • 2 • 3 • 4
Programmers Are Gods, Designers Their Creations. • Websites For Sale! • Where Can I Get Microsoft Frontpage To Download Or Buy?

)
