Jump to content

CyberShot

Members
  • Posts

    322
  • Joined

  • Last visited

Everything posted by CyberShot

  1. yes, that did the trick. I had that once but changed it while I was looking for the problem. Good catch
  2. okay, I made all those changes. Good catch. I am still coming up empty. it's not echoing out the list. Which I am doing simply to test that the code is working here is both scripts just in case <form method="post" action="formData.php" id="form1"> <table width="350" border="0"> <tr> <td>First Name:</td> <td><input type="text" name="firstName" id="first" /></td> </tr> <tr> <td>Last Name:</td> <td><input type="text" name="lastName" id="last" /></td> </tr> <tr> <td>Company Name:</td> <td><input type="text" name="companyName" id="company" /></td> </tr> </table> <br /> <br /> <table width="350" border="0"> <tr> <td>Home Phone:</td> <td><input type="text" name="homePhone" id="homePhone" /></td> </tr> <tr> <td>Cell Phone:</td> <td><input type="text" name="cellPhone" id="cellPhone" /></td> </tr> <tr> <td>Company Phone:</td> <td><input type="text" name="companyPhone" id="companyPhone" /></td> </tr> <tr> <td>Amount Owed:</td> <td><input type="text" name="amount" id="amount" /></td> </tr> <tr> <td> </td> <input type="hidden" name="submitted" value="form1"> <td><input type="submit" value="submit" name="submit" id="submit"/></td> </tr> </table> </form> the second form <form method="post" name="form2" action="formData.php"> <?php if($result){ echo "<select name=\"listNames\">"; while($row = $result->fetch_object()){ $id = $row->namesID; $name = $row->firstName . " " . $row->lastName; echo "<option value=\"{$id}\">$name </option>"; } echo "</select>"; } ?> <input type="hidden" name="submitted" value="form2"> <input type="submit" name="form2" value="submit"> </form> and the action page if(isset($_POST['submitted'])){ if($_POST['submitted'] == 'form1') if(isset($_POST['submit'])){ $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $companyName = $_POST['companyName']; $homePhone = $_POST['homePhone']; $cellPhone = $_POST['cellPhone']; $companyPhone = $_POST['companyPhone']; //checking the values are filled //echo $firstName. " " . $lastName . " " . $companyName . " " . $homePhone . " " . $cellPhone . " " . $companyPhone; $mysql->query("INSERT INTO names(firstName,lastName,companyName)values('$firstName','$lastName','$companyName')"); } if( $_POST['submitted'] == 'form2' ){ $list = $_POST["listNames"]; echo $list; echo "Success"; } } Thanks for the help
  3. okay, I did that. But I am coming up empty. I know the button works because I am getting the success echoed my form <form method="post" name="form2" action="formData.php"> <?php if($result){ echo "<select name=\"listNames\">"; while($row = $result->fetch_object()){ $id = $row->namesID; $name = $row->firstName . " " . $row->lastName; echo "<option value\"$id\">$name </option>"; } echo "</select>"; } ?> <input type="submit" name="form2" value="submit"> </form> and my formData.php if(isset($_POST['form2'])){ $list = $_POST["listNames"]; echo $list; echo "Success"; }
  4. I am working on that now. What would you suggest I do? I want this select box to be in a different location on my page. So it is outside the main form which means I made a second form that when you push the submit button goes to my formdata.php page. But I already have a isset function for the first submit button. How would you suggest handling the second submit button on this page?
  5. nope. I thought because I didn't have the select list in a form tag. but it's still not working. <form method="post" name="form2" action=""> <?php if($result){ echo "<select name=\"listNames\">"; while($row = $result->fetch_object()){ $id = $row->namesID; $name = $row->firstName . " " . $row->lastName; echo "<option value\"$id\">$name </option>"; } echo "</select>"; echo $list; } ?> </form>
  6. okay, i did that like so $list = $_POST["listNames"]; if($result){ echo "<select name=\"listNames\">"; while($row = $result->fetch_object()){ $id = $row->namesID; $name = $row->firstName . " " . $row->lastName; echo "<option value\"$id\">$name </option>"; } echo "</select>"; echo $list; } but I get an error saying Undefined index: listNames on this line $list = $_POST["listNames"];
  7. I have a test database, I have two names in the database which get returned just fine in my html dropdown. I am trying to figure out how to figure out which item in the list was selected so that I can return information from another table based on the selected id. This is what I am trying now but I don't know how to proceed or if it is correct $result = $mysql->query("SELECT * FROM names") or die($mysql->error); ?> <select> <?php if($result){ while($row = $result->fetch_object()){ $id = $row->nameID; $name = $row->firstName . " " . $row->lastName; ?> <option value"<?php $id ?>"><?php echo $name ?></option> <?php }?> </select> <?php } ?>
  8. when I did my test queries, I had several that failed. so when I first discovered insert_id and echoed it to see what it did, I got back the value of 19 when I looked in the database, my last primary id was 9. They don't match. which is why I wanted to reset the values. What do you do when insert_id returns 19 and you are only on 9?
  9. why would I want to count the rows of a table? that was the whole point to this post. the only way I know of to get the primary key is by using insert_id which is why I wanted to know how I could reset the count. insert_id won't use count() for anything that I know of. it gets the id of the current query and I plan on using that to insert into my foreign key like this ("INSERT INTO phone(home, cell) VALUES($home, $cell, $mysql->insert_id)");
  10. So this is the standard practice to get the id to insert into the foreign key? write another query every time to count the rows and then insert that number into the foreign key? That seems like it would take much more programming than just using insert_id
  11. Use the COUNT() for what? to get the id's to put into the foreign keys?
  12. I have three tables. two of my tables are linked to the names table with the namesID foreign key. So when I tried my query, I tried SELECT * FROM names, amounts, phone WHERE names.namesID = phone.nameID, amounts.nameID the idea is to return a name, phone number and amount owed from the tables. I am getting an error that says incorrect syntax near amounts.nameID
  13. because I am teaching myself how to work with databases. When a query fails, it still seems to auto increment the count which eventually throws off my count for doing what I want to do do. So I am using insert_id to get the ID of the primary key so that I can insert that number into the foreign key of my child tables. last night, the insert_id was return 19 but the primary key of the parent was only on 9 So I needed to reset things to keep working properly
  14. using phpmyadmin, I tried to reset the auto_increment but it won't work. I tried a query that I found googling the issue that sets it to one but then whey I tried a new query to see what the id was, it incremented from 8 to 9 instead of showing 1. how do you do this without recreating the database?
  15. Okay, I tried setting up a class structure instead of using functions. I created MyClasses.php and so far just have this in it class mysql { function connect(){ $mysql = new MySQLi('localhost','cybershot','pascal35','billpay') or die($mysql->error); } } now in my index page, I included the MyClasses.php file and down where I wanted to perform a query, I have this $mysql = new mysql(); $mysql->connect(); $result = $mysql->query("SELECT * FROM names") or die($mysql->error); but now I get an error saying Call to undefined method mysql::query() in C:\wamp\www\BillPay\index.php on line 52 which should be this line $result = $mysql->query("SELECT * FROM names") or die($mysql->error);
  16. I don't know what you mean when you say the same data in two separate tables. I have table names firs name last name company name table phone home cell company phone my form asks for the information above then I want to insert it. I am having trouble using just one insert query to insert whatever values were filled into the form. Someone else here said that you can't use one query to insert into to tables but I am finding code online for it.
  17. I am experimenting with some code. I have an html form that asks for first, last and company name also for home, cell and company phone numbers. I have been trying to insert the values into both tables with one insert query. Something I read online but it doesn't seem to work. If I use one insert query to insert into one table, then it works fine So if I want to insert the values from my form into two tables, do I need to use two insert queries? How is this normally done
  18. if there is so such thing as a multiple table insert query, why am I finding them online when I google it? I have re worked my query several times and it is getting better. I also fixed the error code. it doesn't give me the error anymore. It also doesn't give me an error on the insert query. right now, it just doesn't insert. The code says it does but the table is empty
  19. okay, that makes sense. Now do you know of a tutorial that shows this? after 3 days of searching, I have been unable to find one. Someone could make this tutorial and sell it and make money. There are website that buy them. Like this one for example http://marketplace.tutsplus.com/
  20. I am sure I have done this. I will try it again and let you know how it goes. Usually I get an error saying that i can't update or insert to the child table due to a foreign key restraint.
  21. i used the nnodb or whatever it is. Here is exactly what I am trying to figure out I want to make a database for a bill application. So I will have tables = names, phone, amounts so phone and amounts will be linked to names by foreign keys. so the idea is that I can enter 4 names, 2 numbers and one amount and be able to pull the information out of the database that goes with the right name. That means that I think the phone table and the amounts table needs to know how to keep track of what information goes with which name. I have tried setting the relationships but I get errors when it comes time to input the data. So how do you set up the database so that it will keep track of the id's automatically like the auto increment? Or do I have to tell each table to automatically insert blanks if there is no data so that each insert will match up?
  22. okay, I figured out what I did wrong and I got the success message, but the table doesn't show the information. I changed it to this $insert = ("INSERT INTO names('firstName','lastName','companyName'), phone('home','cell','company') values('$firstName','$lastName','$companyName','$homePhone','$cellPhone','$companyPhone'"); $mysql->query($insert);
  23. yep. I am sure. Yes, it talked about 1nf and second and so on but didn't show how to relate the tables. It talked about how you would get an error if you tried to add to the tables in a certain way. I have gotten those errors. What I wanted the article to do was give a step by step on how to set up the database it was talking about. Primary and foreign keys. and then show how to insert data into those tables while keeping the relationship. It did not do that.
  24. i intended it to insert the values from the form into the database. Why won't it work?
×
×
  • 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.