6 Replies - 276 Views - Last Post: 03 November 2013 - 03:15 AM Rate Topic: -----

#1 ainyrusly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 07-February 11

how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 01:22 AM

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php session_start()
?>
</head>

<body>



<?php
$con=mysqli_connect("localhost","root","","asnaf2db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO admin (adminName, adminID)
VALUES
('$_POST[name]','$_POST[password]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "1 record added";

document.location = "home.php";

mysqli_close($con);
?>

This post has been edited by Dormilich: 03 November 2013 - 03:04 AM
Reason for edit:: please use [CODE] [/CODE] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: how to redirect this to other page, i've try this by i get an erro

#2 Peter O  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 125
  • Joined: 19-October 13

Re: how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 01:50 AM

document.location = "home.php";
is Javascript. In PHP you can redirect by setting a HTTP header.
header('Location: http://www.yoursite.com/home.php');
Note that all headers will be sent before any other output to the client so you have to set it before you output the page (before <html...).
Was This Post Helpful? 0
  • +
  • -

#3 ainyrusly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 07-February 11

Re: how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 02:00 AM

i already change it but it said duplicate primary key
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2886
  • View blog
  • Posts: 9,587
  • Joined: 12-December 12

Re: how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 02:15 AM

$sql="INSERT INTO admin (adminName, adminID)
VALUES
('$_POST[name]','$_POST[password]')";

You are inserting a password into the adminID field. I would guess that adminID is the primary key field and you've already entered the password once.
Was This Post Helpful? 1
  • +
  • -

#5 Peter O  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 125
  • Joined: 19-October 13

Re: how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 02:18 AM

What is the primary key for the admin table? Each row in the table has to have a unique primary key. If adminName is the primary key that means you can't have more than one admin with the same name and if you try to add another admin with the same name the query will fail.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3397
  • View blog
  • Posts: 9,607
  • Joined: 08-June 10

Re: how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 03:05 AM

note, your session won’t start either, session_start() must come before any output (it needs to set some headers).
Was This Post Helpful? 0
  • +
  • -

#7 ainyrusly  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 07-February 11

Re: how to redirect this to other page, i've try this by i get an erro

Posted 03 November 2013 - 03:15 AM

thank you !! i already solved it :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1