|
I have 2 pages. 1st is the index.php that have 3 fields. 2 of them should saved to sql and its works fine and the 3rd one should pass the value to 2nd screen. I have JS file. I success doing these 2 operations successfuly but in seperated projects. When I am trying to make them together there are mistakes. I want to know How can I implement those 2 parts together please.
index.php
<pre><!DOCTYPE html>
<html>
<head>
<title>PHP MySQL Insert Tutorial</title>
<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
</head>
<body>
<form action='insert.php' method='post' id='myform' >
<p>
<input type='text' name='username' placeholder='user name' id='username' />
</p>
<p>
<input type='text' name='password' placeholder='password' id='password' />
</p>
<p>
<input id = "minus" type="text" name="main" value="<?php echo $num1; ?>" autocomplete="off">
</p>
<button id='insert'>Insert</button>
<p id='result'></p>
</form>
</body>
</html>
2nd.php
<?php
session_start();
if(isset($_POST['Submit']))
{
$num_2 = "";
$pass_num = $_POST['main'];
}
?>
<h2>minus</h2>
<br>
<form method="post" action="index.php">
<input type="text" name="state" value="<?php echo $num_2;?>" autocomplete="off">
<br>
<input type="hidden" name="rrr" value="<?php echo $pass_num;?>" autocomplete="off">
<br>
<br>
<input name="Submit" type="submit" value="Submit">
</form>
jS
$('#myform').submit(function(){
return false;
});
$('#insert').click(function(){
$.post(
$('#myform').attr('action'),
$('#myform :input').serializeArray(),
function(result){
$('#result').php(result);
}
);
});
modified 21-Jul-20 7:04am.
|
|
|
|
|
One thing I see right away: your 2nd.php form submit's to index.php but the values you pass from the form are never looked for in index.php.
So what's the point of that interaction?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
I created an Asp.Net Core Web API project. By default it comes with a "WeatherForecastController". I run the app at "https://localhost:44368/weatherforecast", a browser opens, and I get JSON back. All's fine.
Next, I added a controller called Test with code to call my DAL (See code below) and when I try "[https://localhost:44368/Test/GetAll] I get a Not Found. . What's the right way to call these methods on the controller? Is there some routing config that I need?
[ApiController]
[Route("[controller]")]
public class TestController : _ControllerBase
{
[HttpPost]
public int Add(TestDataEntity entity)
{
try
{
IRepository repo = GetRepository<TestDataRepository>();
return repo.Add(entity);
}
catch (Exception e)
{
throw;
}
}
[HttpDelete]
public void Delete(int id)
{
try
{
IRepository repo = GetRepository<TestDataRepository>();
repo.Delete(id);
}
catch (Exception e)
{
throw;
}
}
[HttpGet]
public TestDataEntity Get(int id)
{
try
{
IRepository repo = GetRepository<TestDataRepository>();
return repo.Get(id);
}
catch (Exception e)
{
throw;
}
}
[HttpGet]
public List<TestDataEntity> GetAll()
{
try
{
IRepository repo = GetRepository<TestDataRepository>();
return repo.GetMany();
}
catch (Exception e)
{
throw;
}
}
[HttpPost]
public void Update(TestDataEntity entity)
{
try
{
IRepository repo = GetRepository<TestDataRepository>();
repo.Update(entity);
}
catch (Exception e)
{
throw;
}
}
}
When I run this
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I've just tried this simpler version:
[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{
private static readonly string[] Values =
{
"Foo", "Bar", "Baz"
};
[HttpGet]
public IEnumerable<string> GetAll() => Summaries;
[HttpGet]
public string Get(int index) => Summaries[index];
} With that, I get an ambiguous match exception:
The request matched multiple endpoints. Matches:
TestCoreApi.Controllers.TestController.GetAll (TestCoreApi)
TestCoreApi.Controllers.TestController.Get (TestCoreApi) After changing the route on the Get method, it works as expected:
[HttpGet("{id:int}")]
public string Get(int index) => Summaries[index];
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am making php page.
In my php page, exit() function calls in serveral places and i declared sqlite3::open() function in first line of php.
Closing db before each exit function makes code complex.
So i don't close sqlite db at the end is ok?
Please help me
|
|
|
|
|
Member 14490964 wrote: In my php page, exit() function calls in serveral places You need to redesign your page.
|
|
|
|
|
|
Detail of what? We have no idea what your code does or why. It is up tp you to review it and figure out why you have all these exit calls, and why you are leaving open databases if the code terminates.
|
|
|
|
|
please sir, i am new in web application development. and i am in desprate need of PHP and MSQLI codes that can link my php page to a form in excel sheet and at after the form is filled, once i click the send button it sends the information to database.
|
|
|
|
|
|
Database data export is a familiar operation for many of us. phpMyAdmin is the go to choice for a database client in PHP. It provides database administration tools and also allows exporting the data. The exported data can be in various formats like SQL, CSV as selected.
Please let me know if below code is useful. I used it for adding same functionality on my website here.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Here is another good reference https://phppot.com/php/database-data-export-to-excel-file-using-php/
|
|
|
|
|
I am using xampp apache server.
The server domain is registered in cloudflare.
All works well.
But cloudflare ip is saved in access.log
So I have done googling about restore real ip of cloudflare.
But I only found the way in linux apache server.
How can i resotore real ip in access.log of xampp server registered in cloudflare.
|
|
|
|
|
Message Removed
modified 14-Jul-20 15:02pm.
|
|
|
|
|
Hi all,
I did a small database and web page to help me control the time I work for my customers...
Today I've thought on adding graph capabilities to perform reports.
Given this thing is coded using PHP, some jquery and used a MySQL database, what would you recommend me?
I'm searching for a good looking free graph library.
Thank you all!
|
|
|
|
|
I want to redirect from http to https using express framework.
It is my code and it works properly, but i am not sure is it right way to redirect from
http to https. Anybody knows is my solution right?
var fs = require('fs');
var https = require('https');
var config = require( ".\\config\\config.json");
var folder = __dirname + '\\SSLCERT\\';
var fkey = folder + 'privatekey.key';
var fcert = folder + 'certificate.crt';
var privateKey = fs.readFileSync(fkey, 'utf8');
var certificate = fs.readFileSync(fcert, 'utf8');
var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
var https_mode = false;
app.get('/', function (req, res) {
if (https_mode == false) {
res.redirect('https://localhost:' + config.port_https);
https_mode = true;
}
else{
res.send('Hello World!!!');
https_mode = false;
}
})
app.listen(config.port_http,()=> {
console.log('listening on ' + config.port_http);
});
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(config.port_https, () => {
console.log('listening on ' + config.port_https) });
|
|
|
|
|
Hi All,
I have a thousand odd points of data, (city,state) describing the countries top high schools. I was wondering what an effective way to graph this would be.
I have the data in a PDF, so I'm currently working on scraping that into .CSV form.
Does the city/state location need to by long/latitude? I see a number of tools out there, just wondering what is the easiest to get started on a project like this.
My background is Linux Admin, some HTML and of course bash scripting. I would like to learn how to do this using golang if possible.
Thansk!
|
|
|
|
|
I think other people can give better answers but if all goes to hell, you can try with Python. Python has extensive libraries to help you in this regard.
|
|
|
|
|
if an airline booking tickets website is hard to do ?
and what is best website idea i can do it for a project?
|
|
|
|
|
moustafa arabi wrote: airline booking tickets website is hard to do ? Extremely unless you are only doing this as a learning exercise that will never go into production. It can be fascinating winkling out all the nuances required for passenger booking.
I found the best training method (besides working through a book or two) was to pick a hobby you or a friend knows and build a solution based on that. Then you have the domain knowledge available to you.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I don’t know if this question belongs to this forum.
I'm developing a website with vb.net web application using visual studio 2015 where a client is able to download a pdf file and I have considered 2 approaches as follows.
Dim sqlcom As New SqlCommand("select bookcontent,bookname from books where bookn=" & Page.RouteData.Values("bookn").ToString & "", conn)
Dim da As New SqlDataAdapter(sqlcom)
Dim ds As New DataTable
da.Fill(ds)
Dim filename As String = ds.Rows(0)("bookcontent").ToString
Dim fff As String = ds.Rows(0)("bookname").ToString
Dim fileInfo As FileInfo = New FileInfo(filename)
If fileInfo.Exists Then
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "Application/pdf"
Response.ContentType = "application/ms-word"
Response.AddHeader("Content-Disposition", "inline; filename=""" & ds.Rows(0)("bookname").ToString & ".pdf" & """")
Response.AddHeader("Content-Length", fileInfo.Length.ToString())
Response.TransmitFile(filename)
Response.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
I'm having trouble with the first approach above because when downloaded start the website
Hang on until pdf file fully downloaded to client PC ,this is bad since website will be access
By thousand of users every day,so I want to make the download process asynchronous.
I use the .NET Framework WebClient class in the second approach:
Dim Client As New WebClient
Dim weburl As String= ....here is some procedure to get url
Client.DownloadFileAsync(New Uri(weburl), @"c:\myfile.pdf")
But the problem here is that a path must be set and I want clients to get the file in the default download folder according to the Internet browser they use and the download process not appear through browser user can't see downloading file progress .
I will very much appreciate any comment that points me in the direction to solve this issue.
Thanks a lot.
|
|
|
|
|
The second approach isn't going to work, your code is running on the server so when you download to c:\myfile.pdf it will download from the url to that path on the server and not the client's machine. It might appear to work when running the site locally, but that is only because the client and server are the same machine, when you host it remotely it'll stop working.
You'll need to stick with the first method but I wouldn't worry about it, just let IIS deal with the threading for you.
|
|
|
|
|
Amer Amer wrote:
Dim sqlcom As New SqlCommand("select bookcontent,bookname from books where bookn=" & Page.RouteData.Values("bookn").ToString & "", conn) Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Dim ds As New DataTable
Using sqlcom As New SqlCommand("select bookcontent,bookname from books where bookn = @bookn", conn)
sqlcom.Parameters.AddWithValue("@bookn", Page.RouteData.Values("bookn"))
Dim da As New SqlDataAdapter(sqlcom)
da.Fill(ds)
End Using
If ds.Rows.Count <> 0 Then
Dim filename As String = ds.Rows(0).Field(Of String)("bookcontent")
Dim fff As String = ds.Rows(0).Field(Of String)("bookname")
Dim fileInfo As FileInfo = New FileInfo(filename)
If fileInfo.Exists Then
Response.Clear()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "inline; filename=""" & fff & ".pdf" & """")
Response.AddHeader("Content-Length", fileInfo.Length.ToString())
Response.TransmitFile(filename)
Response.Flush()
Context.ApplicationInstance.CompleteRequest()
Return
End If
End If Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
As already mentioned, this is the only way to send the file to the user. IIS is pretty good at handling file transfers; requests from other users shouldn't be blocked whilst the file is downloading.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank for the support Its work, your code very useful and your advice is valuable.
modified 10-Jun-20 17:14pm.
|
|
|
|
|
I'm trying to decide here.
If I create an account on my Web App, using my email address me@mywebapp.com, and then later I'm offered the opportunity to login to my Web App using Google SignIn; because I just wrote the code to add this feature, and elected to use it.
A:
Should I use googleUser's email address (me@mywebapp.com) as the account name, because I want to create an account to represent the user. But id the email is in use already, just update the login, and use the googleUser token to authenticate again, to AuthGuard.
Pro's:
I can login using either method to the same account.
Con's:
I can't really think of any, which is why I'm asking. Am I over looking something, perhaps someone's experience can say ... "No don't do that because ...".
B:
Use googleUsers first and last name, and sort of create a new account name from it that is unique.
Pro's:
I can't think of any
Con's:
EBay did this to me, and I ended up with 2 EBay accounts; didn't realize it for months, and really wish I just had the one.
Sounds like a dumb question, but wanted to ask before going into production mode.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
In the company intranet where I work there is a web-based documentation system that you can access through a regular web browser (Chrome, Firefox, Edge, etc). I need to write an application (in C#) that interfaces to this documentation system and I'm currently working on making sure that I can programmatically supply the user name and password correctly. When accessing the documentation system through a web browser, I always have to supply the user name and password once after re-boot and then I never have to type it again until next re-boot. I've come to the conclusion that the user name and password are being stored somewhere in the computer, but they are not stored in the browsers themselves and if I go to Control Panel -> User Accounts -> Credential Manager I see mostly Microsoft related passwords (Microsoft Outlook, Microsoft Office, XboxLive, SSO_POP_Device, virtualapp/didlogical, tfs, etc). Does anybody know where the user name and password could be stored and how I can remove them (without rebooting my computer) in order to be able to verify that my code supplies the user name and password correctly? I already asked the IT-manager (who's also in charge of the documentation system) and he didn't know.
|
|
|
|