Jump to content

Data doesn´t go into db?


eduard

Recommended Posts

Data doesn´t go into db! Why? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><HTML><head><meta http-equiv="content-type" content="text/ html; charset=UTF-8"><title>Eduard Lid</title><link rel="stylesheet" type="text/css" href="ex1.css"></head><body><br><div id="idioma"><p>Chose your lenguage:</p>Seleccione su idioma:<form method="post" name="nav"><br><select name="lang" onChange="document.location.href=document.nav.lang.options[document.nav.lang.selectedIndex].value"><option value="portfolio.html" selected >English </option><option value="portfolio.html">Español </option><option value="portfolio.html">German </option><option value="portfolio.html">Dutch </option><option value="portfolio.html">French </option></select><br><br><?php$Site_Name = $_POST['site_name'];$Site_URL = $_POST['site_url'];$Description = $_POST['Description'];$con = mysql_connect("localhost","root","usbw") or die(mysql_error());mysql_select_db("website", $con);$sql="INSERT INTO links (Site_Name, Site_URL, Description)VALUES ('$_POST[site_name]','$_POST[site_url]','$_POST[Description]')";if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error());}mysql_close($con);?><form action="insert.php" method="POST"> <label for="s_name">Site Name: </label> <input type="text" id="s_name" name="site_name"/> <label for="s_url">Site URL: </label> <input type="text" id="s_url" name="site_url"/> <label for="Description">Description:</label> <input type="text" id="Description" name="Description"/> <input type="submit" value="Add Link"/></form></div><div id="floater"><ul id="flags"> <li>eng<a href="english.html"><span id="amer"></span></a></li> <li>es<a href="spanish.html"><span id="spanish"></span></a></li> <li>d<span id="germ"></span></li> <li>nl<span id="dutc"></span></li> <li>f<span id="fren"></span></li></ul></div><!--end #floater --><div id="vertical"></div><div id="main"><p><img id="eduard" src="eduard.JPG" alt="img Eduard Lid"></p><p align="center"> <iframe width="450" height="300" src="http://www.youtube.com/embed/h2AWKgU0cN4" frameborder="0" allowfullscreen></iframe><img id="lake" src="lake.jpg" alt="img lake"></p><div id="content"><p>Web designer<span class="right">Diseñador de sitios web</span></p><p>Translator<span class="right">Traductor</span></p><ul id="links"><li><a href="english.html">more</a></li><li><a href="spanish.html">más</a></li></ul></div></div><!--end #main --><h1>Eduard Lid</h1><p id="copyright">Copyright © 2012</p></body></HTML>

  • Like 1
Link to comment
Share on other sites

What is the above page called? I'm assuming that's your homepage, so something like index.html?
Yes (index.html)
Link to comment
Share on other sites

wow, it always goes back to square one with you, doesn't it? 1) you have PHP in an HTML page. So that right off the bat is wrong, and is the first thing that's taught on the tutorials page.2) you're submitting to index.php, so that's never gonna happen, since your page with the INSERT code is in index.html (also, see number 1).

Edited by thescientist
Link to comment
Share on other sites

The form is being submitted to a page called insert.php. That may explain why nothing is being added to the database table. Also, if you're going to have php in HTML/PHP webpage, you have to change the extension to .php: index.php

Link to comment
Share on other sites

The form is being submitted to a page called insert.php. That may explain why nothing is being added to the database table. Also, if you're going to have php in HTML/PHP webpage, you have to change the extension to .php: index.php
But index.php has to be a web page?I can´t rename the index.html - into index.php?I changed both, but still it doesn´t work! Edited by eduardlid
Link to comment
Share on other sites

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><HTML><head><meta http-equiv="content-type" content="text/ html; charset=UTF-8"><title>Eduard Lid</title><link rel="stylesheet" type="text/css" href="ex1.css"></head><body><br><div id="idioma"><p>Chose your lenguage:</p>Seleccione su idioma:<form method="post" name="nav"><br><select name="lang" onChange="document.location.href=document.nav.lang.options[document.nav.lang.selectedIndex].value"><option value="portfolio.html" selected >English </option><option value="portfolio.html">Español </option><option value="portfolio.html">German </option><option value="portfolio.html">Dutch </option><option value="portfolio.html">French </option></select><br><br><?php$Site_Name = $_POST['site_name'];$Site_URL = $_POST['site_url'];$Description = $_POST['Description'];$con = mysql_connect("localhost","root","usbw") or die(mysql_error());mysql_select_db("website", $con);$sql="INSERT INTO links (Site_Name, Site_URL, Description)VALUES ('$_POST[site_name]','$_POST[site_url]','$_POST[Description]')";if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error());}mysql_close($con);?><form action="index.php" method="POST"> <label for="s_name">Site Name: </label> <input type="text" id="s_name" name="site_name"/> <label for="s_url">Site URL: </label> <input type="text" id="s_url" name="site_url"/> <label for="Description">Description:</label> <input type="text" id="Description" name="Description"/> <input type="submit" value="Add Link"/></form></div><div id="floater"><ul id="flags"> <li>eng<a href="english.html"><span id="amer"></span></a></li> <li>es<a href="spanish.html"><span id="spanish"></span></a></li> <li>d<span id="germ"></span></li> <li>nl<span id="dutc"></span></li> <li>f<span id="fren"></span></li></ul></div><!--end #floater --><div id="vertical"></div><div id="main"><p><img id="eduard" src="eduard.JPG" alt="img Eduard Lid"></p><p align="center"> <iframe width="450" height="300" src="http://www.youtube.com/embed/h2AWKgU0cN4" frameborder="0" allowfullscreen></iframe><img id="lake" src="lake.jpg" alt="img lake"></p><div id="content"><p>Web designer<span class="right">Diseñador de sitios web</span></p><p>Translator<span class="right">Traductor</span></p><ul id="links"><li><a href="english.html">more</a></li><li><a href="spanish.html">más</a></li></ul></div></div><!--end #main --><h1>Eduard Lid</h1><p id="copyright">Copyright © 2012</p></body></HTML>

Link to comment
Share on other sites

Are you getting any errors? If so, you can post them as well.Also, are you sure you renamed it correctly? If clicked on the file and right clicked and clicked on rename, that doesn't rename the WHOLE file. Make sure the whole file is index.php and not index.php.html. If you're under windows and you went directly to the file and right clicked on it and clicked on rename, and typed index.php, it will be saved as index.php.html still.

Link to comment
Share on other sites

We went over this in another thread. You're not using the correct names for $_POST. Look at the names in your form. Sorry, the above is incorrect, I was looking at ID attributes instead of names. Also, just because I know you're going to ask this question again, I'll go ahead and answer it now. The reason why it is inserting blank records into your database is because you're not checking if the form was submitted before you add the data. One other issue is that you have one form inside another one, you have 2 forms on that page and the first one never ends.

Link to comment
Share on other sites

Are you getting any errors? If so, you can post them as well. Also, are you sure you renamed it correctly? If clicked on the file and right clicked and clicked on rename, that doesn't rename the WHOLE file. Make sure the whole file is index.php and not index.php.html. If you're under windows and you went directly to the file and right clicked on it and clicked on rename, and typed index.php, it will be saved as index.php.html still.
I thought so! That´s why I copied and paste the text to a new file!. But now it doesn´t open as a web page! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><HTML><head><meta http-equiv="content-type" content="text/ html; charset=UTF-8"><title>Eduard Lid</title><link rel="stylesheet" type="text/css" href="ex1.css"></head><body><br><div id="idioma"><p>Chose your lenguage:</p>Seleccione su idioma:<form method="post" name="nav"><br><select name="lang" onChange="document.location.href=document.nav.lang.options[document.nav.lang.selectedIndex].value"><option value="portfolio.html" selected >English </option><option value="portfolio.html">Español </option><option value="portfolio.html">German </option><option value="portfolio.html">Dutch </option><option value="portfolio.html">French </option></select><br><br><?php$Site_Name = $_POST['site_name'];$Site_URL = $_POST['site_url'];$Description = $_POST['Description'];$con = mysql_connect("localhost","root","usbw") or die(mysql_error());mysql_select_db("website", $con);$sql="INSERT INTO links (Site_Name, Site_URL, Description)VALUES ('$_POST[site_name]','$_POST[site_url]','$_POST[Description]')";if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error());}mysql_close($con);?><form action="index.php" method="POST"> <label for="s_name">Site Name: </label> <input type="text" id="s_name" name="site_name"/> <label for="s_url">Site URL: </label> <input type="text" id="s_url" name="site_url"/> <label for="Description">Description:</label> <input type="text" id="Description" name="Description"/> <input type="submit" value="Add Link"/></form></div><div id="floater"><ul id="flags"> <li>eng<a href="english.html"><span id="amer"></span></a></li> <li>es<a href="spanish.html"><span id="spanish"></span></a></li> <li>d<span id="germ"></span></li> <li>nl<span id="dutc"></span></li> <li>f<span id="fren"></span></li></ul></div><!--end #floater --><div id="vertical"></div><div id="main"><p><img id="eduard" src="eduard.JPG" alt="img Eduard Lid"></p><p align="center"> <iframe width="450" height="300" src="http://www.youtube.com/embed/h2AWKgU0cN4" frameborder="0" allowfullscreen></iframe><img id="lake" src="lake.jpg" alt="img lake"></p><div id="content"><p>Web designer<span class="right">Diseñador de sitios web</span></p><p>Translator<span class="right">Traductor</span></p><ul id="links"><li><a href="english.html">more</a></li><li><a href="spanish.html">más</a></li></ul></div></div><!--end #main --><h1>Eduard Lid</h1><p id="copyright">Copyright © 2012</p></body></HTML>
Link to comment
Share on other sites

We went over this in another thread. You're not using the correct names for $_POST. Look at the names in your form. Sorry, the above is incorrect, I was looking at ID attributes instead of names. Also, just because I know you're going to ask this question again, I'll go ahead and answer it now. The reason why it is inserting blank records into your database is because you're not checking if the form was submitted before you add the data. One other issue is that you have one form inside another one, you have 2 forms on that page and the first one never ends.
What so you mean by checking the form?
Link to comment
Share on other sites

A form sends data. Before using the data you have to first check that the form actually sent any data.I'm not sure how to put it simpler.

Link to comment
Share on other sites

unclosed <form> element, i know this is a waste of time, any chance of validating page before posting, hey what do you say...its what its there for, to point out these errors.
I thought the validator is called: ´dsonesuk´!
Link to comment
Share on other sites

A form sends data. Before using the data you have to first check that the form actually sent any data.I'm not sure how to put it simpler.
How?
Link to comment
Share on other sites

One way is see if the $_POST array is empty.

if(empty($_POST)) {  // No form data was sent}

Or

if(!empty($_POST)) {    // Form data was sent}

Link to comment
Share on other sites

But now it doesn´t open as a web page!
If that's true then you didn't give it a correct name that ends in .php. For what it's worth, this is part of why we get frustrated with you - you never seem to learn the basics. You're trying to debug PHP and you can't even figure out how to name the file or how to combine 2 HTML files into one valid document. Those are the absolute basics of HTML, not even PHP, just basic HTML. Many of your problems are HTML problems, not PHP problems, and you can't even figure out the HTML problems on your own. This is why we get frustrated, just so you understand. You've been here 18 months, you should know by now how to set up a valid HTML document. The first thing you learn in the PHP tutorial (literally, in the intro) is that PHP files (usually) need the extension .php, but you're still trying to run PHP code inside a .html file. Do you understand our frustration?
Link to comment
Share on other sites

No! everyone HERE seems to be your personal validator, Oh! my form does not work, well it can't possibly be anything done wrong by myself, so it would be pointless in validating my page at http://validator.w3.org/, guess i'll just have post yet again! dah, problems, problems, problems.
You´re totaññy right, but sometimes (now!) persons forget something! Human, isn´t it?
Link to comment
Share on other sites

Humans, yes! do forget! but continuously, No! they should be able to retain some memory and knowledge and not keep repeating the same mistakes, again and again, and again. I mean 18 Months and you STILL can't get through the basics of html and php.

Link to comment
Share on other sites

If that's true then you didn't give it a correct name that ends in .php. For what it's worth, this is part of why we get frustrated with you - you never seem to learn the basics. You're trying to debug PHP and you can't even figure out how to name the file or how to combine 2 HTML files into one valid document. Those are the absolute basics of HTML, not even PHP, just basic HTML. Many of your problems are HTML problems, not PHP problems, and you can't even figure out the HTML problems on your own. This is why we get frustrated, just so you understand. You've been here 18 months, you should know by now how to set up a valid HTML document. The first thing you learn in the PHP tutorial (literally, in the intro) is that PHP files (usually) need the extension .php, but you're still trying to run PHP code inside a .html file. Do you understand our frustration?
A problem for a beginner can´t be simple explained! I´ve to ask many times the same question until I get a good simple reply (by you!) (combining or integrating :glare: ) mysql queries into a html file. I cook now for more than 20 years and still making mistakes! I´m not a ´loop´ person (thank god!)! What do you think I´ve been doing those 18 months?Facts: living at 4 different locations, living in 2 foreign countries (Chile and Argentina), since 4 months no personal computer and because of my (fysically) dsabillity I´ve far less time than you have! Do you understand my frustration? (P. s. you wrote me yourself that the tutorials aren´t good! - 2011) Edited by eduardlid
Link to comment
Share on other sites

I´ve to ask many times the same question until I get a good simple reply
See, that's not true though. You could do the research to look up the answers yourself. Most people do the research to look up the answers themselves. In fact, I actually think that you may be the only person here who only asks questions and doesn't do research, and I've been telling you from the start that any successful programmer does their own research. You keep saying it's too complicated or you can't understand it, but I don't think that's true, I don't think you try hard enough. Maybe you glance through the text but you don't make an effort to understand it. The reason I think that is because the information that you don't know is very basic, it's very simple, and it's very easy to understand. People from 10 years old or less up until the 70s or 80s, with no programming experience, can understand that information. I don't believe you can't understand it, I believe that you can but you don't try hard enough to learn it. Because of that, I don't see the point in trying to teach you anything because I don't think you're going to put the effort into learning that I put into explaining it.
Facts: living at 4 different locations, living in 2 foreign countries (Chile and Argentina), since 4 months no personal computer and because of my (fysically) dsabillity I´ve far less time than you have!
People living in any location, in any country, with or without a computer, with or without a disability, are able to learn how to program. It doesn't take huge amounts of time, it only takes dedication. I've never seen you demonstrate true dedication to learning how to program other than your persistence in coming back to ask more questions (which only seems to be motivated by a desire to get money, not a desire to actually learn how to program).
Do you understand my frustration?
Of course I do, but it's not an excuse. And you never answered whether you understood our frustration, you just made excuses.
(P. s. you wrote me yourself that the tutorials aren´t good! - 2011)
That's true, they leave out a lot of information and present a lot of information poorly, but the basic information is there and you don't know it.
Link to comment
Share on other sites

How about this for an example, a girl from Pakistan who at 9 years old became Microsoft certified. She learned to program at the age of 9 while living in a region where some girls get acid thrown on them for going to school. Are you going to tell me that you've got it tougher than a 9 year old Pakistani girl? Unfortunately, we won't know what kind of impact she would have had on the world because she died this year at 16. http://en.wikipedia.org/wiki/Arfa_Karim

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...