jlgray48 Posted April 21, 2007 Share Posted April 21, 2007 I'm having some difficulty understanding the code below if someone could help. This is actually for an upcoming final where we have to find errors in code. Thanks for any help. Question: Find the errors in the code below. This code must add a record in a table called table_1 that is located in a database called DATABASE_1. <? $conn = mysql_connect ("computer_1", "john_adam", "tigerismycat" ) ;; mysql_select_db ("database_1", $conn); $field1 = $_REQUEST["field_1"]; $field2 = $_REQUEST["field_2"]; $sql = "SELECT * FROM table_1" ; If (mysql_query ($sql, $conn) ) { Print "New record was added"; } ELSE { Print "New record entry fails!" : } ?> I understand the 2 connection lines, I don't understand the $field lines. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 21, 2007 Share Posted April 21, 2007 Not meaning to be rude or anything but if this is for an upcoming final(meaning the end of the class) shouldn't you of obtained this knowledge by now Quote Link to comment Share on other sites More sharing options...
jlgray48 Posted April 21, 2007 Author Share Posted April 21, 2007 No Quote Link to comment Share on other sites More sharing options...
keeB Posted April 21, 2007 Share Posted April 21, 2007 proz: I think he came for help not for a lecture. @topic: Print "New record entry fails!" : Should be Print "New record entry fails!"; Also, the SQL String is saying 'SELECT' when it should be 'INSERT INTO' $_REQUEST = the same as $_POST or $_GET, it just doesn't define which one (for pages allowing both POST and GET requests.) I am assuming the professor wants the code to look something like <?php $conn = mysql_connect ("computer_1", "john_adam", "tigerismycat" ) ;; mysql_select_db ("database_1", $conn); $field1 = $_REQUEST["field_1"]; $field2 = $_REQUEST["field_2"]; $sql = "INSERT INTO table_1 values('$field1', '$field2')" ; If (mysql_query ($sql, $conn) ) { Print "New record was added"; } ELSE { Print "New record entry fails!"; } ?> Quote Link to comment Share on other sites More sharing options...
per1os Posted April 21, 2007 Share Posted April 21, 2007 He came her so someone else would do his homework for him so he does not have to learn anything. Smart move by him, suckered one guy in. Quote Link to comment Share on other sites More sharing options...
jlgray48 Posted April 21, 2007 Author Share Posted April 21, 2007 Did I say this was homework? No, it is for a final and I am making sure that my work is correct if that is ok with you. I am definitely behind but that is because my father passed away 2 weeks ago and I haven't been able to attend a nite class for 2 weeks. I will be posting several more questions in the next few days. I would appreciate it if you would just ignore them. I don't have time to waste with smart SmartA$$ like you. Quote Link to comment Share on other sites More sharing options...
per1os Posted April 21, 2007 Share Posted April 21, 2007 Sad sap stories always tug at me especially ones over the internet :cries: Have fun bud. Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 21, 2007 Share Posted April 21, 2007 He came her so someone else would do his homework for him so he does not have to learn anything. Smart move by him, suckered one guy in. Did I say this was homework? No, it is for a final and I am making sure that my work is correct if that is ok with you. I am definitely behind but that is because my father passed away 2 weeks ago and I haven't been able to attend a nite class for 2 weeks. I will be posting several more questions in the next few days. I would appreciate it if you would just ignore them. I don't have time to waste with smart SmartA$$ like you. Sad sap stories always tug at me especially ones over the internet :cries: Have fun bud. jlgray, watch your language first of all, nobody here is entitled to help, they do it by choice. Frost, I will say that was kinda harsh, though. Anyways, there's no need to argue, it's over. He got his answer and he can now go on with his final. Quote Link to comment Share on other sites More sharing options...
jlgray48 Posted April 21, 2007 Author Share Posted April 21, 2007 Thanks Glyde. I post on message boards quite often. That's how I have learned most of what I know about programming. When you get on message boards there is always 2 or 3 posters like this guy who wants to chime in with worthless posts. My response to them is always, if you don't want to offer help then why do you sit around on message boards in the first place. I help other people on network and Cisco forums and I only go there to help not hinder. Who cares if the information the person is posting is for homework. They came here not knowing and hopefully left knowing. Isn't that what getting educated is about? Enough spewing, I've got to put up another question, I'm stuck again. Thanks again...... jg Quote Link to comment 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.