What's new

Ask ko lang guys bat kaya di nag save sa sql?

Shinki gami

Forum Veteran
Joined
Apr 27, 2017
Posts
1,406
Reaction
1,938
Points
757
Age
29
di po ba talaga gumagana yung href kasi pag button nagsasave naman sa sql ko salamat sa sasagot mga master
Code:
<?php include 'header.php';?>

<div class="container mt-3">

<style>

        body {

            background-color: #587383;

            color: #ffffff;

        }

    </style>

<h1>Input Information</h1>



<form action="add_hiring.php" method="POST">

<div class="form-group">

    <div class="form-group">

    <label>Last Name</label>

    <input name="lastname" type="text" class="form-control">

    </div>

    <div class="form-group">

    <label>First Name</label>

    <input name="firstname" type="text" class="form-control">

    </div>

    <div class="form-group">

    <label>Age</label>

    <input name="age" type="text" class="form-control">

    </div>

    <div class="form-group">

    <label>Email</label>

    <input name="email" type="text" class="form-control">

    </div>

    <a href="ty.php" class="btn btn-primary" role="button">Apply</a>

    </form>

</div>
 
Based on the code you provided, it seems like you are using a form to collect input information from the user. The form action is set to "add_hiring.php" which suggests that upon submission, the form data will be sent to that PHP script for processing.

However, instead of using a submit button, you are using an anchor tag with a href attribute set to "ty.php". This means that when the user clicks on the "Apply" link, it will redirect them to the "ty.php" page instead of submitting the form data to the "add_hiring.php" script.

If you want the form data to be saved in your SQL database, you need to modify the code as follows:

1. Change the anchor tag to a submit button by replacing the anchor tag with a button tag:
HTML:
<button type="submit" class="btn btn-primary">Apply</button>

2. Make sure the form action attribute is set to "add_hiring.php":
HTML:
<form action="add_hiring.php" method="POST">

3. In the "add_hiring.php" file, you can access the form data using the $_POST superglobal array and then save it in your SQL database accordingly.

Here's an example of how you can retrieve the form data and save it in your database using PHP and MySQLi:

PHP:
<?php
// add_hiring.php

include 'db_connect.php'; // Include your database connection file

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve the form data
    $lastname = $_POST["lastname"];
    $firstname = $_POST["firstname"];
    $age = $_POST["age"];
    $email = $_POST["email"];

    // Insert the form data into your SQL database
    $sql = "INSERT INTO your_table_name (lastname, firstname, age, email) VALUES ('$lastname', '$firstname', '$age', '$email')";

    if ($conn->query($sql) === TRUE) {
        // Data saved successfully
        echo "Data saved to SQL database.";
    } else {
        // Error occurred while saving data
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    // Close the database connection
    $conn->close();
}
?>

Make sure to replace "your_table_name" with the actual name of your database table where you want to save the data.

Remember to also validate and sanitize the form inputs to prevent SQL injection and other security vulnerabilities.
 
di po talaga magsave yan.. ang <a href=""> ay for link lang. kailangan talaga dyan ay submit button para pati yung data na nasa form mo masama sa pag send ng request sa ty.php lalo na kung post method lang nareread ng ty.php mo.

kung gusto mo na maredirect sa ty.php pagtapos masave yung data sa db

gumamit ka ng header function sa ty.php mo. pede mo lagay yan pag success yung paginsert mo ng data sa db.

header("Location: thankyou_page.html/"); exit;
 
Last edited:
di po talaga magsave yan.. ang <a href=""> ay for link lang. kailangan talaga dyan ay submit button para pati yung data na nasa form mo masama sa pag send ng request sa ty.php lalo na kung post method lang nareread ng ty.php mo.

kung gusto mo na maredirect sa ty.php pagtapos masave yung data sa db

gumamit ka ng header function sa ty.php mo. pede mo lagay yan pag success yung paginsert mo ng data sa db.

header("Location: thankyou_page.html/"); exit;
Sge master ni try ko to with if e pero dumederecho sya sa ty.php naman without inputting dun sa form
 
Sge master ni try ko to with if e pero dumederecho sya sa ty.php naman without inputting dun sa form
sa add_hiring.php nyo pala ilagay yung header ("Location: ty.php") since nandun yung pag insert ng data. dapat palitan nyo din ng <button type="submit"> yung nasa form din
 

Similar threads

Back
Top