tracy Posted November 13, 2006 Share Posted November 13, 2006 I can insert data into mysql using php. When I try to insert data into mysql table using html form, won't work. Seems like server permissions issue. Any ideas? Thanks. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/ Share on other sites More sharing options...
stb74 Posted November 13, 2006 Share Posted November 13, 2006 Can you post some code. ;) Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124121 Share on other sites More sharing options...
jsladek Posted November 14, 2006 Share Posted November 14, 2006 If you can do it with php you are half way there. The html form you made should have something that looks like this [code]<form action="phpapp.php" method="POST">[/code]or[code]<form action="phpapp.php" method="GET">[/code]the action being the name of your php program that updates the database. The method is either POST or GET what ever one you choose you will have to use the corresponding php to get the value.$myvar = $_GET[myvar];$myvar2 = $_POST[myvar2];you can print these out to make sure they are working.print ("$myvar");Then you can edit the sql insert statement to use the values that the form sent instead of your hard coded data.hope that helps.... I've assumed a lot so, as previous poster mentioned, posting some code might do some good.Regards,John Sladek Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124260 Share on other sites More sharing options...
tracy Posted November 14, 2006 Author Share Posted November 14, 2006 Thanks for your replies...I'm rewriting and trying again...if that doesn't work I'll likely post the code and re-ask questions. Thanks again. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124436 Share on other sites More sharing options...
tracy Posted November 14, 2006 Author Share Posted November 14, 2006 Re-wrote, no success...I can write the php code to post to mysql database, no problem. That lets me know I'm connected fine to mysql. But when I use a form (html) and send that data to insert.php on the serverfor posting to mysql, it won't work.I'm new to php, but I have written several different test pages, even allowingphpmyadmin to help write the 'proper' insert code. It still doesn't work. Absolutely nothing. Any help is appreciated. If you know of an easier method using a form to allow web browsers to postto mysql database, feel free to tell me how if you know it works. If you tell me to do something to 'test' this, please remember I'm new to php. Thanks.THIS IS THE FORM PAGE CODE: (it simply has a form with two blanks: one is make as in automobile maker, one is model, as in automobile model)<html><head><title>Form</title></head><body><form action="insert.php" method="post">Make: <input type="text" value="" name="make"> Model: <input type="text" value="" name="model"> <input type="submit" value="Submit Query"> </form></body></html>THIS IS THE INSERT.PHP PAGE CODE: (CAPS JUST TO MAKE READING EASIER IN POST)<html><head><title>Form</title></head><body><form action="insert.php" method="post">Make: <input type="text" value="" name="make"> Model: <input type="text" value="" name="model"> <input type="submit" value="Submit Query"> </form></body></html>By the way, I have set the permissions for insert.php to 7 all the way across. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124471 Share on other sites More sharing options...
stb74 Posted November 14, 2006 Share Posted November 14, 2006 TraceyI maybe wrong but in the insert.php you should just have the code that is going to insert the data into the database.$submit = $_POST['submit'];if($submit){ $make= trim($_POST['make']); $model= trim($_POST['model']); //code to insert data to database.{ Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124495 Share on other sites More sharing options...
tracy Posted November 14, 2006 Author Share Posted November 14, 2006 you mean with no values set? maybe...I don't know either. could you explain what you mean more? thanks. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124503 Share on other sites More sharing options...
stb74 Posted November 14, 2006 Share Posted November 14, 2006 you will have say your index file.index.php<html><head><title>Form</title></head><body><form action="insert.php" method="post">Make:<input type="text" value="" name="[color=red]make[/color]"> Model:<input type="text" value="" name="[color=red]model[/color]"><input type="[color=red]submit[/color]" value="Submit Query"> </form></body></html>then the insert.php will have the details that your are using from the form (red). insert.php(database connection details)$submit = $_POST['submit'];if($submit){ $make= trim($_POST['make']); $model= trim($_POST['model']); mysql_query(" INSERT INTO database SET model = '$model', make = '$make' ",$dbconnect) or die(mysql_error());{ Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124513 Share on other sites More sharing options...
jsladek Posted November 14, 2006 Share Posted November 14, 2006 If you are having trouble take a look @ the program I am working on. @ www.iobe.net/proj or post the sql to create your table and I'll make a script for you to look at.Regards,John Sladek Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-124756 Share on other sites More sharing options...
fenway Posted November 15, 2006 Share Posted November 15, 2006 What do you currently have in your PHP script? The code you posted looks like HTML. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125117 Share on other sites More sharing options...
tracy Posted November 15, 2006 Author Share Posted November 15, 2006 Thank you but I feel I have gotten this problem resolved. I would like some code examples of how to output a ten column table from mysql using php. Or a tutorial site that really works. Thanks. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125158 Share on other sites More sharing options...
fenway Posted November 15, 2006 Share Posted November 15, 2006 That probably warrants a new thread, which whatever code you have thus far. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125251 Share on other sites More sharing options...
jsladek Posted November 15, 2006 Share Posted November 15, 2006 As previously offered, give me the sql to create the table and I'll give you some code...... Last offer.. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125277 Share on other sites More sharing options...
tracy Posted November 16, 2006 Author Share Posted November 16, 2006 It looks like this will be the mysql table creation:SQL query:CREATE TABLE `TestTable` (`stocknumber` VARCHAR( 8 ) NOT NULL ,`make` VARCHAR( 4 ) NOT NULL ,`model` VARCHAR( 20 ) NOT NULL ,`photo` VARCHAR( 30 ) NULL ,`five` VARCHAR( 10 ) NOT NULL ,`six` VARCHAR( 10 ) NOT NULL ,`seven` VARCHAR( 10 ) NOT NULL ,`eight` VARCHAR( 10 ) NOT NULL ,PRIMARY KEY ( `stocknumber` ) ) ENGINE = MYISAM ;Keep in mind that five, six, seven and eight are simply place holders. This entire table is just an example only. I am interested in learning how the code works and looks for a table like this, for example. Also, I'd like the photo to be a file, not a varchar but phpmyadmin won't allow that (at least not in a way I know)...Also: It would be great if the photo was automatically thumbnailed.Thanks. If I need to start a new thread for this I will...I checked out your site, Iobe and it is pretty cool. Good luck with that. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125536 Share on other sites More sharing options...
jsladek Posted November 17, 2006 Share Posted November 17, 2006 Now Were Talking...Your going to have to make two files...Create a fill called dataConn.php and put this code in it, make sure you change the database info to your info.[code]<?$hostname_dataConn = "localhost";$database_dataConn = "your_database_name";$username_dataConn = "username";$password_dataConn = "password";$dataConn = mysql_pconnect($hostname_dataConn, $username_dataConn, $password_dataConn) or trigger_error(mysql_error(),E_USER_ERROR);?>[/code]Create a file called [b]TestTable.php[/b] and put this in it.[code]<?# include ("secure.php");$pgflow = $_GET[pgflow];# Conditional statements to determine program flowswitch ($pgflow) { case 'addrecord': new_record(); break; case 'insertrecord': insert_record(); break; case 'deleterecord': delete_record(); break; case 'editrecord': edit_record(); break; case 'showchanges': show_changes(); break; case 'verified': update_database(); break; default: show_data();}#-------------------------------------------------------------------------------------------------------------------------------function delete_record(){//get the variable datakey//database infoinclude("dataConn.php"); $stocknumber = $_GET[stocknumber]; //print out variables so we can see if they made it #print ("$stocknumber <br>"); $make = $_GET[make]; //print out variables so we can see if they made it #print ("$make <br>"); $model = $_GET[model]; //print out variables so we can see if they made it #print ("$model <br>"); $photo = $_GET[photo]; //print out variables so we can see if they made it #print ("$photo <br>"); $five = $_GET[five]; //print out variables so we can see if they made it #print ("$five <br>"); $six = $_GET[six]; //print out variables so we can see if they made it #print ("$six <br>"); $seven = $_GET[seven]; //print out variables so we can see if they made it #print ("$seven <br>"); $eight = $_GET[eight]; //print out variables so we can see if they made it #print ("$eight <br>"); //connect to databasemysql_select_db($database_dataConn, $dataConn);// create sql$sql_delete_record ="DELETE FROM `TestTable` WHERE `stocknumber` ='$stocknumber' LIMIT 1 ; ";#print ("$sql_delete_record");// delete the old record if it exists$result = mysql_query($sql_delete_record); // close database mysql_close();//show records in tableshow_data(); } #-------------------------------------------------------------------------------------------------------------------------------function new_record(){ //title of page and open tableprint ("<br><br><center><h3> Add New Record in Table: TestTable</h3></center> <form action='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=insertrecord' method='POST' name='log_entry'> <TABLE align='center' border='1'>"); print("<tr><td>stocknumber</td><td><input name='stocknumber' type='text' id='stocknumber'><img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'></td></tr>"); print("<tr><td>make</td><td><input name='make' type='text' id='make'></td></tr>"); print("<tr><td>model</td><td><input name='model' type='text' id='model'></td></tr>"); print("<tr><td>photo</td><td><input name='photo' type='text' id='photo'></td></tr>"); print("<tr><td>five</td><td><input name='five' type='text' id='five'></td></tr>"); print("<tr><td>six</td><td><input name='six' type='text' id='six'></td></tr>"); print("<tr><td>seven</td><td><input name='seven' type='text' id='seven'></td></tr>"); print("<tr><td>eight</td><td><input name='eight' type='text' id='eight'></td></tr>"); //add submit and reset buttonsprint(" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> "); } #-------------------------------------------------------------------------------------------------------------------------------function insert_record(){include("dataConn.php");// Variables can be declared here $stocknumber = $_POST[stocknumber]; //print out variables so we can see if they made it #print ("$stocknumber <br>"); $make = $_POST[make]; //print out variables so we can see if they made it #print ("$make <br>"); $model = $_POST[model]; //print out variables so we can see if they made it #print ("$model <br>"); $photo = $_POST[photo]; //print out variables so we can see if they made it #print ("$photo <br>"); $five = $_POST[five]; //print out variables so we can see if they made it #print ("$five <br>"); $six = $_POST[six]; //print out variables so we can see if they made it #print ("$six <br>"); $seven = $_POST[seven]; //print out variables so we can see if they made it #print ("$seven <br>"); $eight = $_POST[eight]; //print out variables so we can see if they made it #print ("$eight <br>"); //connect to databasemysql_select_db($database_dataConn, $dataConn);//create sql$sql_insert = "INSERT INTO TestTable (stocknumber, make, model, photo, five, six, seven, eight) VALUES ('$stocknumber', '$make', '$model', '$photo', '$five', '$six', '$seven', '$eight')";#print("$sql_insert");// this statement actually executes the sql$result = mysql_query($sql_insert); # make this vaiable match the last one // close database mysql_close();//show records in tableshow_data();} #-------------------------------------------------------------------------------------------------------------------------------function edit_record(){ // this pulls in connection specific information to connect to the database include ("dataConn.php"); //get vars $stocknumber = $_GET[stocknumber]; //print out variables so we can see if they made it #print ("$stocknumber <br>"); $make = $_GET[make]; //print out variables so we can see if they made it #print ("$make <br>"); $model = $_GET[model]; //print out variables so we can see if they made it #print ("$model <br>"); $photo = $_GET[photo]; //print out variables so we can see if they made it #print ("$photo <br>"); $five = $_GET[five]; //print out variables so we can see if they made it #print ("$five <br>"); $six = $_GET[six]; //print out variables so we can see if they made it #print ("$six <br>"); $seven = $_GET[seven]; //print out variables so we can see if they made it #print ("$seven <br>"); $eight = $_GET[eight]; //print out variables so we can see if they made it #print ("$eight <br>"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql #$sql_table_data="SELECT * FROM TestTable WHERE stocknumber = '$datakey'"; $sql_table_data="SELECT * FROM TestTable WHERE `stocknumber` ='$stocknumber' LIMIT 1 ;"; #print("$sql_table_data"); // this statement actually executes the sql $result = mysql_query($sql_table_data); //access record info and build form while($row = mysql_fetch_array($result)) {//title of page and open tableprint ("<br><br><center><h3> Edit Log entry </h3></center> <form action='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=showchanges' method='POST' name='log_entry'> <TABLE border='1'>"); print("<tr><td>stocknumber</td><td><input name='stocknumber' type='text' id='stocknumber' value='$row[stocknumber]'><img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'></td></tr>"); print("<input name='orig_stocknumber' type='hidden' id='orig_stocknumber' value='$row[stocknumber]'>"); print("<tr><td>make</td><td><input name='make' type='text' id='make' value='$row[make]'></td></tr>"); print("<input name='orig_make' type='hidden' id='orig_make' value='$row[make]'>"); print("<tr><td>model</td><td><input name='model' type='text' id='model' value='$row[model]'></td></tr>"); print("<input name='orig_model' type='hidden' id='orig_model' value='$row[model]'>"); print("<tr><td>photo</td><td><input name='photo' type='text' id='photo' value='$row[photo]'></td></tr>"); print("<input name='orig_photo' type='hidden' id='orig_photo' value='$row[photo]'>"); print("<tr><td>five</td><td><input name='five' type='text' id='five' value='$row[five]'></td></tr>"); print("<input name='orig_five' type='hidden' id='orig_five' value='$row[five]'>"); print("<tr><td>six</td><td><input name='six' type='text' id='six' value='$row[six]'></td></tr>"); print("<input name='orig_six' type='hidden' id='orig_six' value='$row[six]'>"); print("<tr><td>seven</td><td><input name='seven' type='text' id='seven' value='$row[seven]'></td></tr>"); print("<input name='orig_seven' type='hidden' id='orig_seven' value='$row[seven]'>"); print("<tr><td>eight</td><td><input name='eight' type='text' id='eight' value='$row[eight]'></td></tr>"); print("<input name='orig_eight' type='hidden' id='orig_eight' value='$row[eight]'>"); //add submit and reset buttonsprint(" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> "); }} #-------------------------------------------------------------------------------------------------------------------------------function show_changes(){// Variables can be declared here $stocknumber = $_POST[stocknumber]; $orig_stocknumber = $_POST[orig_stocknumber]; //print out variables so we can see if they made it #print ("$stocknumber <br>"); #print ("$orig_stocknumber <br>"); $make = $_POST[make]; $orig_make = $_POST[orig_make]; //print out variables so we can see if they made it #print ("$make <br>"); #print ("$orig_make <br>"); $model = $_POST[model]; $orig_model = $_POST[orig_model]; //print out variables so we can see if they made it #print ("$model <br>"); #print ("$orig_model <br>"); $photo = $_POST[photo]; $orig_photo = $_POST[orig_photo]; //print out variables so we can see if they made it #print ("$photo <br>"); #print ("$orig_photo <br>"); $five = $_POST[five]; $orig_five = $_POST[orig_five]; //print out variables so we can see if they made it #print ("$five <br>"); #print ("$orig_five <br>"); $six = $_POST[six]; $orig_six = $_POST[orig_six]; //print out variables so we can see if they made it #print ("$six <br>"); #print ("$orig_six <br>"); $seven = $_POST[seven]; $orig_seven = $_POST[orig_seven]; //print out variables so we can see if they made it #print ("$seven <br>"); #print ("$orig_seven <br>"); $eight = $_POST[eight]; $orig_eight = $_POST[orig_eight]; //print out variables so we can see if they made it #print ("$eight <br>"); #print ("$orig_eight <br>"); // this pulls in connection specific information to connect to the database include ("dataConn.php"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql #$sql_user_data="SELECT * FROM TestTable WHERE stocknumber = '$stocknumber'"; $sql_user_data="SELECT * FROM TestTable WHERE `stocknumber` ='$orig_stocknumber' LIMIT 1 ;"; #print("$sql_user_data"); // this statement actually executes the sql $result = mysql_query($sql_user_data); //access record info and build form while($row = mysql_fetch_array($result)) {//title of page and open tableprint ("<br><br><center><h3> Please Verify Changed below and Submit to database if correct. </h3></center> <form action='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=verified' method='POST' name='log_entry'> <TABLE>"); if ($row[stocknumber]== $stocknumber) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>stocknumber</font></td><td><input name='xstocknumber' type='text' id='xstocknumber' value='$stocknumber' disabled></td></tr>");print("<input name='stocknumber' type='hidden' id='stocknumber' value='$stocknumber'>");print("<input name='orig_stocknumber' type='hidden' id='orig_stocknumber' value='$orig_stocknumber'>"); if ($row[make]== $make) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>make</font></td><td><input name='xmake' type='text' id='xmake' value='$make' disabled></td></tr>");print("<input name='make' type='hidden' id='make' value='$make'>");print("<input name='orig_make' type='hidden' id='orig_make' value='$orig_make'>"); if ($row[model]== $model) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>model</font></td><td><input name='xmodel' type='text' id='xmodel' value='$model' disabled></td></tr>");print("<input name='model' type='hidden' id='model' value='$model'>");print("<input name='orig_model' type='hidden' id='orig_model' value='$orig_model'>"); if ($row[photo]== $photo) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>photo</font></td><td><input name='xphoto' type='text' id='xphoto' value='$photo' disabled></td></tr>");print("<input name='photo' type='hidden' id='photo' value='$photo'>");print("<input name='orig_photo' type='hidden' id='orig_photo' value='$orig_photo'>"); if ($row[five]== $five) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>five</font></td><td><input name='xfive' type='text' id='xfive' value='$five' disabled></td></tr>");print("<input name='five' type='hidden' id='five' value='$five'>");print("<input name='orig_five' type='hidden' id='orig_five' value='$orig_five'>"); if ($row[six]== $six) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>six</font></td><td><input name='xsix' type='text' id='xsix' value='$six' disabled></td></tr>");print("<input name='six' type='hidden' id='six' value='$six'>");print("<input name='orig_six' type='hidden' id='orig_six' value='$orig_six'>"); if ($row[seven]== $seven) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>seven</font></td><td><input name='xseven' type='text' id='xseven' value='$seven' disabled></td></tr>");print("<input name='seven' type='hidden' id='seven' value='$seven'>");print("<input name='orig_seven' type='hidden' id='orig_seven' value='$orig_seven'>"); if ($row[eight]== $eight) {$fontcolor = 'black';} else {$fontcolor = 'red';}print("<tr><td><font color=$fontcolor>eight</font></td><td><input name='xeight' type='text' id='xeight' value='$eight' disabled></td></tr>");print("<input name='eight' type='hidden' id='eight' value='$eight'>");print("<input name='orig_eight' type='hidden' id='orig_eight' value='$orig_eight'>"); //add submit and reset buttonsprint(" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> "); } #end while($row = mysql_fetch_array($result)) exit;} #end function show_changes(){ #-------------------------------------------------------------------------------------------------------------------------------function update_database(){include("dataConn.php");// Variables can be declared here $stocknumber = $_POST[stocknumber]; $orig_stocknumber = $_POST[orig_stocknumber]; //print out variables so we can see if they made it #print ("$stocknumber <br>"); #print ("$orig_stocknumber <br>"); $make = $_POST[make]; $orig_make = $_POST[orig_make]; //print out variables so we can see if they made it #print ("$make <br>"); #print ("$orig_make <br>"); $model = $_POST[model]; $orig_model = $_POST[orig_model]; //print out variables so we can see if they made it #print ("$model <br>"); #print ("$orig_model <br>"); $photo = $_POST[photo]; $orig_photo = $_POST[orig_photo]; //print out variables so we can see if they made it #print ("$photo <br>"); #print ("$orig_photo <br>"); $five = $_POST[five]; $orig_five = $_POST[orig_five]; //print out variables so we can see if they made it #print ("$five <br>"); #print ("$orig_five <br>"); $six = $_POST[six]; $orig_six = $_POST[orig_six]; //print out variables so we can see if they made it #print ("$six <br>"); #print ("$orig_six <br>"); $seven = $_POST[seven]; $orig_seven = $_POST[orig_seven]; //print out variables so we can see if they made it #print ("$seven <br>"); #print ("$orig_seven <br>"); $eight = $_POST[eight]; $orig_eight = $_POST[orig_eight]; //print out variables so we can see if they made it #print ("$eight <br>"); #print ("$orig_eight <br>"); //connect to databasemysql_select_db($database_dataConn, $dataConn);//create sql#$sql_update="UPDATE `TestTable` SET `stocknumber` = '$stocknumber',`make` = '$make',`model` = '$model',`photo` = '$photo',`five` = '$five',`six` = '$six',`seven` = '$seven',`eight` = '$eight' WHERE `stocknumber` =$stocknumber LIMIT 1"; #$sql_update="UPDATE `TestTable` SET `stocknumber` = '$stocknumber',`make` = '$make',`model` = '$model',`photo` = '$photo',`five` = '$five',`six` = '$six',`seven` = '$seven',`eight` = '$eight' WHERE `stocknumber` ='$stocknumber' LIMIT 1 ;";$sql_update="UPDATE `TestTable` SET `stocknumber` = '$stocknumber',`make` = '$make',`model` = '$model',`photo` = '$photo',`five` = '$five',`six` = '$six',`seven` = '$seven',`eight` = '$eight' WHERE `stocknumber` ='$orig_stocknumber' LIMIT 1 ;";#print("$sql_update");// this statement actually executes the sql$result = mysql_query($sql_update); # make this vaiable match the last one // close database mysql_close();//show records in tableshow_data(); exit;} function show_data(){ // Title of page print "<center><h3>TestTable</h3></center>"; // this pulls in connection specific information to connect to the database include ("dataConn.php"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql $sql_user_data="SELECT * FROM TestTable"; // this statement actually executes the sql $result = mysql_query($sql_user_data); //Create table print("<table border='1' align='center'><tr>"); //add edit column header print("<th>Edit"); //create column headers based on feilds from table print("<th>stocknumber"); print("<th>make"); print("<th>model"); print("<th>photo"); print("<th>five"); print("<th>six"); print("<th>seven"); print("<th>eight"); // add the delete column header print("<th>Delete</tr>"); //now we iterate through the results of the SQL Query while($row = mysql_fetch_array($result)) { //create a new row in the table print("<tr>"); // add an edit icon for the row #print("<td align='center'><a href='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=editrecord&datakey=$row[stocknumber]'><img src='images/edit_icon.png' width='16' height='16' border='0' alt='edit'></a></td>"); print("<td align='center'><a href='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=editrecord&stocknumber=$row[stocknumber]'><img src='images/edit_icon.png' width='16' height='16' border='0' alt='edit'></a></td>"); print("<td>$row[stocknumber] </td>");print("<td>$row[make] </td>");print("<td>$row[model] </td>");print("<td>$row[photo] </td>");print("<td>$row[five] </td>");print("<td>$row[six] </td>");print("<td>$row[seven] </td>");print("<td>$row[eight] </td>"); // add a delete icon for the row #print("<td align='center'><a href='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=deleterecord&datakey=$row[stocknumber]'><img src='images/delete_icon.png' width='16' height='16' border='0' alt='edit'></a></td>"); print("<td align='center'><a href='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=deleterecord&stocknumber=$row[stocknumber]'><img src='images/delete_icon.png' width='16' height='16' border='0' alt='edit'></a></td>"); print("</tr>"); } #end while( = mysql_fetch_array()) // add a final row to the end of the table that has a link to add a record print("<tr><td align='right'><a href='".$_SERVER['PHP_SELF']."?pg=TestTable&pgflow=addrecord'>New Record</a><td></tr>"); // finally we close the table print("</table>");}?>[/code]Let me know how it works for you...-John SladekPS. Here are the images that are missing, just save them in a directory called image, much like you see them. http://www.iobe.net/proj/images/edit_icon.pnghttp://www.iobe.net/proj/images/delete_icon.pnghttp://www.iobe.net/proj/images/primarykey_icon.pnghttp://www.iobe.net/proj/images/autoincrement_icon.png Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125881 Share on other sites More sharing options...
jsladek Posted November 17, 2006 Share Posted November 17, 2006 As far as the photo goes, store the name of the image in the database and then when you query the image name from the database just build the SRC tag based on the name.print("<img src=\"$row[image]\">"-John Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-125886 Share on other sites More sharing options...
tracy Posted November 20, 2006 Author Share Posted November 20, 2006 John-Sorry for the late reply. I appreciate the effort.I think maybe I'm missing something. Are these files supposed to be linked from somewhere, like a delete button or add/edit button? Kinda new to this, so sorry...I can't get it to work. When I open these php files (dataConn.php or testtable.php) the browser shows a blank page. I entered some test data in mysql but still blank pages.I also don't understand the picture part. The last entry of yours about the SRC file...Thanks. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127439 Share on other sites More sharing options...
jsladek Posted November 20, 2006 Share Posted November 20, 2006 Hi Just upload both those pages to your server that is running php make sure they are in the same directory. the dataConn.php you will have to edit and put in the connection information specific to your database. Change this stuff...$hostname_dataConn = "localhost";$database_dataConn = "your_database_name";$username_dataConn = "username";$password_dataConn = "password";The link to the images are so you have them. The script will run without having them it will just be missing images. I'd like to see you get this working so let me know.-John Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127657 Share on other sites More sharing options...
tracy Posted November 21, 2006 Author Share Posted November 21, 2006 Thanks. I have one other question, related to this. When I output this table to the browser, I'm finding it hard to get a good tutorial or instructions on making one of the columns a check box. That way, if the box is checked and the delete or edit button is clicked, that file that is checked will be opened for editing or deleted, whichever is the case. I think I know the premise of it, but the actual writing of the exact phrase to get the true/false statement from the checkbox cell is the problem for me. Any thoughts on where I can get this info? I'm not asking for you to write it for me, just the info. Thanks for all your help. It is appreciated. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127679 Share on other sites More sharing options...
jsladek Posted November 21, 2006 Share Posted November 21, 2006 That script I gave you should handle all the basic functions. Here, take a look @ it in action. http://www.iobe.net/proj/workshop/TestTable.php-John Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127706 Share on other sites More sharing options...
tracy Posted November 21, 2006 Author Share Posted November 21, 2006 Man, that's pretty cool. Almost exactly what I've been fretting about all day!Thanks.Was this autogenerated?Thanks again. Amazing. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127713 Share on other sites More sharing options...
tracy Posted November 21, 2006 Author Share Posted November 21, 2006 I've loaded them up to test them, with proper changes. No luck. Still blank pages, no errors. Pretty impressive looking on your site, wish I could test on mine. I'll work on it. Again thanks very much. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127716 Share on other sites More sharing options...
jsladek Posted November 21, 2006 Share Posted November 21, 2006 Yes, it was auto generated based on the sql you provided me with. I used a program I wrote to create that file. It basically asks for infomation to log into your database and then creates a php script like that for each table in your database. The program can be downloaded free if your interested, http://www.iobe.net/proj/ . There are a bunch of things that that script does not do (it's a work in progress) but it is a quick way to get started, especially if you have a lot of tables in your database. One of the good things about it is it should be pretty easy to go into and see what is going on. Regards,John Sladek Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127717 Share on other sites More sharing options...
tracy Posted November 21, 2006 Author Share Posted November 21, 2006 Cool. Thanks. Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127718 Share on other sites More sharing options...
jsladek Posted November 21, 2006 Share Posted November 21, 2006 Hi, Sorry it's not working for you. I've only had a few servers to test it on. I'm suprised that you are not getting a blank page and no errors. What do you get when you do a view source of the webpage? I'd like to help you get this working, it's kinda like test and tune for my program.Regards,John SladekAIM: johnnysladek Link to comment https://forums.phpfreaks.com/topic/27132-html-form-for-mysql-using-php/#findComment-127722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.