Need help in Redirecting to another page - php

<html>
<head>
<title>
Installation
</title>
<script src="public/js/jquery-1.9.0.min.js"></script>
<script src="public/js/bootstrap3/js/bootstrap.js"></script>
<link media="all" type="text/css" rel="stylesheet" href="public/js/bootstrap3/css/bootstrap.min.css">
<link media="all" type="text/css" rel="stylesheet" href="public/js/bootstrap3/css/font-awesome.min.css">
<link media="all" type="text/css" rel="stylesheet" href="public/js/bootstrap3/css/main.css">
</head>
<body>
<div
class="navbar navbar-default navbar-fixed-top">
<div
class="container">
<div
class="navbar-header">
<button
type="button"
class="navbar-toggle"
data-toggle="collapse"
data-target=".navbar-collapse">
<span
class="icon-bar"></span>
<span
class="icon-bar"></span>
<span
class="icon-bar"></span>
</button>
<a
class="navbar-brand"
href="<?php // echo base_url()?>">Kingpabel
ATN</a>
</div>
<div
class="navbar-collapse collapse">
</div>
<!--/.nav-collapse -->
</div>
</div>
<div
class="rc">
<div
class="container main">
<div
class="col-md-3">
</div>
<div
class="col-md-6">
<form
method="post"
accept-charset="utf-8"
role="form"
class="form- signin form-horizontal">
<h2
class="form-signin-heading">Installation</h2>
<div
style="margin-top: 20px;">
<label
for="host_name"
class="col-sm-3 control-label"
style="color: black">
Host
Name
</label>
<div
class="input text database_host col-md-9">
<input
type="text"
name="host_name"
class="form-control"
placeholder="Database Host Name"
autofocus=""
required="required"
id="host_name">
</div>
</div>
<div>
<label
for="database_name"
class="col-sm-3 control-label"
style="color: black">
Database
Name
</label>
<div
class="input text database_name col-md-9">
<input
type="text"
name="database_name"
class="form-control"
placeholder="Database Name"
autofocus=""
required="required"
id="database_name">
</div>
</div>
<div>
<label
for="user_name"
class="col-sm-3 control-label"
style="color: black">
User
Name
</label>
<div
class="input text user_name col-md-9">
<input
type="text"
name="user_name"
class="form-control"
placeholder="Database User Name"
autofocus=""
required="required"
id="user_name">
</div>
</div>
<div>
<label
for="password"
class="col-sm-3 control-label"
style="color: black">
Password
</label>
<div
class="input text password col-md-9">
<input
type="password"
name="password"
class="form-control"
placeholder="Database Password"
autofocus=""
id="password">
</div>
</div>
<div>
<label
for="project_url"
class="col-sm-3 control-label"
style="color: black">
Project
Url
</label>
<div
class="input text project_url col-md-8 input-group input-group-sm">
<input
style=" margin-left: 13px;"
type="text"
name="project_url"
class="form-control"
placeholder="Project URL"
autofocus=""
id="project_url"
aria-describedby="basic-addon2">
<span
class="input-group-btn">
<button
class="btn btn-default"
type="button"
style="margin-top: -15px;">/public</button>
</span>
</div>
</div>
<button
type="submit"
class="btn btn-lg btn-login btn-block">Install</button>
</form>
</div>
</div>
</div>
<section
id="bottom"
style="margin-top: 50px">
</section>
<footer
id="footer">
<div
class="container">
<div
class="footer">
<div
class="row">
<div
class="col-md-12">
</div>
</div>
</div>
</div>
</footer>
</body>
</html>
<?php
if ($_POST) {
$envFile = file_get_contents('.env');
if (isset($_POST['host_name']) && $_POST['host_name'])
$envFile = str_replace('DB_HOST=localhost', "DB_HOST= {$_POST['host_name']}", $envFile);
if (isset($_POST['database_name']) && $_POST['database_name'])
$envFile = str_replace('DB_DATABASE=homestead', "DB_DATABASE={$_POST['database_name']}", $envFile);
if (isset($_POST['user_name']) && $_POST['user_name'])
$envFile = str_replace('DB_USERNAME=homestead', "DB_USERNAME={$_POST['user_name']}", $envFile);
if (isset($_POST['password']) && $_POST['password'])
$envFile = str_replace('DB_PASSWORD=secret', "DB_PASSWORD={$_POST['password']}", $envFile);
file_put_contents('.env', $envFile);
if (isset($_POST['project_url']) && $_POST['project_url']) {
file_get_contents('index.php');
file_put_contents('index.php', "<?php
header('Location: {$_POST['project_url']}/public');
");
}
}`
In above code, after submitting the form, the idex.php is rewriiten and changes. And i wanted to redirect to another page after submitting the form. But it is not being redirected.

Not sure what all your block of codes are for but perhaps try this..
On your
if (isset($_POST['project_url']) && $_POST['project_url']) {
file_get_contents('index.php');
file_put_contents('index.php', "<?php
header('Location: {$_POST['project_url']}/public');
");
}
change to
if (isset($_POST['project_url']) && $_POST['project_url']) {
$url = $_POST['project_url'] + '/public';
header('Location: $url');
}

Related

Bootstrap 4 carousel next and prev slides don't work

I'm trying to solve an weird issue for a school group project on my own, but I'm at wit's end. Essentially, I have a Bootstrap 4 Carousel with three images. Though one of the images is displayed, you can't advance to the next or previous slides. The initial webpage is launched using php as follows:
<?php
//require_once('connection.php');
if (isset($_GET['controller']) && isset($_GET['action'])) {
$controller = $_GET['controller'];
$action = $_GET['action'];
} else {
$controller = 'static';
$action = 'landing';
}
require_once('views/layout.php');
?>
The landing page launches layout.php (which has the Bootstrap, jQuery, popper and other JavaScript files and landing.php (which has the carousel code:
landing.php:
<div id="main_container" class="container-fluid">
<div id="body" class="container">
<p>Stuff about how great the application is.</p>
<div id="carousel" class="carousel slide" content="width=device-width data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
</ol>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="./views/images/kids_kites.png" alt="Los Angeles">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>We had such a great time in LA!</p>
</div>
</div>
<div class="carousel-item">
<img src="./views/images/kids_playing.png" alt="Chicago">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>We had such great pizza in CHI!</p>
</div>
</div>
<div class="carousel-item">
<img src="./views/images/kids_swing.png" alt="New York">
<div class="carousel-caption">
<h3>New York</h3>
<p>It is too crowded!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#carousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#carousel" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</div>
Search Events
</div>
layout.php
<!doctype HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script defer src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<title>Kamps For Kids</title>
<link rel="stylesheet" href="views/styles/styles.css">
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script defer src="views/scripts/main.js"></script>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
</head>
<body>
<?php
require_once "templates/header.php";
require_once "templates/footer.php";
require_once "routes.php";
?>
<div id="id01" class="modal">
<!--action_page.php is the php file which will perform user validation when the 'submit' button is clicked -->
<form class="modal-content animate" action="/action_page.php">
<div class="img-container">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<div><img src="./views/images/KamparoosLogo.png" alt="Logo" class="logo"></div>
<img src="./views/images/img_avatar2.png" alt="Avatar" class="avatar">
<div>
<!-- Add icon library from font-awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Add font awesome icons -->
</div>
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="user-name" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#FAFC2F">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancel-btn">
Cancel
</button>
<span class="psw">Forgot password?</span>
</div>
</form>
</div>
<div id="id02" class="modal">
<!--action_page.php is the php file which will perform user validation when the 'submit' button is clicked -->
<form class="modal-content animate" name="registrationForm" onsubmit="return validateForm()" method="post"
action="/action_page.php">
<div class="img-container">
<h3>Registration Form</h3>
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
<div><img src="./views/images/KamparoosLogo.png" alt="Logo" class="logo"></div>
<img src="./views/images/img_avatar2.png" alt="Avatar" class="avatar">
<div>
<!-- Add icon library from font-awesome -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</div>
</div>
<div class="container">
<div class="form-row">
<div class="form-group col-md-6">
<label for="firstName">First Name</label>
<input type="text" class="form-control" id="firstName" placeholder="Enter first name" name="firstName"
required>
</div>
<div class="form-group col-md-6">
<label for="lastName">Last Name</label>
<input type="text" class="form-control" id="lastName" placeholder="Enter last name" name="lastName"
required>
</div>
<div class="form-group col-md-6">
<label for="emailAddress">Email Address</label>
<input type="email" class="form-control" id="emailAddress" placeholder="Enter email address"
name="emailAddress" required>
</div>
<div class="form-group col-md-6">
<label for="phoneNumber">Phone Number</label>
<input type="tel" class="form-control" id="phoneNumber" placeholder="Enter 10 digit phone number"
name="phoneNumber" required
pattern="[0-9]{3}[0-9]{3}[0-9]{4}"
size="10">
</div>
<div class="form-group col-md-12">
<label for="numOfKids">Number of Kids </label>
<select name="numOfKids" id="numOfKids">
<option value="">Select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter password" name="password"
required>
</div>
<div class="form-group col-md-4">
<label for="confirmPassword">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" placeholder="Re-enter password"
name="confirmPassword" required>
</div>
<div class="form-group col-md-12">
<label for="userRole">Register as </label>
<select name="userRole" id="userRole" required>
<option value="">Select...</option>
<option value="user">Individual User</option>
<option value="admin">Admin</option>
<option value="organization">Organization</option>
</select>
</div>
</div>
</div>
<button type="submit" class="btn btn-danger btn-success"
">Register</button>
</form>
</div>
<script>
// Get the modal
var modal = document.getElementById('id01');
// When the user clicks anywhere outside of the modal, the modal with close
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// Get the modal
var modalTwo = document.getElementById('id02');
// When the user clicks anywhere outside of the modal, the modal with close
window.onclick = function (event) {
if (event.target == modalTwo) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
If you're interested, the project is being saved in a GitHub repository at : https://github.com/ad410project/ad410project I'm sure it's possible some crazy php issue, but any help or suggestions would be appreciated.

data is not coming through in php form [duplicate]

This question already has answers here:
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given... what I do wrong? [duplicate]
(11 answers)
Can I mix MySQL APIs in PHP?
(4 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
this is the code please help me I am connected to the database
so i use mysqli_real_escape_string to get the clear data and save it into my table but it give me a nothing in my data
<?php
$db_connect = mysqli_connect("localhost", "root", "", "master_wn");
if(isset($_POST['send']))
{
session_start();
$name = mysqli_real_escape_string($_POST['name']);
$name2 = mysqli_real_escape_string($_POST['name2']);
$email = mysqli_real_escape_string($_POST['email']);
$case = mysqli_real_escape_string($_POST['case']);
$phone = mysqli_real_escape_string($_POST['phone']);
$adress = mysqli_real_escape_string($_POST['adress']);
$sex = mysqli_real_escape_string($_POST['sex']);
$prove = mysqli_real_escape_string($_POST['prove']);
$quali = mysqli_real_escape_string($_POST['quali']);
$exper = mysql_real_escape_string($_POST['exper']);
$query = "INSERT INTO `stu_data` (`number`,`name`,`name2`,`email`,`phone`,`address`,`sex`,`cases`,`prove`,`quali`,`exper`) VALUES ('','$name','$name2','$email','$phone','$adress','$sex','$case','$prove','$quali','$exper')";
$q = mysqli_query($db_connect,$query);
if ($q){
header("location:step2.php");
}
else
{
"try again";
}
}
?>
<html>
<head>
<title>
test
</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/bootstrap.min.css"/>
<link rel="stylesheet" href="../css/normliaze.css"/>
<link rel="stylesheet" href="../css/style.css"/>
</head>
<body>
<div>
<div class="global">
<!--Star Header-->
<div class="header">
<div class="boy">
<h1>خطوات التقديم لحجز مقعد للدراسات العليا</h1>
<img src="../images/logo.PNG" alt="logo" width="90" height="80">
<p>موقع التقديم للدراسات العليا</p>
</div>
</div>
<!--End Header-->
<div class="holdForm">
<div class="container">
<form class="well form-horizontal" action="step1.php" method="post" id="contact_form">
<fieldset>
<!-- Form Name -->
<legend>الخطوة الاولي </legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input placeholder="Name" class="form-control" type="text" name = "name">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" >الاسم</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input placeholder="الاسم بالعربي" class="form-control" type="text" name="name2">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">E-Mail</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input placeholder="E-Mail Address" class="form-control" type="text" name="email">
</div>
</div>
</div>
<!-- radio checks -->
<div class="form-group">
<label class="col-md-4 control-label">الحالة الاجتماعية</label>
<div class="col-md-4">
<div class="radio">
<label>
<input type="radio" name="case" value="marig" /> متزوج
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="case" value="single" /> اعزب
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="case" value="widow" /> ارمل
</label>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">الهاتف</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-earphone"></i></span>
<input placeholder="(+249)555-1212" class="form-control" type="text" name="phone">
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label">السكن</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
<input placeholder="Address" class="form-control" type="text" name="adress">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">الجنس</label>
<div class="col-md-4">
<div class="radio">
<label>
<input type="radio" name="sex" value="mail" /> ذكر
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="sex" value="fmail" /> اثتي
</label>
</div>
</div>
</div>
<!-- Text area -->
<div class="form-group">
<label class="col-md-4 control-label">اثبات شخصية</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-file"></i></span>
<input placeholder="Address" class="form-control" type="text" name="prove">
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">المؤهل العلمي</label>
<div class="col-md-4 selectContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-list"></i></span>
<select class="form-control selectpicker" name="quali">
<option value=" " >... اختر مؤهل</option>
<option name="select1">دبلوم عالي</option>
<option name="select2">بكلاريوس</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">سنوات الخبرة</label>
<div class="col-md-4 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input name="exper" placeholder="Address" class="form-control" type="text">
</div>
</div>
</div>
<!-- Success message -->
<div class="alert alert-success" role="alert" id="success_message">Success <i class="glyphicon glyphicon-thumbs-up"></i> Thanks for contacting us, we will get back to you shortly.</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<input type="submit" class="btn btn-warning glyphicon glyphicon-send" name="send" value="التالي" >
</div>
</div>
</fieldset>
</form>
</div>
</div><!-- /.container -->
</div>
<div id="footer">
<p class="p2">جميع الحقوق محفوظة للمبرمج محمد تاج الدين © 2017-2018</p>
</div><!--end footer-->
</div><!--end all-->
<!--End content-->
<script src="/js/bootstrap.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/plugin.js"></script>
</body>
</html>
this is the code please help me I am connected to the database
so i use mysqli_real_escape_string to get the clear data and save it into my table but it give me a nothing in my data this is the code please help me I am connected to the database
so i use mysqli_real_escape_string to get the clear data and save it into my table but it give me a nothing in my data

trying to make a login system but nothing returns to database

i've been trying to make a login system on my website with a signup button but nothing returns to the database aka its empty, here's the code
<?php
include 'dbh.php', 'connect.php';
$usernames=$_POST['usernames'];
$passwords=$_POST['passwords'];
$repassword=$_POST['repassword'];
$email=$_POST['email'];
$taken="false";
$database="database1";
//Main if Statement
if($usernames&&$passwords&&$email&&$repassword){
//connect to database
$con = mysqli_connect('localhost', $username, $password) or die("Unable to log into database");
#mysql_select_db($database1, $con) or die("Unable to connect");
mysql_query("INSERT INTO `users` VALUES('', '$usernames', '$passwords', '$email', '$repassword')") or die ("Strange error");
echo "Account created";
mysql_close($con);
// header("location: index.php");
} else {
echo"You need to have Username, Password and Email!";
}
?>
i have tried to signup for testing but nothing returns to the database?
here's the html script
<!DOCTYPE html>
<html lang="en">
<head>
<link href="animate.css" rel="stylesheet">
<title>Twist - Shortie Lovers!</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js" </script>
</head>
<body>
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
Twist
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>New</li>
<li class="dropdown">
Hot <b class="caret"></b>
<ul class="dropdown-menu">
<li>Test</li>
</ul>
</li>
<li>Upload</li>
<li>Sign up</li>
<li>Login</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="jumbotron text-center">
<h1>You can do it!</h1>
<p>How? simple... Make your own movie, get rated by other users and movie makers and WIN!</p>
<a class="btn btn-info">Read More...</a>
</div>
</div>
<div class="container text-center">
<h3>Browse popular Posts or Login</h3>
</div>
<div class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<p class="navbar-text pull-left">Copyright © 2016 Twist</p>
Contribute
</div>
</div>
<!--For signup-->
<div class="modal fade" id="signup" role="dialog" action="create.php" method="POST">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" >
<div class="modal-header">
<h4>Signup</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="signup-username" class="col-lg-2 control-label">Username:</label>
<div class="col-lg-10">
<input type="text" name="usernames" class="form-control" id="signup-username" placeholder="Username" required>
</div>
</div>
<div class="form-group">
<label for="signup-password" class="col-lg-2 control-label">Password:</label>
<div class="col-lg-10">
<input type="password" name="passwords" class="form-control" id="signup-password" placeholder="Password" required>
</div>
</div>
<div class="form-group">
<label for="signup-repassword" class="col-lg-2 control-label">Again:</label>
<div class="col-lg-10">
<input type="password" name="repassword" class="form-control" id="signup-repassword" placeholder="Retype Password" required>
<!--<script>
$('form').on('submit1',function(){
if($('#signup-password').val()!=$('#signup-repassword').val()){
alert('Password does not match!');
return false;
}
return true;
});
</script>-->
</div>
</div>
<div class="form-group">
<label for="signup-email" class="col-lg-2 control-label">Email:</label>
<div class="col-lg-10">
<input type="text" name="email" class="form-control" id="signup-email" placeholder="Email" required>
</div>
</div>
</div>
<!--<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>-->
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal">Close</a>
<button class="btn btn-primary" type="submit1">Sign Up</button>
</div>
</form>
</div>
</div>
</div>
<!--Login -->
<div class="modal fade" id="login" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" action="">
<div class="modal-header">
<h4>Login</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="login-username" class="col-lg-2 control-label">Username:</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="login-username" placeholder="Username" required>
</div>
</div>
<div class="form-group">
<label for="login-password" class="col-lg-2 control-label">Password:</label>
<div class="col-lg-10">
<input type="password" class="form-control" id="login-password" placeholder="Password" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal">Close</a>
<button class="btn btn-primary" type="submit">Log In</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Your query is probably not working because you override your username and password, so you probably can't login:
$username=$_POST['username'];
$password=$_POST['password'];
$repassword=$_POST['repassword'];
$email=$_POST['email'];
$taken="false";
$database="database1";
$password=""; //This one is already set!!!
$username="root"; //This one is already set!!!
EDIT:
Try adding something like this, to make sure your query is right:
$result = mysql_query('YOUR QUERY');
if (!$result) {
die('Invalid query: ' . mysql_error());
}

Only 1 item stored in my database

checkout.php
...............
I use this code it. When i buy 2 or more items, only 1 item stored in my database. thanks in advance...................
<?php
session_start();
include('conn.php');
require('item.php');
if(isset($_POST['confirm'])){
$order=$_POST['order'];
$date = date('Y-m-d H:i:s');
$lname=$_POST['lname'];
$fname=$_POST['fname'];
$mname=$_POST['mname'];
$add=$_POST['add'];
$em=$_POST['email'];
$num=$_POST['number'];
if(empty($order)){
echo"<script>alert('Please choose your payment method.')</script>";
}
mysqli_query($con,"INSERT INTO `godgets`.`order` (`Lastname`, `Firstname`, `Middlename`, `Address`, `Email`, `Number`, `Date`) VALUES ('$lname', '$fname', '$mname', '$add', '$em', '$num', '$date')");
$orderid=mysqli_insert_id($con);
$cart=unserialize(serialize($_SESSION['cart']));
for ($i=0; $i<count($cart); $i++) {
$p_name=$cart[$i]->name;
$p_price=$cart[$i]->price;
$p_des=$cart[$i]->des;
$p_quantity=$cart[$i]->quantity;
$p_image=$cart[$i]->image;
$p_total=$cart[$i]->price * $cart[$i]->quantity;
mysqli_query($con,"INSERT INTO order_details (`ORDER_ID`, `P_name`, `P_price`, `P_quantity`, `Picture`,`Total`) VALUES
('.$orderid.', '$p_name.', '.$p_price.', '.$p_quantity.', '.$p_image.','.$p_total.')");
}
echo"<script>alert('Thankyou For Shopping!')</script>";
echo"<script>window.open('index.php','_self')</script>";
unset($_SESSION['cart']);
exit();
}
?>
help me please i`m a newbie :(
tnx
fds
item.php
<?php
class Item{
var $id;
var $name;
var $des;
var $quantity;
var $price;
var $image;
}
?>
addcart.php
<?php
session_start();
?>
<head>
<meta name="viewport" content="width=device-width, initial- scale=1">
<link rel="stylesheet" type="text/css" href="css\bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css\bootstrapValidator.min.css">
<script src="jq/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrapValidator.min.js"></script>
</head>
<body background="pic/bg3.jpg" style="background-attachment:fixed;background-size:cover;">
<?php include("navbar.php");
require('conn.php');
require('item.php');
if(!isset($_SESSION['username'])){
echo"<script>window.open('sign.php','_self')</script>";
exit();
}
if(isset($_GET['id']) && !isset($_POST['update'])){
$result=mysql_query('select * from products_db where P_ID ='.$_GET['id']);
$product=mysql_fetch_object($result);
$item= new Item();
$item->id= $product->P_ID;
$item->name=$product->P_NAME;
$item->des=$product->DESCRIPTION;
$item->price=$product->P_PRICE;
$item->image=$product->PICTURE;
$item->quantity=1;
//check product
$index=-1;
$cart=unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart);$i++)
if ($cart[$i]->id==$_GET['id']){
$index=$i;
break;
}
if($index==-1){
$_SESSION['cart'][]=$item;
}
else{
$_SESSION['cart']=$cart;
}
}
//delete
if(isset($_GET['index']) && !isset($_POST['update'])){
$cart=unserialize(serialize($_SESSION['cart']));
unset($cart[$_GET['index']]);
$cart=array_values($cart);
$_SESSION['cart']=$cart;
}
if (isset($_POST['update'])){
$arrQuantity=$_POST['quantity'];
// check quantity
$valid=1;
for($i=0; $i<count($arrQuantity);$i++)
if(!is_numeric($arrQuantity[$i]) || $arrQuantity[$i]< 1){
$valid=0;
break;
}
if($valid==1){
$cart=unserialize(serialize($_SESSION['cart']));
for($i=0; $i<count($cart);$i++){
$cart[$i]->quantity=$arrQuantity[$i];
}
$_SESSION['cart']=$cart;
}
else
$error='Quantity is Invalid';
}
?>
<div class="container">
<div class="row">
<div class="col-md-12 col-xs-12">
<div class="panel panel-info">
<div class="panel-heading">
<form method="POST">
<div class="panel-title">
<h5><span class="glyphicon glyphicon-shopping-cart" style="float:left;"></span> YOUR ITEM(s)
<label style="color:red;margin-left:400px;"><?php echo isset($error) ? $error : '';?></label>
<span class="glyphicon glyphicon-share-alt"></span> Continue Shopping
<button type="submit" name="update" style="float:right; margin-right:3%;"class="btn btn-info btn-sm "><span class="glyphicon glyphicon-floppy-saved"></span>Update Cart</button>
</h5>
</div>
</div>
<?php
$cart=unserialize(serialize($_SESSION['cart']));
$s=0;
$index=0;
for ($i=0;$i<count($cart); $i++){
$s+=$cart[$i]->price * $cart[$i]->quantity;
?>
<div class="panel-body">
<div class="row">
<div class="col-md-2 col-xs-12">
<img class="img-responsive" src="<?php echo $cart[$i]->image;?>" style="height:30%;width:100%;">
</div>
<div class="col-md-4 col-xs-12">
<h4 style="font-family:agency fb;"><strong><?php echo $cart[$i]->name;?></strong></h4>
<div><h4 style="font-family:agency fb;"><small><?php echo $cart[$i]->des;?></small></h4></div>
</div>
<div class="col-md-6 col-xs-12">
<div class="col-md-6 text-right">
<h4 style="font-family:agency fb;"><strong>Php <?php echo $cart[$i]->price;?></strong> x </h4>
</div>
<div class="col-md-4 col-xs-9">
<input type="text" name="quantity[]" value="<?php echo $cart[$i]->quantity;?>" class="form-control" style="width:50px;">
</div>
<div class="col-md-3 col-xs-2" style="margin-top:1%;">
<span class="glyphicon glyphicon-trash"></span>
</div>
</div>
</div>
</div>
<hr class="divider">
<?php
$index++;
}
?>
</form>
<div class="panel-footer" style="height:9%;">
<div>Empty Cart</div>
<div>Checkout</div>
<div style="float:right;margin-right:2%;font-family:agency fb;"><p class="form-control"><b>Total</b> Php: <?php echo $s;?></p></div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header" style="background-color:#cceaf6;">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel" style="font-family:agency fb;font-size:30px;">Costumer`s Information</h4>
</div>
<form method="POST" action="checkout.php">
<div class="modal-body">
<div class="form-group">
<div class="row col-md-12">
<div class="container inline col-md-4" >
<input type="radio" class="form-control" name="order" onclick="showhidediv(this);" value="paypal">
<img src="pic/paypal.jpg" style="width:200px;height:100px;">
</div>
<div class="col-md-4">
<center><span style="font-family:agency fb; font-size: 50px;">or</span></center>
</div>
<div class="col-md-4">
<input type="radio" class="form-control" name="order" onclick="showhidediv(this);" value="Cash On Delivery">
<img src="pic/cash.png" style="width:200px;height:100px;">
</div>
</div>
<div class="form-inline">
<input type="text" class="form-control" name="lname" placeholder="Lastname" required>
<input type="text" class="form-control" name="fname" placeholder="Firstname"required>
<input type="text" class="form-control" name="mname" placeholder="Middlename"required>
</div>
<br>
<input type="text" class="form-control" name="add" placeholder="Complete Address" style="width:596px;"required>
<br>
<input type="email" class="form-control" name="email" placeholder="Email Address"style="width:596px;"required>
<br>
<input type="text" class="form-control" name="number" placeholder="Contact Number"style="width:196px;" required>
<br>
<div id="one" style="display:none;">
<div style="background-color:#cceaf6;"><p>Bill to another address. (Optional)</p></div>
<div class="form-inline">
<input type="text" class="form-control" name="lname2" placeholder="Lastname">
<input type="text" class="form-control" name="fname2" placeholder="Firstname">
<input type="text" class="form-control" name="mname2" placeholder="Middlename">
</div>
<br>
<input type="text" class="form-control" name="add2" placeholder="Complete Address" style="width:596px;">
<br>
<input type="email" class="form-control" name="email2" placeholder="Email Address"style="width:596px;">
<br>
<input type="text" class="form-control" name="number2" placeholder="Contact Number"style="width:196px;">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="confirm" class="btn btn-success" style="font-family:agency fb;font-size:15px;width:100px;">OK</button>
</div>
</form>
</div>
</div>
</body>
<script>
function goBack() {
window.history.back();
}
function showhidediv( rad )
{
var rads = document.getElementsByName( rad.name );
document.getElementById( 'one' ).style.display = ( rads[1].checked ) ? 'block' : 'none';
}
</script>
Error
only 1 item stored.
Hi you need to correct this: '.$cart[$i]->image.'
for ($i=0; $i<count($cart); $i++) {
mysql_query("INSERT INTO order_details VALUES ('.$orderid.', '.$cart[$i]->name.', '.$cart[$i]->price.', '.$cart[$i]->quantity.', '.$cart[$i]->image.', '.$cart[$i]->price * $cart[$i]->quantity.','.$order.')");
}
Also please highlight the error line in the code next time you ask such question.

PHP Radio Buttons forms example

So lets say i have the following example how can i get values from radio buttons and acctualy work with those values? You can see that i tried something but i can't find it how to make it work ..
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-ex-collapse"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand">My learning skills: A self-assessment questionnaire</a></div>
<div class="collapse navbar-collapse" id="navbar-ex-collapse">
<ul class="nav navbar-nav navbar-right"></ul>
</div>
</div>
</div>
<div class="section">
<div class="container">
<div class="row">
<div class="col-md-12">
<form role="form" method="post">
<div class="form-group"><label class="control-label" for="exampleInputEmail1">Nume:</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter name" type="text"></div>
<div class="form-group"><label class="control-label" for="exampleInputEmail1">Email address:</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter email" type="email"></div>
<div class="container">
<div class= "row">
<h4>Your gender: *</h4>
</div>
<div class="row">
<div class="radio">
<label><input type="radio" name="gender" value="female">F</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="male">M</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="other">Other</label>
</div>
</div>
</br>
<div class="row">
<div class="form-group"><label class="control-label" for="exampleInputEmail1">Your age: *</label><input class="form-control input-lg" id="exampleInputEmail1" placeholder="Enter age" type="text"></div>
</div>
<div class= "row">
<h2>That was it! Please, keep your scores saved and check that after refilling in this questionnaire, in 6-8 months from now on. Happy learning!</h2>
</div>
<div class= "row">
<button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg">Send</button>
</div>
</div>
</form>
<?php $gender = $_POST['contact']; echo $gender; ?>
</div>
</div>
</div>
</div>
</body>
</html>
As example:
echo $gender;
and the results should be $female
<?php $gender = $_POST['contact']; echo $gender; ?>
Change this to
<?php $gender = $_POST['gender']; echo $gender; ?>.
Name of your radio control is gender not contact.

Categories