-
Posts
188 -
Joined
-
Last visited
Posts posted by mdmartiny
-
-
Now it is giving me double the fields on the page
-
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
-
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
-
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;
-
I keep getting this error code and not sure why
Strict Standards: Only variables should be passed by reference inThis is the line of code that it reference to.
$file_ext = strtolower(end(explode(".", $file_name)));
Can someone please help me
-
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
-
Will that also give me the values that are entered into the text boxes?
-
$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;
-
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.
-
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.
-
How would I do that this is something new to me?
-
Although why you would want to let people, who have no idea how to actualy use a database, anywhere near one baffles me.
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
Example:
Let's say your user see's a form to help them design a table...
Table Name: [text box name=name]
Table Stuff: [text box name=stuff]
You can set the name of the text box elements, and then, when the form is submitted, you can look at $_POST['name'] and $_POST['stuff'] to see what the user put into the text box.
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]
-
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?
-
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
-
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>"; }
-
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.
Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\CMS\admin\includes\get_table.php on line 76This 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++;
-
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>
-
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.
Warning: mysql_field_name() [function.mysql-field-name]: Field 5 is invalid for MySQL result index 7 in C:\xampp\htdocs\CMS\admin\includes\get_table.php on line 44This is the section of code that it is referring to. Line 44 is
$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) . "'/>";$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;
-
Thank You
-
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++;
-
I seem that after I actually took the time to look at it. Was in a rush this morning.
-
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 ) )
-
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
)
)
-
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.
Getting mysql data into an array
in PHP Coding Help
Posted
It is still giving me the double fields