Jump to content

mdmartiny

Members
  • Posts

    188
  • Joined

  • Last visited

Everything posted by mdmartiny

  1. Now it is giving me double the fields on the page http://www.webpagescreenshot.info/img/379433-420201284323AM
  2. This is just the test database that I am working with. Once this is done I will not know what the column names are going to be. The person that this is for will make all of the fields and names themselves. I am just writing the php code
  3. Could I put it so that each value is put into a variable of some kind so I can insert it into a form field for editing? Also when I Echo all it says is Array
  4. I am in the process of writing code for a dynamic form. I have the part of the form written for information to be entered. I am now trying to write code for the modification of the information in the table. I know that I want to get the table data my doing a MySql Select and putting that information into an array. I am not very familiar with arrays and have spent some time looking for a solution online with no solution. When I print_r the results I get what I want but when I do anything else I get Array. What I am actually looking to do is make it so that the table data is in another variable this is the section of code that I am working with. $mod_form = "<form name='insert_table' id='insert_table' action='ad_add.php' method='post' enctype='multipart/form-data'> <fieldset> <legend>table information</legend> <input name='table' TYPE='hidden' VALUE='" . $table . "' />"; $mod_sql = "SELECT * FROM $table WHERE id = '$id'"; $mod_sql_result = mysql_query($mod_sql); $allowed_ext = array('jpg', 'jpeg', 'png', 'gif'); $input_array = array(); while ($row = mysql_fetch_array($mod_sql_result, MYSQL_NUM)) { $input_array[] = $row; } foreach ($input_array as $input => $data) { print_r($data); } while ($i < mysql_num_fields($mod_sql_result)) { $header = str_replace("_", " ", (mysql_field_name($mod_sql_result, $i))); $name = mysql_field_name($mod_sql_result, $i); (mysql_field_name($mod_sql_result, $i) == 'image' ? $mod_form .= "<p>" . $header . ": <input name='" . $name . "' id='" . $name . "' type='file' /></p>" : $mod_form .= "<p>" . $header . ": <input name='" . $name . "' id='" . $name . "' type='text' value='" . $input . "'/></p>"); $i++; } $mod_form .= " <p> <input type='submit' name='submit_mod' id='submit_mod' /> </p> </fieldset> </form> "; echo $mod_form;
  5. I keep getting this error code and not sure why This is the line of code that it reference to. $file_ext = strtolower(end(explode(".", $file_name))); Can someone please help me
  6. I did some playing around and I got this to work $table = $_POST['table']; $fieldnamesquery = "SELECT * FROM $table"; $fieldnamesquery_result = mysql_query($fieldnamesquery); $i = 3; while ($i < mysql_num_fields($fieldnamesquery_result)) { $post_info = htmlspecialchars(mysql_real_escape_string($_POST[mysql_field_name($fieldnamesquery_result, $i)])); echo "<p>".$post_info."</p>"; $i++; } Now all I need to do is figure out how to get the post information into individual variables
  7. Will that also give me the values that are entered into the text boxes?
  8. $tablecolumn = "<form name='insert_table' id='insert_table' action='get_database.php' method='post' enctype='multipart/form-data'> <fieldset> <legend>table information</legend>"; $fieldnamesquery = "SELECT * FROM $table"; $fieldnamesquery_result = mysql_query($fieldnamesquery); $i = 3; while ($i < mysql_num_fields($fieldnamesquery_result)) { $header = str_replace("_"," ",(mysql_field_name($fieldnamesquery_result, $i))); $name = mysql_field_name($fieldnamesquery_result, $i); (mysql_field_name($fieldnamesquery_result, $i) == 'image' ? $tablecolumn .= "<p>" . $header . ": <input name='" . $name . "' id='" . $name . "' type='file' /></p>" : $tablecolumn .= "<p>" . $header . ": <input name='" . $name . "' id='" . $name . "' type='text' /></p>"); $i++; } $tablecolumn .= " <p> <input type='submit' name='submit_info' id='submit_info' /> </p> </fieldset> </form> "; echo $tablecolumn;
  9. I need to get the information that is entered into the dynamic form field out of it. I have the form created just need to get the information inputted out.
  10. Not for this step yet... I am trying to search online for examples and such and I am finding nothing yet. I just have never done anything like this before with PHP. I have always had control over the form and new exactly what was being put in them.
  11. How would I do that this is something new to me?
  12. This is something that I am working on for someone that wants to have a classified ad section on there website and want to be able to do all of the work themselves. That way every time that they want to ad something to it they do not have to come to me or some one else. They do not have direct access to the database just the ability to add TimeBomb The script that I have written so far allows a person to fill out 2 form fields one for a table name and another for how many columns they want in the table. This then allows them to fill in the column names and and attributes and all of that. What I am doing now is writing a script that goes in and pulls the names of the columns from the table that the user has created and make a form to allow them to fill out for the individual fields. What they do is pick the table that they want to use from a drop down menu which then creates a form for them to fill out The example that you showed was pretty accurate. What I need to figure out now is since I will not be making the tables myself and the owner will be. How do I get the information that they have entered into the form. When I do not know the names of the columns they are creating. Meaning I will not know the name of the form fields when they are entering the information. I do not know what the names of the columns or the form fields names are going to be. column name one: [text box name=column name one] column name two [text box name=column name two]
  13. I have some code that pulls the field names from a table to create form form submitting information. I am trying to write this code so that someone who knows nothing about databases, tables and MySQL can make a table of their own by filling in a few text boxes. Now what I was wondering is since I have no idea what people are going to name their table columns so I won't know what information Post information I will be sending to the next step of the process. Is there a way with PHP that will allow me to get unknown post variables? If there is how would I do that?
  14. What I am trying to do is get a field that will allow me to upload an image. I have it doing that for me but it is also giving me an extra field for the same name. How do I remove the extra field that I do not need? $i = 2; while ($i < mysql_num_fields($fieldnamesquery_result)) { $meta = mysql_fetch_field($fieldnamesquery_result, $i); $meta2 = mysql_fetch_field($fieldnamesquery_result, $i); $meta2->name = str_replace("_", " ", $meta2->name); if ($meta->name == 'image') { $tablecolumn .= "<p>" . $meta2->name . ":<input TYPE='file' name='" . $meta->name . "' id='" . $meta->name . "'/></p>"; } $tablecolumn .= "<p>" . $meta2->name . ":<input type='text' name='" . $meta->name . "' id='" . $meta->name . "'/></p>"; $i++; } I have added a screenshot of what I am talking about
  15. Now I have another question. I want to have a field that would allow someone to upload an image to the server. Is there a way using this method that I could change the one field type to file. By doing something like if($meta == 'image') { $tablecolumn .= "<p>" . $meta->name . ":<input TYPE='file' name='" . $meta->name . "' id='" . $meta->name . "'/></p>"; }
  16. I am using a script that get the field names from a table in a database. It works, however, when I try to remove the underscore(_) from the name. I get an error message. This is the section of code that I am using it with $i = 2; while ($i < mysql_num_fields($fieldnamesquery_result)) { $meta = mysql_fetch_field($fieldnamesquery_result, $i); // This is the line of code that I am having problems with $meta.name = str_replace("_", " ", $meta.name); if (!$meta) { echo "No information available"; } $tablecolumn .= "<p>" . $meta->name . ":<input type='text' name='" . $meta->name . "' id='" . $meta->name . "'/></p>"; $i++;
  17. I hope that this is in the right forum. I am in the process of writing a block of code that will allow the use of chained select boxes. I am pretty sure that it is a AJAX issue. When I select from the first select box. The second select box does not fill with anything. It gives me an empty select box. Here is the code that I am using. Anyone have any suggestions on what to do? <?php $host = 'localhost'; $username = 'root'; $dbname = 'classified'; $dbpassword = ''; $connection = mysql_connect($host, $username, $dbpassword); $db = mysql_select_db($dbname, $connection); if (!$connection) { die('Could not make a connection to MySql Database' . mysql_error()); } if (!$db) { die('Could not connect to DB $dbname' . mysql_error()); } function showCategory() { $select_sql = "SELECT * FROM category ORDER BY cat_id"; $cat_select = mysql_query($select_sql); $category = "<option value='0'>Select a Category......</option>"; while ($row = mysql_fetch_array($cat_select)) { $category .= "<option value='" . $row['cat_id'] . "'>" . $row['category'] . "</option>\n "; } return $category; } function subCategory() { $sub_sql = "Select * From sub_cat where cat_id='" . $_POST['id'] . "'"; $sub_select = mysql_query($sub_sql); $sub = "<option value='0'>Select a Sub Category</option>"; while ($row = mysql_fetch_array($sub_select)) { $sub .= "<option value='" . $row['sub_cat_id'] . "'>" . $row['sub_cat'] . "</option>\n "; } return $sub; echo $_POST['id']; } ?> <!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("select#sub_category").attr("disabled","disabled"); $("select#category").change(function(){ $("select#sub_category").attr("disabled","disabled"); $("select#sub_category").html("<option>wait...</option>"); var id = $("select#category option:selected").attr('value'); $.post("<?php echo $_SERVER['PHP_SELF']; ?>", {id:id}, function(data){ $("select#sub_category").removeAttr("disabled"); $("select#sub_category").html(data); }); }); }); </script> </head> <body> <br/><form action="" method="post" name="cars"> <select id="category" name="category"> <?php $select_sql = "SELECT * FROM category ORDER BY cat_id"; $cat_select = mysql_query($select_sql); $category = "<option value='0'>Category</option>"; while ($row = mysql_fetch_array($cat_select)) { $category .= "<option value='" . $row['cat_id'] . "'>" . $row['category'] . "</option>\n "; } echo $category; ?> </select> <select id="sub_category" name="sub_category"> <?php $sub_sql = "Select * From sub_cat where cat_id='" . $_POST['id'] . "'"; $sub_select = mysql_query($sub_sql); $sub = "<option value='0'>Sub Category</option>"; while ($row = mysql_fetch_array($sub_select)) { $sub .= "<option value='" . $row['sub_cat_id'] . "'>" . $row['sub_cat'] . "</option>\n "; } echo $sub; echo $sub_sql; ?> </select> <input type="submit" name="fire" value="GO"/> </form> </body> </html>
  18. Hello Everyone, I am working on a project where I have to go in and grab the names of the fields in a table. I got it to work and for it to show me the field names but it also displays a lot more than what I would like for it to do. I keep getting the following error. It is repeated over my screen like 15 times. This is the section of code that it is referring to. Line 44 is $tablecolumn = "<form name='insert_table' id='insert_table' action='get_database.php' method='post' > <fieldset> <legend>table information</legend>"; for ($table_field = 2; $table_field < $fieldnamesquery_result; $table_field++) { $tablecolumn .= "<p>" . mysql_field_name($fieldnamesquery_result, $table_field) . "<input type='text' name='" . mysql_field_name($fieldnamesquery_result, $table_field) . "' id='" . mysql_field_name($fieldnamesquery_result, $table_field) . "'/>"; <-----This is line 44 } $tablecolumn .= " <p> <input type='submit' name='submit_info' id='submit_info' /> </p> </fieldset> </form> "; echo $tablecolumn;
  19. Hello Everyone, I am working on a project I pull the field names from the database. I am trying to remove the underscore (_) when the field name is displayed. Does anyone know how I would do that? Here is the code that I am working with $i = 0; while ($i < mysql_num_fields($fieldnamesquery_result)) { $meta = mysql_fetch_field($fieldnamesquery_result, $i); if (!$meta) { echo "No information available"; } $meta = str_replace("_", " ", $meta); $tablecolumn .= "<p>" . $meta->name . ":<input type='text' name='" . $meta->name . "' id='" . $meta->name . "' /></p>"; $i++;
  20. I seem that after I actually took the time to look at it. Was in a rush this morning.
  21. This is the output from the code Array ( [table_name] => mike [field_name] => Array ( [0] => hggghghbwthw [1] => test [2] => test_field ) [field_type] => Array ( [0] => int [1] => char [2] => varchar ) [field_length] => Array ( [0] => 5 [1] => 50 [2] => 50 ) [primary] => Array ( [0] => y ) [auto_increment] => Array ( [0] => y ) )
  22. This is the output from the code Array ( [table_name] => mike [field_name] => Array ( [0] => hggghghbwthw [1] => test [2] => test_field ) [field_type] => Array ( [0] => int [1] => char [2] => varchar ) [field_length] => Array ( [0] => 5 [1] => 50 [2] => 50 ) [primary] => Array ( [0] => y ) [auto_increment] => Array ( [0] => y ) )
  23. I find the issue to be with the $_POST(auto_increment) and $_POST(primary). It adds the null and primary factor. Then when it moves onto yhe next grips in the array that is when I get the error.
  24. Hello my fellow PHP developers. I am writing a script that will allow for someone to create a table in their database but just filling in a few text boxes. I am coming across the problem Notice: Undefined offset: 1. I know what it means and all but I just do not know how to fix it. So if someone would be so kind to help me I would appreciate it. <?php $table_name = $_POST['table_name']; $create_sql = "create table $table_name ("; for ($i = 0; $i < count($_POST['field_name']); $i++) { $create_sql .= $_POST['field_name'][$i] . " " . $_POST['field_type'][$i]; if($_POST['auto_increment'][$i] == "y" ) { $additional = "NOT NULL auto_increment"; } else { $additional = ""; } if($_POST['primary'][$i] == "y"){ $additional .= ", primary key(".$_POST['field_name'][$i].")"; } else { $additional = ""; } if ($_POST['field_length'][$i] != "") { $create_sql .= "(" . $_POST['field_length'][$i] . ") $additional,"; } else { $create_sql .= " $additional ,"; } } $create_sql = substr($create_sql, 0, -1); $create_sql .= ")"; $create_res = mysql_query($create_sql); if ($create_res) { $sql_column = "SHOW COLUMNS FROM $table_name"; $res_column = mysql_query($sql_column); echo "<h3>the following database has been created <strong>". $table_name. "</strong></h3>"; if (mysql_num_rows($res_column)) { echo "<table class='db-table' cellpadding='5' cellspacing='5'>"; echo "<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default<th>Extra</th></tr>"; while ($row = mysql_fetch_row($res_column)) { echo "<tr>"; foreach ($row as $key => $value) { echo "<td>". $value ."</td>"; } echo "</tr>"; } echo "</table><br />"; } echo "<a href='create_table.php'>Create</a> another table"; } else { echo "<h3>There was an error" . mysql_error()."</h3>"; } ?>
×
×
  • 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.