Jump to content

Next step?


eduard

Recommended Posts

Still the same error (after modification!): Notice: Undefined index: s_name in E:\USBWebserver v8_en\root\insert.php on line 3Notice: Undefined index: s_url in E:\USBWebserver v8_en\root\insert.php on line 4Notice: Undefined index: description in E:\USBWebserver v8_en\root\insert.php on line 5Error: 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 '['s_name'], ['s_url'], ['description'])' at line 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>database</title></head><body><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></body></html> <?php $s_name = $_POST['s_name']; $s_url = $_POST['s_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 (['s_name'], ['s_url'], ['description'])";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con);?>

Link to comment
Share on other sites

  • Replies 118
  • Created
  • Last Reply

Top Posters In This Topic

VALUES (['s_name'], ['s_url'], ['description'])";
where is your variables? check the one you declared an wha you used. <input type="text" id="s_name" name="Site_Name"/> check the name of your input field and your $_POST array's indexes$_POST['s_name'] they need to be same Edited by birbal
Link to comment
Share on other sites

Also... <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>doesn't match with... $s_name = $_POST['s_name'];$s_url = $_POST['s_url']; .. why it says undefined index. I am not sure why you got 'description' too since it matches with the name attribute as I just tested the above exactly as you have it and I only got undefined index for the above. (That's if the error is referring to this line: $description = $_POST['description']; line 5)

Link to comment
Share on other sites

where is your variables? check the one you declared an wha you used. <input type="text" id="s_name" name="Site_Name"/>check the name of your input field and your $_POST array's indexes$_POST['s_name'] they need to be same
In this html form I use 3 different ways to write e. g. ´Site Name´:1 s_name for label2 Site Name3 Site_NameWhich one has to be the same as in my php script??? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>database</title></head><body><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></body></html>
Link to comment
Share on other sites

Also... <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>doesn't match with... $s_name = $_POST['s_name'];$s_url = $_POST['s_url']; .. why it says undefined index. I am not sure why you got 'description' too since it matches with the name attribute as I just tested the above exactly as you have it and I only got undefined index for the above. (That's if the error is referring to this line: $description = $_POST['description']; line 5)
Very clear! But how could I know that the name (could nobody explain to me the meaning of ´name´?) in my html form must be the same as in my php script?
Link to comment
Share on other sites

Very clear! But how could I know that the name (could nobody explain to me the meaning of ´name´?) in my html form must be the same as in my php script?
###### read the tutorials!!!!!!!! Look at their examples!! ##### not only that, we've told you!! sigh, i hate to say it, but I don't think you can really learn this stuff at all.... Edited by thescientist
Link to comment
Share on other sites

###### read the tutorials!!!!!!!! Look at their examples!! ##### not only that, we've told you!! sigh, i hate to say it, but I don't think you can really learn this stuff at all....
<?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 (['Site_Name'], ['Site_URL'], ['Description'])";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con);?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>database</title></head><body><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></body></html> As far as I can see, they are exactly the same, but still this error: Notice: Undefined index: Site_Name in E:\USBWebserver v8_en\root\insert.php on line 3Notice: Undefined index: Site_URL in E:\USBWebserver v8_en\root\insert.php on line 4Notice: Undefined index: Description in E:\USBWebserver v8_en\root\insert.php on line 5Error: 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 '['Site_Name'], ['Site_URL'], ['Description'])' at line 2
Link to comment
Share on other sites

Eduard, is that all on one page? Or is html page itself and the insert.php itself? If they are on the same page, try making them separate. Make sure the html page and insert.php file is in the same directory(folder) and then see if you still get the undefined index errors.

Edited by Don E
Link to comment
Share on other sites

<?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 (['Site_Name'], ['Site_URL'], ['Description'])";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added"; mysql_close($con); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>database</title></head> <body> <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> </body></html> As far as I can see, they are exactly the same, but still this error: Notice: Undefined index: Site_Name in E:\USBWebserver v8_en\root\insert.php on line 3 Notice: Undefined index: Site_URL in E:\USBWebserver v8_en\root\insert.php on line 4 Notice: Undefined index: Description in E:\USBWebserver v8_en\root\insert.php on line 5Error: 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 '['Site_Name'], ['Site_URL'], ['Description'])' at line 2
you really are a piece of work. still the same SQL problem, still the same misunderstanding of POST, still the same confusion about array indexes....I thought you said you already figured this out? You seemed so confident... you almost had us fooled...http://w3schools.inv...98 and as said by Don E., that if this is one page, then you've been told why there would be undefined index's herehttp://w3schools.inv...30 Honestly, my mind is blown at this point. All the work we've gone through, and yet you only manage to go backwards in your comprehension.

I'm convinced he has been a w3fools troll all this time

Edited by thescientist
Link to comment
Share on other sites

Very clear! But how could I know that the name (could nobody explain to me the meaning of ´name´?) in my html form must be the same as in my php script?
You know it by reading the long responses in full, rather than just skimming over them. From that very same explanation that you claimed to have found helpful:
In your HTML form, make sure to name the 'name' attribute for the input field. Example: <input type="text" name="myName" /> Highlighted in red is the 'name' attribute.
If they don't match, for example <input type="text" name="fname" /> and in PHP you have this: $_POST["myName"]; you'll get the 'undefined index' error message. "fname" and 'myName' don't match.
Link to comment
Share on other sites

Eduard, is that all on one page? Or is html page itself and the insert.php itself? If they are on the same page, try making them separate. Make sure the html page and insert.php file is in the same directory(folder) and then see if you still get the undefined index errors.
They are separated!
Link to comment
Share on other sites

They are separated!
then you need to present them as such. You should be helping us out and learning how to put code in code tags on this forum. it is a standard courtesy to explain and present your problem in the clearest and most presentable manner to those who you keep asking help from. JSG has also told you how to debug these kind of situations. You need to know if your form is even submitting correctly, and this is by outputting the content of $_POST. http://w3schools.invisionzone.com/index.php?showtopic=43189&st=0&p=238257entry238257 You must learn these things. Seriously. You say you understand them and that the replies are helpful, but still it's the same mistakes...
Link to comment
Share on other sites

I´m going to do it as follows!Because I don´t understand good what an array or attribute is and neither understand much of your ´technical´ lenguage, I start learning php from the beginning (not with W3Schools!).And as I´m in a hurry, I´ve to do that in some days! (I now start!)

Link to comment
Share on other sites

I´m going to do it as follows!Because I don´t understand good what an array or attribute is and neither understand much of your ´technical´ lenguage, I start learning php from the beginning (not with W3Schools!).And as I´m in a hurry, I´ve to do that in some days! (I now start!)
Well! good luck with that!. AS you have taken basically two years to learn simple BASIC php, mysql interaction using forms, and FAILED in understanding ANY OF IT, from w3schools, and this forum. Do you really think that you starting from scratch is really going help! come on who you kidding, just face it you just don't have the mind set to understand any of this to become a web developer/designer, as it goes in one ear and out the other. Just stick with what you can do, teaching English apparently. If there was a book 'php, mysql complete utter idiots' it would still be beyond you. JUST DO US A BIG FAVOUR AND GIVE IT UP.
Link to comment
Share on other sites

Well! good luck with that!. AS you have taken basically two years to learn simple BASIC php, mysql interaction using forms, and FAILED in understanding ANY OF IT, from w3schools, and this forum. Do you really think that you starting from scratch is really going help! come on who you kidding, just face it you just don't have the mind set to understand any of this to become a web developer/designer, as it goes in one ear and out the other. Just stick with what you can do, teaching English apparently. If there was a book 'php, mysql complete utter idiots' it would still be beyond you. JUST DO US A BIG FAVOUR AND GIVE IT UP.
GIVE IT UP! FORGET IT!Unfortunately, you haven´t read all my posts!Again a very simple reply of someone full of prejudiges! (and therefore with a very small mind. Php he knows and probably some other computer lenguages. What else? Not much I suppose!Us? This post is written by DSONEUK! Edited by eduardlid
Link to comment
Share on other sites

Got it!: <?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());}echo "1 record added";mysql_close($con);?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang='en' xml:lang='en' xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>database</title></head><body><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></body></html>

Link to comment
Share on other sites

Did I get all the time as error ´undefined index´ because the data which I filled in my html form didn´t go to my insert.php?

Link to comment
Share on other sites

Basically. insert.php wasn't receiving the data because $_POST array wasn't receiving the data. (because the name attribute from the input field(s) didn't match to $_POST array labels(index keys): ie: $_POST['site_name'])

Link to comment
Share on other sites

Basically. insert.php wasn't receiving the data because $_POST array wasn't receiving the data. (because the name attribute from the input field(s) didn't match to $_POST array labels(index keys): ie: $_POST['site_name'])
I´m too tired now, but I´ll study it tomorrow!
Link to comment
Share on other sites

Did I get all the time as error ´undefined index´ because the data which I filled in my html form didn´t go to my insert.php?
it will show undefined index when you first time load the page. when it comes to this line $s_name=$_POS['s_name'] it will try to assign $_POST['s_name'] but as still form is not been submited so it does not exist , thus it will show you undefined index. next when you will submit the form it will hold value, thus it wont show you any php notice. you can assure that it does not show notices you can use isset(). so it executes process part only when form is submited<form.....> </form>if(isset($_POST['name_of_your_submit_button'])){//process the form}
I´m going to do it as follows!Because I don´t understand good what an array or attribute is and neither understand much of your ´technical´ lenguage, I start learning php from the beginning (not with W3Schools!).And as I´m in a hurry, I´ve to do that in some days! (I now start!)
it is not the thing you can do in hurry it takes time. did this hurry help you a bit to learning this stuff since 1 year? sorry, but i dont think so. if you had show some patience i am almost sure you would improved much more than where are you now. as for technical language, you have to used with it. it works like that. you are going to work in technical line. that is what it is you can't avoid that. Cocerntrate on the Basics first. without it you are going to nowhere.never.
Link to comment
Share on other sites

Basically. insert.php wasn't receiving the data because $_POST array wasn't receiving the data. (because the name attribute from the input field(s) didn't match to $_POST array labels(index keys): ie: $_POST['site_name'])
Although it´s working now I want to determine (?) it:<label for="fName">First Name:</label><input type="text" id="fName" name="firstName" /><br/>- What means ´label for´?- What are ´fName´ and ´firstname´?- Which one has to be the same as in my php file?- What´s ´input type´?- What´s ´id´ (in php)?
Link to comment
Share on other sites

Although it´s working now I want to determine
That's the spirit!!! :) - When you click the text of a label, a form element will "gain focus" (for a text field, this means a blinking marker will appear on it, allowing you to type). In the "for" attribute, you specify the "id" of the element you want focused.- In the context of the "input" element, "fName" is the "id" of the input and "firstName" is the "name" of the input. These are the values of two different attributes that have nothing to do with each other.- The "name" attribute.- Literally, the type (as in "kind") of form field. Depending on the type, the browser will show a different way the user can fill the form in. You can see what the browser does for each type on this part of the HTML tutorial.- The "id" has no effect in PHP. Only the "name" does.A little theory (don't skip this!!! Read it in full!!! You'll need it!!!):The IDs have nothing to do with the whole form submission process.When you "submit" a form, what the browser does is to send PHP a collection of "name and value pairs". Each input element represents a pair, the name attribute reflects the name in the pair, and whatever the user fills in reflects the value in the pair.PHP puts all pairs in either the $_POST array or the $_GET array, depending on the form's "method" attribute. At this point, each pair is turned into an array "key and value pair". Another word for "key" is "index". The terms are slightly different in some other languages, but in PHP, they're synonymous.The IDs only have an effect on the page they're on. In it, they allow you to target a specific element for some purpose, such as (in the case of the label's "for" attribute) putting a focus to the element. IDs can appear on any element, whereas names can only appear on form elements.
Link to comment
Share on other sites

That's the spirit!!! :) - When you click the text of a label, a form element will "gain focus" (for a text field, this means a blinking marker will appear on it, allowing you to type). In the "for" attribute, you specify the "id" of the element you want focused.- In the context of the "input" element, "fName" is the "id" of the input and "firstName" is the "name" of the input. These are the values of two different attributes that have nothing to do with each other.- The "name" attribute.- Literally, the type (as in "kind") of form field. Depending on the type, the browser will show a different way the user can fill the form in. You can see what the browser does for each type on this part of the HTML tutorial.- The "id" has no effect in PHP. Only the "name" does. A little theory (don't skip this!!! Read it in full!!! You'll need it!!!): The IDs have nothing to do with the whole form submission process. When you "submit" a form, what the browser does is to send PHP a collection of "name and value pairs". Each input element represents a pair, the name attribute reflects the name in the pair, and whatever the user fills in reflects the value in the pair. PHP puts all pairs in either the $_POST array or the $_GET array, depending on the form's "method" attribute. At this point, each pair is turned into an array "key and value pair". Another word for "key" is "index". The terms are slightly different in some other languages, but in PHP, they're synonymous. The IDs only have an effect on the page they're on. In it, they allow you to target a specific element for some purpose, such as (in the case of the label's "for" attribute) putting a focus to the element. IDs can appear on any element, whereas names can only appear on form elements.
Thanks very much! However. it´s sunday morning here (Argentina), so I´ve to study it later!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...