mysql 404 error - mysql

have the following code:
<?php
if (isset($_POST['submitted'])) {
$reqwidth = $_POST['reqwidth'];
$reqside = $_POST['reqside'];
$reqrad = $_POST['reqrad'];
$sqlinsert = "INSERT INTO tirelist (width, sidewall, radial) VALUES ('$reqwidth','$reqside', '$reqrad')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting new record');
}
$newrecord = "1 record added to database";
}
?>
<html>
<head>
<title>Request Tire Size</title>
</head>
<body>
<h1>Request Tire Size</h1>
<form method="post" action="insert-data.php">
<input type="hidden" name="submitted" value="true" />
<fieldset>
<legend>Request Tire</legend>
<label>Tire Width: <input type="text" name="reqwidth" /></label>
<label>Tire Sidewall: <input type="text" name="reqside" /></label>
<label>Tire Radial: <input type="text" name="reqrad" /></label>
</fieldset>
<br />
<input type="submit" value="Send Order Request" />
</form>
when i click send order request, I get a 404 error.
i noticed the page is called ~http://localhost/index.php?p=test2~, but when i click it redirects me to ~http://localhost/insert-data.php~
been trying for hours, wondering what i could do to fix it

Change
<form method="post" action="insert-data.php">
to have index.php?p=test2 instead.

In your form, you reference insert-data.php. Does that exist?
If you're trying to submit the form to the same file, you can try to use this:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">

Try this instead. form method="post" action="/insert-data.php"

Related

Extract form value from HTML and send it with HTML form POST

First, I am trying to extract the username that is stored in the page source when the different user loads the page that contains the below book now button. So username changes for each user. Second, when the book now is pressed I want to send that username as the corresponding value to name="user[name]".
I can successfully extract the username that is loaded in the page source but having trouble to send it as a variable username value through the html post method.
I know I am doing something or everything wrong :) so any help is much appreciated.
Best.
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Text value Property
</title>
</head>
<body style="text-align:center;">
<h2>Extracted User</h2>
<input type="text" name="Username" id="Username" autocomplete="off" value="yardicafe+emaartest#gmail.com" style="display:none;">
<p id="username"></p>
<!-- Script to return the Input Text value Property-->
<script>
let txt = document.getElementById("Username").value;
document.getElementById("username").innerHTML = txt;
</script>
<form method="post" action="https://www.supersaas.com/api/users">
<input type="hidden" name="account" value="vavevu"/>
<input type="hidden" name="id" value="1234fk"/> <!-- The user has ID 1234 on your server's database -->
<input type="text" name="user[name]" value="??????"/>
<input type="hidden" name="user[full_name]" value=""/>
<input type="hidden" name="user[email]" value="yardicafe+emaartest#gmail.com"/>
<input type="hidden" name="user[phone]" value=""/>
<input type="hidden" name="user[address]" value=""/>
<!-- you can add and remove fields on the "Access Control" screen -->
<input type="hidden" name="checksum" value="d14c0e6398ef11a9a34cf513060e45a8"/>
<input type="hidden" name="after" value="Scuba_Dalis"/>
<input type="submit" value="Book now"/>
</form>
</body>
</html>

how put put dynamically populated number into input value field

I have dynamically populated value coming from an external js file. The value is working just fine when I call it in the HTML page but I'm stuck on how to have an input field display this value.
Here is my HTML:
<form action="../mail.php" method="POST" class="location-form">
<div class="device-details">
<h2>Device: iPhone5</h2>
<h2>Repair Cost: <span id="result">0</span></h2>
</div>
<input name="device" type="hidden" id="device" value="iPhone5" maxlength="20">
<input name="cost" type="hidden" id="cost" value="" maxlength="20">
<div class="submit-btn">
<input type="submit" value="Submit Request" />
</div>
</form>
<script>
document.getElementById("result").innerHTML = localStorage.getItem("sum");
</script>
at the top, in the div "device-details", the h2 "repair cost" is populating the value just fine, no issues. But I cannot seem to populate the last input with this value.
<input name="cost" type="hidden" id="cost" value="(need the value here)" maxlength="20">
I need the value of the input field to mimic the value of the repair cost at the top in order to send that value to an email address.
I've tried inserting the following into the value and it didn't work
value="<span id='result'>0</span>"
I've tried creating a variable in php and then putting the variable into the value field, and it did not work
<?php
$my_var = '<span id="result">0</span>';
?>
value="<?php echo '$my_var'); ?>"
I've also tried:
value="<?php echo htmlspecialchars($my_var); ?>"
these last two just returned the actual HTML code
<span id="result"></span>
instead of the populated value.
Try this one.
<!DOCTYPE html>
<html>
<body onload="abc()">
<form action="../mail.php" method="POST" class="location-form">
<div class="device-details">
<h2>Device: iPhone5</h2>
<h2>Repair Cost: <span id="result">0</span></h2>
</div>
<input name="device" type="hidden" id="device" value="iPhone5" maxlength="20">
<input name="cost" type="hidden" id="cost" value="" maxlength="20">
<div class="submit-btn">
<input type="submit" value="Submit Request" />
</div>
</form>
<script>
function abc(){
document.getElementById("result").innerHTML=localStorage.getItem("sum");
document.getElementById("cost").value = localStorage.getItem("sum");
}
</script>
</body>
</html>

How to see if input contain some value?

I've some form like this:
<form action="#" method="post">
<input type="text" name="website" />
</form>
How I can find if user enter website with http:// or without? I want to show it in:
<a href="value from input">
Any suggestions how to validate this form and send it to database as right link like: http://website...?
You may use javascript to validate input.
function validate()
{
var input = document.getElementsByName("website")[0].value;
if(input.startsWith("http://")) {
alert("valid input");
return true;
}
alert("invalid input");
return false;
}
<form action="#" method="post" onsubmit="return validate()">
<input type="text" name="website" />
<input type="submit" />
</form>

add parameters to form url before submit

I need to add a path to a file to the form url before submitting. I created therefore a text field and want to add the text to the url without php.
can somebody help?
the existing code:
<form action="http://127.0.0.1:8080/WebService1/HTTPMethod_1?new_value=value" method="post">
<input type="text" value="" size="30" name="filename">
<input type="submit" name="submit" value="Submit" class="continue-button">
</form>
look into using hidden input fields. these allow you to send form data, but not necessarily show a form field.
for instance:
<script type="text/javascript">
function setFormAction() {
document.myForm.action = document.getElementById("url").value;
}
</script>
<form name="myForm" method="POST" action="default.php">
<input type="value" name="url" id="url" />
<input type="submit" name="submit" onclick="setFormAction();" />
</form>

How to GET data but preserve link array

Let's say I have index.php?couple=old and I want to GET new data (search all couples that are "old" but get new data) for example
<form action="index.php?couple=old" method="get">
<input type="text" name="search" >
<input type="submit" name="search_btn" />
</form>
And someone enters keyword "Smith" it should be index.php?couple=old&search=Smith
couple must be a variable to pass, otherwise PHP does not store it as part of $_GET.
You need:
<form action="index.php" method="get">
<input type="hidden" name="couple" value="old" />
<input type="text" name="search" />
<input type="submit" name="search_btn" />
</form>
maybe little bit more better solution (if you have couple of parameters you want to use).
<form action="index.php" method="get">
<?php foreach($_GET as $name=>$value):?>
<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />
<?php endforeach;?>
<input type="text" name="search" />
<input type="submit" name="search_btn" />
</form>