Jump to content

hmiller73

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by hmiller73

  1. it was looking at that other php file. which had the right code. The code that I posted works all expect when to display the database data. It need it to do that on submit not when loaded. I am about ready to give up and just take the crappy grade.
  2. Ugg. This does nothing but display the form. It is not writing to the database and it doesnt display any data.
  3. after all that excitement I realize that the line pointing to the test.php was not the same as the file I named it. There for when It ran on submit it went to the other php file for the commands. Which is why it returned the data on submit. I can only have one file. So when I changed that to the new file I create, I do not get any error statements when I submit blank info and I don't send the data I submit to the database. So now I am really confused.
  4. I want to thank you from the bottom of my heart for taking the time to teach me this. You should become an instructor. Heather
  5. I cannot believe it!! I am so excited that this works. You are a true angel for me. Now if you don't mind could you explain what I did wrong and how you fix it so I can learn this. This was my first assignment and I don't even have a book to learn from.
  6. bless your heart. It does work when I hit submit now, But I get this error when I load it. Notice: Undefined index: submit in C:\wamp\www\index\startover\startover.php on line 32 if($_POST['submit'])
  7. I didn't know how to do that do I enter those tags before and after my code. I am new here.
  8. I have redone my script, but now it is not returning all the data in the database table. It is only returning what I just submitted. here is my new code. </html> <head> <title>myform</title> </head> <body> <form method="post" action="test.php"> Name: <br /> <input type="text" name="name" size="30" /><br /> Email: <br /> <input type="text" name="email" size="30" /><br /> <input type="submit" value="Submit" /> </form> </body> </html> <?php $databasename='week3'; // Name of the database $tablename='email'; // Name of the table $mysqladd='localhost'; // Address to the MySQL Server - Usually localhost or an IP address $mysqluser='root'; // Your MySQL UserName $mysqlpass=''; // Your MySQL Password @$name = addslashes($_POST['name']); @$email = addslashes($_POST['email']); ///CONNECT TO MYSQL working $link=mysql_connect($mysqladd,$mysqluser,$mysqlpass) or die('Database Error: ' . mysql_error()); //CONNECT TO DATABASE working mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error()); //Get data from Text, Post data to database working $strQuery = "INSERT INTO `email`(`name`,`email`)VALUES (\"$name\",\"$email\")" ; $result = mysql_query($strQuery); if (!$result) { die('Invalid query: ' . mysql_error()); } // print data table from database $result = mysql_query("SELECT * FROM email"); if($row = mysql_fetch_array($result)) { echo $row['name']; echo $row['email']; echo "<br />"; } // this doesn't return all the data in the table. It is only returning what I just entered. ?>
  9. I can only have one file. It has to be a php file extension and it had to include the html form coding within that file. If I would use more thank one file I would have this fixed already, but the instructor just wants one. I am to the point of tears in frustration with this. I have spent 16 hr today alone trying to research code on the internet. I have yet to find code that will do all of that I need to in one file.
  10. They seem to be using more that one php file, which I cannot do. This is the trouble I have been having. All the examples I can go by link to different files. They are not just one php file with all the code in it. Thanks for the help
  11. Thanks for the help, but I am totally lost on this. I don't know how to code this so that it works and I have no book to teach me. What I have in my code I have had to hunt and peck searching the Internet. I am pulling my hair out. My teacher expected us to learn PHP on our own to no references to learn from. I wish I could understand what you were asking me to do, but I don't. Thank you for attempting to help me
  12. I get an error when I place that in my script Parse error: parse error in C:\wamp\www\index\working\working.php on line 77
  13. where in my code would I place that?
  14. how do I get the data from the tables in the database to only show when I hit the submit button. This is my first php project and I am really lost on what to do.
  15. I am having trouble with a form. I am to have 1 script that will do the following: Two form fields : Name, Email 1 Submit Button On submit it should write the Name and Email to an SQL database and it should return all the data in the database tables below the form. When I load my script it shows all the data in the database tables, it is not waiting for me to hit submit. here is my code: Please note I am just learning php. Instructors notes: Your form will be identical to the original form, it will have one submit button. your script will do two actions (actually three) 1) get the POST data and put it in the DB -- if no data (because this isn't the result of a 'submit'), then skip this step. 2) display the form with the proper name and e-mail inserted 3) get the elements from the DB and display them below the form. Yes, you will be able to do all this with one script. <?php /* your logic to process the POST data including connecting to MySQL and putting it into the database */ // Receiving variables @$ip= $_SERVER['REMOTE_ADDR']; @$name = addslashes($_POST['name']); @$email = addslashes($_POST['email']); // Validation //saving record to MySQL database @$strQuery = "INSERT INTO `email`(`Name`,`email`)VALUES (\"$name\",\"$email\")" ; @$host = "localhost"; @$user = "root"; @$pw = ""; @$db = "week3"; $link = mysql_connect($host, $user, $pw); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($db, $link); if (!$db_selected) { die ('Can not use $db : ' . mysql_error()); } //insert new record $result = mysql_query($strQuery); if (!$result) { die('Invalid query: ' . mysql_error()); } mysql_close($link); $sql = "SELECT * FROM `email` WHERE 1 LIMIT 0, 30 "; mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("week3") or die(mysql_error()); // Retrieve all the data from the "email" table $result = mysql_query("SELECT * FROM email") or die(mysql_error()); // store the record of the "email" table into $row $row = mysql_fetch_array( $result ); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>myform</title> </head> <body> <div id="apDiv1"> <form id="form1" name="form1" method="post" action="working.php"> <p>Name <input type="text" name="name" id="name" /> </p> <p> </p> <p>Email <input type="text" name="email" id="email" /> <input type="submit" name="submit" id="submit" value="Submit" /> </p> </form> </div> </body> </html> <?php echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Email</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Name']; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.