<td height="25" align="center" valign="middle"><input type='text' name='day2' id='datepicker2' value='Day 2' readonly="readonly" maxlength="50" style="color:#999999"/></td>
</tr>
<tr>
<td height="25" align="center" valign="middle"><input type='text' name='day3' id='datepicker3' value='Day 3' readonly="readonly" maxlength="50" style="color:#999999"/></td>
</tr>
<tr>
<td height="25" align="center" valign="middle"><input type='text' name='day4' id='datepicker4' value='Day 4' readonly="readonly" maxlength="50" style="color:#999999"/></td>
</tr>
<tr>
<td height="25" align="center" valign="middle"><input type='text' name='day5' id='datepicker5' value='Day 5' readonly="readonly" maxlength="50" style="color:#999999"/></td>
The values Day 4, Day 5, Day 6 etc. are enetring into database. How I block these from entering into database?
How I block these from entering into database?
It sounds like you have some system that takes all your values and posts them to the database... But we can not answer your question without seeing the php code.
Forms have little to nothing to do with mysql insert commands. They just receive information from the browser.
It isn't the most popular method but, you can use the placeholder attribute to still display the default value you want to display and leave the value attribute blank. I do this with a jQuery date picker application.
<input type="text" name="day4" id="datepicker4" value="" placeholder="Day 4" readonly maxlength="50" style="color:#999999"/>
This gives a grayed out effect while still showing the user what should go there. When a value is entered the value attribute takes over.
Also, I have just corrected the attribute tags from single quotation marks to double as well as the readonly attribute.
Related
I have created a blog using PHP that submits a form into a MySQL databse. It works perfectly. What i want to know is how to get it to recognise when i've pressed enter to create a new line or to record a ' without getting a MySQL error. Basically i want to turn a normal submission form into a submission form like is used on this website.
<tr>
<td>Blog Title:</td>
<td><input type="text" id="edt" name="BlogTitle"></td>
</tr>
<tr>
<td>Blog Content:</td>
<td><textarea name="BlogCont" cols="50" rows="10" id="edt"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="Name" value="<?=$_SESSION['Name']?>"></td>
<td><input type="submit" id="but" value="Post"></td>
</tr>
Any help would be appreciated.
For new lines with enter use nl2br (manual), for apostrophe you have to escape it with mysql_real_escape_string (manual).
So I am at my wits end. Out of the more complex issues, this is the one that has just stumped me. I'm not sure if it's a HTML issue or a PHP issue, anymore. I've tried everything I could think up, and just nothing.
Ok so I need to pull a specific name out of a dynamically created table, the Weapon’s Name to be exact.
So User clicks the button “Delete weapon” and that weapon would be deleted. The query is fine; my issue is getting this name. If there was just one weapon and this wasn’t dynamic I would just go for the specific field name. That’s PHP 101.
This is the loop it's being pulled from:
while ( $weapons = mysql_fetch_array($data)) {
echo '
<table width="780" border="1">
<tr>
<td colspan="2">weapon</td>
<td>AttackBonus</td>
<td>crit</td>
</tr>
<tr>
<td colspan="2">
<input type="text" name="weaponName'.$i.'" id="weaponName'.$i.'" size="10" value="'.$weapons["weaponsName"].'" />
<input type="hidden" name="weaponName" value="'.$weapons["weaponsName"].'"/>
</td>
<td>
<input type="text" name="attackBonus'.$i.'" id="attackBonus'.$i.'" size="10" value='.$weapons["weaponsAttackBonus"].' />
</td>
<td>
<input type="text" name="crit'.$i.'" id="crit'.$i.'" size="10" value='.$weapons["weaponsCritical"].' />
</td>
</tr>
<tr>
<td>type</td>
<td>range</td>
<td>ammunition</td>
<td>damage</td>
</tr>
<tr>
<td>
<input type="text" name="type'.$i.'" id="type'.$i.'" size="10" value='.$weapons["weaponsType"].' />
</td>
<td>
<input type="text" name="range'.$i.'" id="range'.$i.'" size="10" value='.$weapons["weaponsRange"].' />
</td>
<td>
<input type="text" name="ammunition'.$i.'" id="ammunition'.$i.'" size="10" value='.$weapons["weaponsAmmunition"].' />
</td>
<td>
<input type="text" name="damage'.$i.'" id="damage'.$i.'" size="10" value='.$weapons["weaponsDamaage"].' />
</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" formaction="include/deleteweapon.php" formmethod="post" value="Delete Weapon"/>
</td>
</tr>
</table>
';
$i++;}
It’s probably something small, that’s how it’s always been my issue. I’ve tried a few different while loops. I’ve tried if statements with issets($_post[“weaponName0”], etc. I just don’t know.
Edit:
So I'm not very good with explaining what I need. The loop to display the information is fine, and yes the button needs to be there.
(I don't have enough rep to up load an image so here is the link)
http://farm9.staticflickr.com/8391/8468562067_0cd4158e35_b.jpg
This is what it looks like. I can not get the value of the weapon name. The output is fine here, it's when I need to delete that specific weapon, that I'm having issue with. I need that name. This is why I'm not sure if it's the HTML or the PHP. The button has to be iterated or whats the point? The mySQL is fine, that was the easy part.
I have an idea of what I can do, but in my opinion it's bad design and I think I would just have the same problem. I could add a check box for these fields to delete, and it'll be deleted after you try to save the character.
I'm not 100% sure I understand your problem, I believe in your HTML, you should do something like:
<input type="hidden" name="weaponName[<?php print $i; ?>]" value="The Name" />
In your PHP, you should be able to access the name given an index:
$index = 1; // Some arbitrary index
$weapon_name = $_POST['weaponName'][$index];
Alternatively, and what I would do: In your form's action, specify an id:
<form action="delete.php?id=<?php print $weaponId; ?>" action="post">
Then in your PHP, you can do:
$id = $_GET['id']; // This is the weapon ID
Then you can just pull the name directly from the database, using the ID.
It looks like you have a single delete button for each iteration of the loop. You should be able to set the name for deletion just as you set it as a label.
<input type=hidden name=weaponsName value=".$weapons['weaponsName'].">
<input type=submit ...>
$weaponsName = $_POST['weaponsName'];
You are using mysql_fetch_array instead of mysql_fetch_assoc, so you should use the field index, like this:
$weapons["weaponsName"] // This is wrong
$weapons[0] // This is the right approach
PS: You should not use the mysql extension....go for the mysqli or PDO ;)
Saludos.
Got a form table below which contains form elements such as text inputs and validation messages:
$error_user = (!empty($errors['user']))?$errors['user']:"";
$error_email = (!empty($errors['email']))?$errors['email']:"";
echo "<form action='./forgotpass.php' method='post'>
<table>
<tr>
<td></td>
<td id='errormsg'>$errormsg</td>
</tr>
<tr>
<td>Username</td>
<td><input type='text' name='user' value='$user'/><br/>".$error_user."</td>
</tr>
<tr>
<td>Email</td>
<td><input type='text' name='email' value='$email'/><br/>".$error_email."</td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='resetbtn' value='Reset Password' /></td>
</tr>
</table>
</form>";
Now I am displaying each validation message below the relevant text inputs but the problem is the allignment. If I display the message underneath the text input as I am doing now, then the text input moves up a little bit to occupy the space below for the validation message, meaning the text input is not leveled with its label e.g Email text input not aligned with this label when validation appears.
My question is that how can I get the label and text inputs to stay align with each other when the validation message appears underneath
If you use this:
echo "<form action='./forgotpass.php' method='post'>
<table>
<tr>
<td></td>
<td id='errormsg'>$errormsg</td>
</tr>
<tr>
<td valign='top'>Username</td>
<td valign='top'><input type='text' name='user' value='$user'/><br/>Username Error</td>
</tr>
<tr>
<td valign='top'>Email</td>
<td valign='top'><input type='text' name='email' value='$email'/><br/>Email Error</td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='resetbtn' value='Reset Password' /></td>
</tr>
</table>
</form>";
You should get the look you want. The reason the message distorts the row is because it is enlarging one cell so the cell with the labels in are being aligned vertically in the middle. Notice the valign:top? That will push everything to the top of the cell so everything in the row on the first line, will be in line.
See this JSFiddle
Add style="vertical-align: top" to all TD tags. You may also need to add a little padding to the label cells, to align them properly with the content in the input boxes.
create another <td> element for displaying error message like this edit
<tr>
<td>Username</td>
<td><input type='text' name='user' value='$user'/></td>
<td>".$error_user."</td>
</tr>
also, besides everything mentioned, and if it doesn't screw you anything else, i would try adding a space in the empty td's like this:
<td> </td>
<td id='errormsg'>$errormsg</td>
it will make things equally distributed
I have a function allowing members to update their personal details when they have logged in, the update page features a form the user will fill in and when the submit button is pressed the deatils are updated. This works fine, I am wanting to display the users current details in the appropriate text filed in the form e.g. the firstname text field will have value "James" and the user can delete this to enter "jim". Is it something to do with adding a value to the form field? My form is shown below.
<tr>
<td width="78">Firstname</td>
<td width="6">:</td>
<td width="294"><input name="firstname" type="text" id="firstname"></td>
</tr>
<tr>
<td width="78">Surname</td>
<td width="6">:</td>
<td width="294"><input name="surname" type="text" id="surname"></td>
</tr>
Any help is much appreciated
Print value inside the text box.
<input type="text" value="<?php echo $someValue; ?>" />
echo '<input type="text" value="'. $someValue .'" />';
OR
<input type="text" value="<?php echo $someValue; ?>" />
Both obviously require that you be in a .php file, and that $someValue contains the appropriate value to set. Watch out for the double quotes around the value, too. Without them, any spaces will break the value when it's rendered.
Hi
I have an evaluation form with more than 300 fields, where there are several parts. i don't want to make 300 rows in mytable.Can someone give me a method how to save my data as it need to be easy to retrive to make some stats.
Thanks.
Edit:
Something like that with lots of differnt parts
<form action="" method="post" id="OKF" name="OKF" autocomplete="off">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="25%" class="tableft"><strong>Date </strong></td>
<td width="25%"><input name="controldate" type="number" id="controldate" /></td>
<td width="25%"><strong>Start Time</strong></td>
<td><input type="text" name="startime" id="startime" class="required"/></td>
</tr>
<tr>
<td class="tableft"><strong>Controller</strong></td>
<td><input type="text" name="controller" id="controller" /></td>
<td><strong>End Time</strong></td>
<td><input type="text" name="endtime" id="endtime" class="required"/></td>
</tr>
<tr>
<td class="tableft"><strong>Hotel Name</strong></td>
<td><input type="text" name="otelname" id="otelname" class="required"/></td>
<td><strong>Company Name</strong></td>
<td><input type="text" name="compres" id="compres" class="required"/></td>
</tr>
<tr>
<td class="tableft"><strong>No Stars</strong></td>
<td><input type="text" name="stars" id="stars" class="required"/></td>
<td><strong>No Room</strong></td>
<td><input type="text" name="roomnum" id="roomnum" class="required"/></td>
</tr>
</table>
<br>
<h1>Part 1</h1>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="40%" class="tabtopmid">Question</td>
<td width="4%" class="tabtopmid"></td>
<td width="17%" class="tabtopmid"><strong>Point</strong></td>
<td width="37%" class="tabtopmid"><strong>Comment</strong></td>
</tr>
<tr>
<td>Question 1</td>
<td>20</td>
<td><input name="puan_1" id="puan_1" type="text"></td>
<td><textarea name="cmt_1" id="cmt_1"></textarea></td>
</tr>
<tr>
<td>Question 2</td>
<td>20</td>
<td><input name="puan_2" id="puan_2" type="text"/></td>
<td><textarea name="cmt_2" id="cmt_2"></textarea></td>
</tr>
<tr>
<td>Question 3</td>
<td>20</td>
<td><input name="puan_3" id="puan_3" type="text"/></td>
<td><textarea name="cmt_3" id="cmt_3"></textarea></td>
</tr>
<tr>
<td>Question 4</td>
<td>20</td>
<td><input name="puan_4" id="puan_4" type="text"/></td>
<td><textarea name="cmt_4" id="cmt_4"></textarea></td>
</tr>
<tr>
<td>Question 5</td>
<td>20</td>
<td><input name="puan_5" id="puan_5" type="text"/></td>
<td><textarea name="cmt_5" id="cmt_5"></textarea></td>
</tr>
</table>
<input name="submit" type="submit" id="submit" value="Submit" alt="Submit" title="Submit">
depending on your fields would recommend you to make more than one table
form
- id
1
n
questions
- id
- type
- value
- label
- form_id
and then you could store the answer of the users in a third table
easier to you would be names like formname[foobar], formname[foobar_1] and so on
then you are able to do something like:
$sql = "INSERT INTO answers (name, value) VALUES ";
foreach ($_POST['formname'] as $key => $value) {
$sql .= "('".$key."', '".$value."'),";
}
$sql = substr($sql, 0, -1).";";
mysql_query($sql);
please note, this is only an example.. no security, no valiation, nothing
So this is a hotel registration form , i take it.
Well, the Questions should definitely be a separate table. Then, i guess, there should be a table for Reservations ( containing hotel_id, room_id, customer_id, date, additional info about reservation ) .. then a Customers table and Hotels table, and Rooms table ... and maybe few more.
It's impossible to tell, without knowing the the entire list of fields.
I never worked with 300 columns in one table. My suggestion is use JSON or someother serialized data technic for columns. Grouping related fields can save time in any case.
Recently used;
column = value (variable1:value1-variable2:value2-var3:val3)
adv_room_numbers(text) = "Room:2-Bedroom:3-Kitchen:1-Dining Room:1,etc..room:1,etc..room:1,etc..room:1" // I can use explode() to extract fields
adv_online(enum) = "active"
adv_contact(text) = "Name:Name Surname-Tel:65465-City:Cityname-Address:address details"
Is it all coming from one big form? If so, it might just make sense to put all the data into one array, serialise it, and log it to a file. Then analyse the data after with a more specialist tool.
If you do want to put it into a database, you need to spend some time breaking out the schema - I'm sure people would help but at the moment, the definition is too vague to say anything meaningful.
It might help you to use a framework to map between the front end form and the database. Symfony is excellent at form generation - you just write the files into a YAML file and run a command.