My code is very simple yet I cannot make a doPost request.
Here is my code below. I am using PHP 5.6.25 or PHP 7.0.10 im not sure. I just recently installed wampp
<?php
include('db.php');
if(isset($_REQUEST['btnsave']))
{
echo "Saves"; //This is not showing after clicking save
}
?>
<form action="" method="post">
<table>
<tr>
<td> Student </td>
<td><input type="text" name "txtsu_name"> </td>
</tr>
<td>Address</td>
<td><input type="text" name "txtaddress"> </td>
</tr>
<td>Status</td>
<td>
<select>
<option value ="1"> Active </option>
<option value ="0"> Suspend </option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Save" name"btnsave"> </td>
</tr>
</table>
</form>
You pretty missing all equal sign in name properties not just bntsave
name="anything"
So, please update all input fields.
and add name to select also:
<select name="isActive">
Related
I have an insert script and an update script, both separate. The script submits the data to the database, and adds or updates the database.
The scripts work within a table.
Part of the code:
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="750" border="0" cellspacing="1" cellpadding="5">
<tr>
<td width="100">Staff ID</td>
<td><input name="staff_id" type="text" id="staff_id">
<th>
Enter Desired ID
</th>
</td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="update" type="submit" id="update" value="Update">
</td>
</tr>
</table>
</form>
I want to add some options to the table, like a drop down menu.
How would I go about that?
Use the select tag, like so:
<select name="myselect">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Source: W3 Schools Select tag
The value selected will be available to your PHP script as $_POST['myselect'] or whatever name you choose for the select tag.
Also, as Devon mentioned in his comment, make sure your form is implemented properly and following PHP rules. If you're posting the form to the same page the form is on, you need to ensure its in a PHP file and not an HTML file. Also, change the "<?php $_PHP_SELF ?>" part to "<?php echo $_SERVER['PHP_SELF']; ?>" and ensure all the HTML in your file is either echoed or outside the <?php ?> tags
I have an UPDATE Query in MySQL
UPDATE users
SET fname='$fname',lname='$lname',username='$user',password='$pass',role='$role',status=$status
where id=$id
It works perfectly when I run it in Phpmyadmin by giving values manually but it gives me an error message when I use it in PHP Page.
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
The error is generated because I am doing echo mysql_error() I am getting values from the FORM like this;
$id=$_POST['id'];
$fname=$_POST['txt_fname'];
$lname=$_POST['txt_lname'];
$user=$_POST['txt_user'];
$pass=$_POST['txt_pass'];
$role=$_POST['txt_role'];
$status=$_POST['status'];
Frankly I sound like a stupid asking such a simple question, but I am stuck and need a bit of help. Thanks
FORM HTML
<div id="cuntable" style=" width:400px; margin:0 auto;">
<div class="CSSTableGenerator">
<form name="userform" action="updateuser.php" method="post">
<table >
<tr>
<td colspan="2"> Edit / Modify User Details </td>
</tr>
<tr>
<td>First Name </td>
<td><input type="text" name="txt_fname" placeholder="<?php echo $row[1];?>" /></td>
</tr>
<tr>
<td>Last Name </td>
<td><input type="text" name="txt_lname" placeholder="<?php echo $row[2];?>" /></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="txt_user" placeholder="<?php echo $row[3];?>"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="txt_pass" placeholder="<?php echo $row[4];?>" /></td>
</tr>
<tr>
<td>Username</td>
<td>
<select name="txt_role">
<option value=""> Select User Role </option>
<option value="user"> User </option>
<option value="admin">Administrator</option>
<option value="operator">Operator</option>
<option value="accountant">Accountant </option>
</select>
</td>
</tr>
<tr>
<td> Status </td>
<td>
<select name="status">
<option value="1"> Active </option>
<option value="0"> Suspended </option>
</select>
</td>
</tr>
</table>
</div>
<br />
<input type="submit" value=" ADD USER " />
<input type="hidden" name="txt_id" value="<?php echo $row[0];?>"
</form>
Would that be possible? I have a game and a custom site with a simple forum made for it. A player can have several characters. So when they make a post in the forum they get to select wich character to post with.
Now the question is, could I instead of having a submit button, that when they select a character the form gets sent?
<form action="/post" method="post">
<table>
<th colspan="3">Post New Topic</th>
<tr>
<td class="bold">Subject:</td>
<td><input type="text" name="subject"></td>
</tr>
<tr>
<td class="bold">Message:</td>
<td><textarea name="message"></textarea></td>
</tr>
<tr><td> </td><td>
<tr>
<td class="bold">Post Topic</td>
<td>
<select name="character">
<option value="" selected>Choose character</option>
<? foreach($db->query("SELECT id, name FROM character WHERE player_id = $pid ORDER BY name ASC") as $row) echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'?>
</select>
</td>
</tr>
</td>
</tr>
</table>
</form>
Instead of having a submit button, would It be possible that when you select a character, then post form?
To submit change on select
Change
<select name="character">
To
<select name="character" onchange="this.form.submit()">
I have created one plugin which inserts vehicles to DB table,displays vehicles at admin side from that table.One page is for settings of that plugin.admin side of plugin is mostly complete.now i want to display a form for taxi booking.when user submit that form in action page, i want to display google map with locations and distance with payment option.i googled it but not found best way.How sholud i create plugin front side?from where should I start?can anyone suggest me?
this is the form that i want to display at front side
<form name="book_form" id="book_form" action="" method="POST">
<!--<input type="hidden" name="action" value="tBM_taxibooking_save_booking" />-->
<table>
<tbody>
<tr>
<th>Select Location Points On Google Map</th>
<td>
<select name="location_points" id="location_points">
<option value="points">Points</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr>
<th>First Address Point</th>
<td><input type="text" name="first_point" id="first_point"></td>
</tr>
<tr>
<th>Second Address Point</th>
<td><input type="text" name="second_point" id="second_point"></td>
</tr>
<tr>
<th>Third Address Point</th>
<td><input type="text" name="third_point" id="third_point"></td>
</tr>
<tr>
<th>Fourth Address Point</th>
<td><input type="text" name="fourth_point" id="fourth_point"></td>
</tr>
<tr>
<th>Adult Seats</th>
<td>
<select name="adult" id="adult">
<option value="Adult Seats">Adult Seats</option>
<?php
$i=1;
for($i=1;$i<=10;$i++)
{ echo'<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
</td>
</tr>
<tr>
<th>Child Seats</th>
<td>
<select name="child" id="child">
<option value="Child Seats">Child Seats</option>
<?php
$i=1;
for($i=1;$i<=10;$i++)
{ echo'<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
</td>
</tr>
<tr>
<th>Suitcases</th>
<td>
<select name="suitcases" id="suitcases">
<option value="Suitcases">Suitcases</option>
<?php
$i=1;
for($i=1;$i<=50;$i++)
{ echo'<option value="'.$i.'">'.$i.'</option>'; }
?>
</select>
</td>
</tr>
<tr>
<th>Select Vehicle</th>
<td>
<select name="vehicle" id="vehicle">
<option value="vehicles">Select Vehicle</option>
<?php
while($row=mysql_fetch_assoc($results))
{
echo'<option value="'.$row['vechicle_id'].'">'.$row['vechicle_title'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>Date</th>
<td><input type="text" name="date" id="date"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Get Map & Distance" id="submit" name="submit"></td>
</tr>
</tbody>
</table>
</form>
I am trying to get the value of my input upon a click of the button.
I am able to get the value of text box but not for drop down list and number box (input type=number).
How should I go about doing it?
Below is my code:
<div class=accountMain>
<div align=left>
<table>
<tr>
<td>Product Code:</td>
<td>EX00001</td>
</tr>
<tr>
<td>Product Name:</td>
<td><input type=text name=productName value=$productName></td>
</tr>
<tr>
<td>Description:</td>
<td><input type=text name=productDesc value=$productDesc></td>
</tr>
<tr>
<td>Price: SGD$</td>
<td><input type=text name=unitPrice value=$unitPrice></td>
</tr>
<tr>
<td>Quantity Available:</td>
<td><input type=text name=qty value=$qty></td>
</tr>
<tr>
<td>Size <br>
(Only applicable for T-Shirt):</td>
<td><select>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select></td>
</tr>
<tr>
<td>Product Image:</td>
<td><input type=file name=imgfile></td>
</tr>
<tr>
<td>Category: Exclusive</td>
</tr>
<tr>
<td></td>
<td><input type=submit name=insert value=Insert></td>
</tr>
</table>
</div>
</td>
</tr>
</div>
echo("<tr><td></td>
<td></td>
<td><font style=title><b>In Stock : ".$row["qty"]."</b></br></br></br></br>
<b><form>Purchase Qty : <input type=number name=qty min=1 max=5></form></b></br></br>
</br></font></td>
</tr>");
echo("<tr><td></td>
<td></td>
<td><a href=shoppingbag.php><img src=images/addToCartBtn.png width=150></a></td></tr>");
your <select> requires a name attribute
Change the following:
<select>
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select>
To:
<select name="size">
<option value=N>NIL</option>
<option value=S>S</option>
<option value=M>M</option>
<option value=L>L</option>
<option value=XL>XL</option>
</select>
And get it using:
<?php $_POST["size"]; ?>
Since this is also marked under PHP, I presume you want to send these values to a PHP page?
If so, unless you are submitting the values dynamically (through script), you'll want to wrap the input and select elements in <form> opening and closing tags. Then you can set the method attribute (post,put,get,delete) and the action attribute (the path to the PHP page to process the values).
<form method="post" action="path-to/my-php-page.php">
...
</form>
HINT: The way your HTML is structured, you may want to wrap the whole of the innermost table with the form tag.