Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by phpnewbie26

  1. Hi, I am working on a website that users can log into from one page and administrate their users from another. first page is index.php and second is admin.php. on the index page I have a form to login with that calls out to a stand alone .php script called "checklogin.php" here is the code... <?php ob_start(); $host=; // Host name $username=; // Mysql username $password="; // Mysql password $db_name="; // Database name $tbl_name="; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $login and $pass $login=$_POST['login']; $pass=$_POST['pass']; // To protect MySQL injection (more detail about MySQL injection) $login = stripslashes($login); $pass = stripslashes($pass); $login = mysql_real_escape_string($login); $pass = mysql_real_escape_string($pass); $sql="SELECT * FROM Registration WHERE login='$login' and pass='$pass'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $login and $pass, table row must be 1 row if($count==1){ session_register("login"); session_register("pass"); header("location:Admin.php"); } else { echo "<script language='javascript'> alert('Sorry, but you must login to view the members area!') </script> <script> window.location='index.php' </script>"; } ob_end_flush(); ?> my admin page has this script on it as a redirect... <?php session_start(); if(!session_is_registered(login)){ header("admin.php"); } ?> my question is...how can I echo out user specific data with this code onto the admin page in a div? since the code is living outside the admin page, I cant figure out how to do it...any help, thanks!
  2. The script gets to the //Check Query part and fails. It echos out the "lid query" and doesn't put anything into the database. I tried to just remove that portion, but it still wouldn't input any data into my table. I am very new at PHP and am basically getting code off the internet and throwing it into some pages and seeing if it works. This is a very simple script, I just dont see why it isn't working?
  3. Hi, I am having an Issue inputting data into my database with this code. I tested the connection, which works fine, but when I try to submit the form I get the "die("lid query: " . mysql_error());". Any Ideas? <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <form action="thispage.php" method="POST"> <input type="text" name="name" placeholder="Check-in Name"> <input type="submit" value='submit'></form> <?php if (isset($_POST['submit'])) { $name = $_POST['name']; $host ="localhost"; $username = "username"; $password = "password"; $dbname = "database"; $con = mysql_connect($host, $username, $password, $dbname); //Check Connection if (!$con) { die("Could not connect: " . mysql_error()); } //Select your database mysql_select_db("database",$con); //Check to make sure the database is there if (!$mysql_select_db) { die ('Can't use the db : ' . mysql_error()); } //Run query $insert = mysql_query("insert into Users(name) values ('$name')"); } //Check Query if (!$insert) { die("lid query: " . mysql_error()); } echo "Data inserted"; mysql_close($con); ?> </body> </html>
  • Create New...