Jump to content

Recommended Posts

Hi Guys,

 

i dont know if im in the right forum but i'll give it ago.

 

im working on a site which has a mysql database which among other things, stores:

name, rep number, issuedate, model, serial, tag, comments, issuer, and title.

 

all these variables are inserted into the database using a form on a php page.

 

this page i will to refer to as "registration page".  this page works perfectly and i can add entry's with no problem

 

what i would now like to do, is have an extremely similar page which has all of the same fields as the "registration page where i can type 1 of any details in any field.

sooooo.

say i want to do a search to see if a rep number is already registered,

i type in the number and if it exists, the rest of the fields get populated with the data from that row in the table.

becuause i want to be able to edit as well as search, i think this would be the best way to do it.

 

i've tried searching this on google, but i cant seem to find what im after.  it all seems to be either "print" which puts all the results on a page, or uses a drop down.  and if its a drop down, there's will have to be 9 fields which have around 300 entries (not benificial at all),

 

so an overview of what im after.  some code which can either be in another page or the current "registration" page where i can search for records and edit records easily.

 

thank you in advanced for any help

 

jack

Link to comment
https://forums.phpfreaks.com/topic/139984-searching-mysql/
Share on other sites

Well what do you have so far? If you've managed to write a registration type page, you're obviously comfortable enough with gathering form data and using it in a query. That's obviously the first part - take whatever information the user types in and query the database with it.

 

If you've found tutorials showing you how to search a database and print out the results then all you need to do is adapt those tutorials so that the results are printed inside the form.

Link to comment
https://forums.phpfreaks.com/topic/139984-searching-mysql/#findComment-732367
Share on other sites

hi,

 

thanks for the reply.  printing to a text field is the bit im having problems with.  this is the code being used as my starting point.  prints everything in the table on a page.

 

<?php

// Connects to your Database

mysql_connect("localhost", "root", "toor") or die(mysql_error());

mysql_select_db("phplogin") or die(mysql_error());

$data = mysql_query("SELECT * FROM contracts")

or die(mysql_error());

Print "<table border=0 cellpadding=5 cellspacing=8>";

while($info = mysql_fetch_array( $data ))

{

Print "<tr>";

 

Print "<th>rep_name:</th> <td>".$info['rep_name'] . "</td> ";

Print "<th>division:</th> <td>".$info['division'] . " </td> ";

Print "<th>title:</th> <td>".$info['title'] . "</td> ";

Print "<th>  displayed text  </th> <td>".$info['title'] . "</td> ";

Print "<th>rep_number:</th> <td>".$info['rep_number'] . "</td> ";

Print "<th>description:</th> <td>".$info['description'] . "</td> ";

Print "<th>serial:</th> <td>".$info['serial'] . "</td> ";

Print "<th>tag:</th> <td>".$info['tag'] . "</td> ";

Print "<th>comments:</th> <td>".$info['comments'] . "</td> </tr>";

}

Print "</table>";

?>

 

i assumed that if i put:

Print "<th>field test:</th><td><input type="text" name="textfield" id="textfield" value=">".$info['comments'] . "/</td> </tr>";

somewhere before the </table>";, that it would have put the same data in the text field for me, but this wasn't the case.  it just said nothing, or i get an error

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/139984-searching-mysql/#findComment-732871
Share on other sites

Well, first off, does the query return what you expect?  Or is the 'comments' column always blank?

 

Secondly there are two main types of text "things".

Single line input

<input type="text" name="inputName" value="defaultValue" />

 

Textarea (multiline)

<textarea row="30" cols="50">Textarea default value</textarea>

Link to comment
https://forums.phpfreaks.com/topic/139984-searching-mysql/#findComment-733019
Share on other sites

yes...when that query is run, it successfully displays all the data in the table.  what i want it to do, is instead of putting that data in the cell of a table, to simply put it in a text box, so that it can be edited, then i will somehow use an update query to put in the new data.  on the comments field in particular, it will be a text area field but i need it all working first, then i can figure the little bits out

Link to comment
https://forums.phpfreaks.com/topic/139984-searching-mysql/#findComment-733180
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.