I have a tracking no. 1Z981Y1ED342132798 . But when I search query directly in phpmyadmin it shows the result but when I run the following through php the result will not show. I am sending the field value in GET method during submit my search form. My code is as follows
<?php
$test_qry = mysql_query(Select * from `table_name` where `tracking_no` like '%".$_REQUEST['srch']."%');
?>
<form name="search_form" action="" method="get">
<td>Search:</td>
<td>
<input type="text" name="srch" value="<?php echo $_REQUEST['srch']; ?>"> </td>
<td>
<input type="submit" name="Search" value="Search"> </td>
</form>
Very weird issue, tried a lot, any help will be appreciated. Thanks!
There is a convention error in your code
like '%".$_REQUEST['srch']."%')
Try replacing $_REQUEST['srch'] with $srch variable.
$srch = $_REQUEST['srch']
Related
I get the id trough the link, this is no problem because there is a table "id" in the database, but i also want to pass the value from input field "quantity" trough the link.. Thank you in advance!
<?php
require_once 'database.php';
$id = $_GET['id'];
$query = sprintf("SELECT * FROM products WHERE id = '%s'", $id);
$result = mysql_query($query);
while( $row = mysql_fetch_assoc($result)) {
echo '<table>';
?>
<form action="add.php?id=<?php echo $row['id'];?>" method="POST">
<fieldset>
<legend> ADD quantity </legend>
Quantity: <br>
<input type="text" name="quantity" size="15"> </input> </br>
<input type="submit" value="Add" />
</fieldset>
</form>
?>
You are submitting a post request, so you should be able to get it like this :
$quantity = $_POST['quantity'];
If you want to send multiple GET values you can separate them via & (&).
You can do this:
link
Note: is better (standard) to use & instead of &. like this:
link
Use the $_POST var, as it follows:
$quantity=$_POST['quantity'];
But please, don't put the $id var and the $quantity directly on the sql query it will lead to mysql-injection attacks. Use PHP's PDO class or sanitized your input with proper function (like mysqli::real_escape_string()). And please not that mysql_* functions are deprecated since php 5.5 and removed since php 7.0.
you will have to use this:
<form action="add.php?id=<?php echo $row['id'];?>" method="GET">
<fieldset>
<legend> ADD quantity </legend>
Quantity: <br>
<input type="text" name="quantity" size="15"> </input> </br>
<input type="submit" value="Add" />
</fieldset>
</form>
And Get data from:
$_GET['quantity']
I have a problem in my project that i cant fix yet.
Im working with MySQL - PHP and everything is working OK but when I try to open "php/consult.php?consult=add" using the form below.
<form action="php/consult.php?consult=add" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
</form>
My browser doesn't change the URL to "php/consult.php?consult=add". Instead it shows only "php/consult.php", what have I done wrong?
Thanks for your answers and your time, and sorry for my english (it isn't too good xD).
This works if submitted - you don't need to add the query string - if it were an <a href="... then you would need the full query string for the url:
<form action="php/test.htm" method="get">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" required/>
</td>
<input type="submit" name="submit" value="Submit" />
</form>
This gives me my url + /php/test.htm?codecosult=ghrth&submit=Submit
ghrth was what I had typed.
If you are submitting it with a script leave the query string off and let the "GET" method deal with it - script here is in the head.
<script language="javascript">function submit_this(){this.form.submit();}</script>
</head>
<body>
<form name="form" id="form" action="php/test.htm" method="GET">
<td>Instruccion SQL:</td>
<td>
<input type="text" name="codecosult" id="codecosult" required/>
</td>
<div onClick="submit_this();">Submit</div>
This gives me my url + test.htm?codecosult=dfthwrth
dfthwrth was what I had typed.
This also works, though the <a href="...'s hrefis modified here by the keypress event each time a key is pressed (may not work in all browsers):
<input type="text" name="codecosult" onKeyPress="ahreff.href='php/test.htm?'+this.value;" required/>
Click Here
This might be of interest - a dropdown will pass its value in the same way:
dropdown menu doesn't function - it will now!
i want to get the text box value which i selected from array of text boxes..
My code is like this:
Here am displaying the data on the browser from DB..
<?php
foreach($dataDecoded['categories'] as $key => $value)
{
?>
<tr>
<td><?php echo $value['CategoryName'];?></td>
<td>
<input type="text" name="categoryId[]" id="categoryId" value="<?php echo $value['CategoryId']?>">
<input type="text" name="categoryName[]" id="categoryName" value="<?php echo $value['CategoryName']?>">
<input type="submit" name="create" id="create" value="create">
</td>
</tr>
<?php
}
?>
The data will be displayed like:
categoryId1 categoryName1 <Create Button>
categoryId2 categoryName2 <Create Button>
categoryId3 categoryName3 <Create Button>
and so on like this..
Now, suppose When i click on Create Button of CategoryName2, i want to get the categoryId and categoryName of only CategoryName2..
Am using this code:
if(isset($_POST['create']) && $_POST['create']=="create")
{
$cat_id[]=$_POST['categoryId'];
$cat_name[]=$_POST['categoryName'];
}
But with this, am getting all the categoryId and categoryName into the array.. how to get only the selected textbox value..
I want to do it using only PHP and not with JavaScript / JQuery... Am a bit new to PHP... Can someone help me / give me a suggestion about how to do it...
Thanks in advance.
Wrap each one in its own form:
<td>
<form method="POST" action="somePage.php">
<input type="text" name="categoryId" value="<?php echo $value['CategoryId']?>">
<input type="text" name="categoryName" value="<?php echo $value['CategoryName']?>">
<input type="submit" name="create" value="create">
</form>
</td>
Since the content being posted in this case is just these two values, then that's the entire scope of a single form post. So each one is logically/semantically its own form. (There's no rule that says a page can have only one form. Unless you're ever using ASP.NET WebForms, which is a lie.)
Note also that I removed your id attributes. Multiple elements can't have the same id, that's invalid HTML and any behavior as a result becomes undefined.
Maybe I don't understand English as well as I thought. I need some help. I read the other posts but I am still not able to send variables to another page using POST instead of GET. Please help me with this example:
I have two pages. The first one has a query (Users). Then I make a table with the results and using the following code I can send user id to another page where I can edit some information.
First page:
<td><div align="center">
<a href="Users_modify.php?id=<?php echo $row_Users['id'];?>">
<img src="Icons/info-icon.png" width="20" height="20"></a></div></td>
Second page:
$colname_recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_recordset1 = $_GET['id'];}
and after this I can use the variable to make a query.
With respect I ask you for a sample of the first page statement in order to be able to use POST on the second page. Thank you for your time!
You can only use $_POST on a form.
If it is associated in a link, you can use $_GET or you can use $_REQUEST to get the query string.
You'll fill $_POST by using a form:
<form action="…" method="post">
<input type="hidden" value="$id">
…
<input type="submit" value="Save">
</form>
posting it by form
<form action="second page url" method="post">
<input type="hidden" name="id" value="$id">
…
<input type="submit" value="Post">
</form>
First Page
<form method="post" action="page2.php">
<input type="hidden" name="idField" value="<?php echo $id; ?>" />
<input type="submit"/>
</form>
Second Page
<p>
<?php
echo $_POST["idField"];
?>
</p>
I am trying to display a database input in a textbox for editing. I cant seem to get it working?!
The page links from a forum post edit button. Firstly, I don't know how to get the database info for that particular field to be displayed and also I don't understand how to make sure the post that the user clicks to edit is the post that is displayed.
My code looks like this
<?php
#data preparation for the query
$id=$_GET['id'];
# selects title and description fields from database
$sql = "SELECT a_answer FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<h3>Edit</h3> <form action="save_edit.php" enctype="multipart/form-data" method="post" name="myForm" />
<table>
<tr>
<td><b>Answer</b></td>
<td><textarea cols="80%" rows="10" name="a_answer"><?php echo $row['$a_answer']; ?></textarea></td>
</tr>
</table> <input name="id" type="hidden" value="<? echo $id; ?>">
<input name="enter" type="submit" value="Edit"> </form>
<?php mysql_close(); ?>
confirm if the question id is integer or varchar in your database. if it is integer then remove the single quotes. ( just a hint may it helps you. ).
One more thing you do not need to put the multipart in your form if you not uploading any files another tip form me.
Two errors in your code: Firstly, you are using row instead of rows. The second is the dollar sign you 're using when accessing the field. The code below should work, provided your database query is correct.
<?php
#data preparation for the query
$id=$_GET['id'];
# selects title and description fields from database
$sql = "SELECT a_answer FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<h3>Edit</h3> <form action="save_edit.php" enctype="multipart/form-data" method="post" name="myForm" />
<table>
<tr>
<td><b>Answer</b></td>
<td><textarea cols="80%" rows="10" name="a_answer"><?php echo $rows['a_answer']; ?></textarea></td>
</tr>
</table> <input name="id" type="hidden" value="<? echo $id; ?>">
<input name="enter" type="submit" value="Edit"> </form>
<?php mysql_close(); ?>
Another way to go about things would be to use prepared statements, and let PHP and MySQL quess the correct type. Here can be found a simple example.