PHP - Issue With Validating The Login Information And Inserting In To Database
Hi All,
I Have an issue validating and inserting the data in to the database. I am beginner and the error message is new to me however i have google it but unable to find hope any one can help Thanks in advanced. Error : "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\signupck.php on line 32 Deprecated: Function eregi() is deprecated in C:\wamp\www\signupck.php on line 50 Welcome, You have successfully signed up Click here to login" Please find the Code Below: File name:signup.php Code: [Select] <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Fast Fix Pro Signup</title> <script type="text/javascript"> function validate(form) { if(form1.userid.value == "") { alert('Please enter userid '); form1.userid.focus(); return false; } if(form1.userid.value == "") { alert('Please enter userid '); form1.userid.focus(); return false; } if(form1.password.value == "") { alert('Please enter password '); form1.password.focus(); return false; } if(form1.password2.value == "") { alert('Please renter the password '); form1.password2.focus(); return false; } if(form1.email.value == "") { alert('Please enter Email '); form1.email.focus(); return false; } if(form1.fname.value == "") { alert('Please enter First Name '); form1.fname.focus(); return false; } if(form1.lname.value == "") { alert('Please enter Last Name '); form1.lname.focus(); return false; } if (!document.form1.agree.checked) { alert("Please Read the guidlines and check the box below ."); return false; } return true; } </script> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <br/> <br/> <table width='67%' height="454" border='0' align=center cellpadding='0' cellspacing='0'><form name="form1" method=post action="signupck.php" onsubmit='return validate(this)'><input type="hidden" name="todo" value=post> <tr bgcolor='#f1f1f1'><td align=center colspan=2><font face='Verdana' size='2' ><b>Signup</b></td></tr> <tr bgcolor='#f1f1f1'><td > <font face='Verdana' size='2' >User ID</td><td ><font face='Verdana' size='2'><input type=text name=userid></td></tr> <tr ><td > <font face='Verdana' size='2' >Password</td><td ><font face='Verdana' size='2'><input name=password type=password></td></tr> <tr bgcolor='#f1f1f1'><td > <font face='Verdana' size='2' >Re-enter Password</td><td ><font face='Verdana' size='2'><input name=password2 type=password></td></tr> <tr ><td ><font face='Verdana' size='2' > Email</td><td ><input type=text name=email></td></tr> <tr bgcolor='#f1f1f1'><td > <font face='Verdana' size='2' >First Name</td><td ><font face='Verdana' size='2'><input type=text name=fname></td></tr> <tr ><td > <font face='Verdana' size='2' >Last Name</td><td ><font face='Verdana' size='2'><input type=text name=lname></td></tr> <tr bgcolor='#f1f1f1' ><td > <font face='Verdana' size='2' >I agree to terms and conditions</td><td ><font face='Verdana' size='2'><input type=checkbox name=agree value='yes'></td></tr> <tr ><td align=center colspan=2><input type=submit value=Signup> <input name="Reset" type=reset value=Reset> <td colspan=2 align=left> </td></td></tr> </table> <center> <br><font face='Verdana' size='2' ><a href='login.php'>Already a member ? Please Login</a></font></center> </body> </html> File Name :signuppck.php Code: [Select] <?php include ("Connection.php");// database connection details stored here ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Type a title for your page here)</title> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <?php extract($_POST); //<---I don't recommand this really if(isset($todo) and $todo=="post") { $status = "OK"; $msg=""; // if userid is less than 3 char then status is not ok if(!isset($userid) or strlen($userid) <3) { $msg=$msg."User id should be =3 or more than 3 char length<BR>"; $status= "NOTOK"; } if(mysql_num_rows(mysql_query("SELECT userid FROM signup WHERE userid = '$userid LIMIT 1' "))) <-------------------(line 32) { $msg=$msg."Userid already exists. Please try another one<BR>"; $status= "NOTOK"; } if ( strlen($password) < 3 ) { $msg=$msg."Password must be more than 3 char legth<BR>"; $status= "NOTOK"; } if ( $password <> $password2 ) { $msg=$msg."Both passwords are not matching<BR>"; $status= "NOTOK"; } if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) <--------------- (Line 50) { $msg=$msg."enter valid email address<BR>"; $status= "NOTOK"; } if ($agree<>"yes") { $msg=$msg."You must agree to terms and conditions<BR>"; $status= "NOTOK"; } if($status<>"OK") { echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>"; }else{ // if all validations are passed. $query=mysql_query("INSERT INTO signup(userid,password,email,Fname,Lname) values('$userid','$password','$email','$fname','$lname')");; echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=login.php>Click here to login</a><br></font>"; } } ?> </body> </html> File Name :<include file> Code: [Select] <HTML> <HEAD> <TITLE>Connecting to Database</TITLE> </HEAD> <BODY> <?php $db = "quantas"; mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db($db); ?> </BODY> </HTML> Similar Tutorialsinformation not posting into the database the code below is the check code/insert code. Please if anyone knows why let me know. Code: [Select] [color=red]<?php //msut be logged in page session_start(); if ($_SESSION['username']) { echo""; } else die("You must log in first!"); //form information $submit = $_POST['submit']; $row4 = $_SESSION['username']; // form data $link = strip_tags($_POST['link']); $message = strip_tags($_POST['message']); $title = strip_tags($_POST['title']); $author = strip_tags($_POST['author']); $date = date('Y-m-d'); $connect = mysql_connect("db","username","password") or die("Not connected"); mysql_select_db("username") or die("could not log in"); $querycheck = "SELECT * FROM boox WHERE username='$row4'"; $result = mysql_query($querycheck); while($rowz = mysql_fetch_array($result)) $linkcheck = $rowz['link']; if ($submit) { if($link&$title&$author) { // check username and subject lentgh if ($linkcheck == $link) { die ("This link has already been posted."); } else { //open database $connect = mysql_connect("db","username","password") or die("Not connected"); mysql_select_db("username") or die("could not log in"); $queryreg = mysql_query("INSERT INTO boox Values ('','$row4','$link','$title','$author','$message','$date')"); echo "You have just officialy posted on the Catalina Beat Mixers. "; } } } else { die ("You forgot to put something in the link/title/author box."); } ?>[/color] [code] hey there I have an issue when I am inserting an array into the database. When I run the insert statements the records get inserted but it is sometimes one less record than is in the table and sometimes even less. for example if I have 5 records it only inserts the first 4. This is confusing because when I echo out the statement in the loop it shows all 4 insert statements. my loop for inserting looks like this: if(isset($_SESSION['cushArray'])){ foreach($_SESSION['cushArray'] as $key => $value){ $getCushSKU = "SELECT SKU FROM Cushion WHERE Name = '".$value['Cushion']."'"; //echo $getCushSKU; $resultGetCushSKU = mysql_query($getCushSKU); $getResultGetCushSKU = mysql_fetch_assoc($resultGetCushSKU); //echo $getResultGetCushSKU['SKU']; $getFabricSKU = "SELECT SKU FROM Fabric WHERE Name = '".$value['Fabric']."'"; $resultGetFabricSKU = mysql_query($getFabricSKU); $getResultGetFabricSKU = mysql_fetch_assoc($resultGetFabricSKU); if($_SESSION['cushArray'][$i]["ContWeltFabric"] != "N/A"){ $getWeltFabricSKU = "SELECT SKU FROM Fabric WHERE Name = '".$value['ContWeltFabric']."'"; $resultGetWeltFabricSKU = mysql_query($getWeltFabricSKU); $getResultGetWeltFabricSKU = mysql_fetch_assoc($resultGetWeltFabricSKU); }else{ $getResultGetWeltFabricSKU = "N/A"; } $sqlCush = "INSERT INTO OrdersCushion(OrderID, ProductSKU, FabricSKU, WeltFabricSKU, Quantity, ButtonColor, ZipperColor, Fill) VALUES('".$getOrderIDNum['OrderID']."', '".$getResultGetCushSKU['SKU']."', '".$getResultGetFabricSKU['SKU']."', '".$getResultGetWeltFabricSKU['SKU']."', '".$value['Quantity']."', '".$value['Button']."', '".$value['Zipper']."', '".$value['Fill']."') "; //echo $sqlCush; $resultCush = mysql_query($sqlCush); } } any help is much appreciated Could anyone help me making a login function that checks the txt document if user and pw exists/are correct? -and if they are, sends you to a logged in page. This is for a assignment which is why I have to store the information in a text document, I know it's unsafe. Also i know i should use $_Sessions but I'm not sure how to use it and where to put it.
So far I have created the form which has 2 buttons one for registering and one for logging in. I have also created the registration function which checks the text file if the username already exists if not it will register it. <html lang="eng"> <head> <link rel="stylesheet" href="style.css"> <title>name</title> </head> <body> <div class="formdiv"> <h2>Log in or register</h2> <form action="" method="post"> <p>Username<p style="color:black">*</p> <input type="text" name="user" placeholder="Type in your username" required> <p>Password<p style="color:black">*</p> <input type="password" name="pw" placeholder="Type in your password" required> <?php if (isset($_POST['saveBtn'])){ $username = $_POST['user']; $password = $_POST['pw']; $error = register($username); if ($error == '') { echo "User: $username has been registered!<br/>"; } else echo $error; } ?> <input type="submit" name="saveBtn" value="Save new user"> <input type="submit" name="loginBtn" value="Login"> </form> </div> <?php // Registration function register($user){ $textError = ''; // Check and see if user exists $UserPassTxt = fopen("userpwd.txt","a+"); // Opens text doc rewind($UserPassTxt); while (!feof($UserPassTxt)) { $line = fgets($UserPassTxt); $tmp = explode(':', $line); if ($tmp[0] == $user) { $textError = "Username already exists!"; break; } } if ($textError == ''){ $hash = password_hash('', PASSWORD_DEFAULT); fwrite($UserPassTxt, "\n$user: $hash"); } fclose($UserPassTxt); // Closes txt doc return $textError; } ?> <?php //Login function login($user, $pass){ } ?> </body> ///here's my best attempt at the function <?php //Login $error = '0'; if (isset($_POST['loginBtn'])){ $username = $_POST['user']; $password = $_POST['pw']; $error = login($username,$password); } function login($user, $pass){ $errorText = ''; $validUser = false; $UserPassTxt = fopen("userpwd.txt","r"); rewind($UserPassTxt); while (!feof($UserPassTxt)) { $line = fgets($UserPassTxt); $tmp = explode(':', $line); if ($tmp[0] == $user) { if (trim($tmp[1]) == trim(password_hash('', PASSWORD_DEFAULT))){ $validUser= true; $_SESSION['user'] = $user; } break; } } fclose($UserPassTxt); if ($validUser != true) $errorText = "Not correct username or password"; if ($validUser == true) $_SESSION['validUser'] = true; else $_SESSION['validUser'] = false; return $errorText; } function logoutUser(){ unset($_SESSION['validUser']); unset($_SESSION['user']); } function checkUser(){ if ((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true)){ header('Location: index.php'); } } ?>
I am coding a php website and i have everything ready to start on the user interface, but now it wont get the data from the login to get data from the database. I added some debugging code in to see if it even gets a session and it doesn't even get one, can someone please help me and tell me what i am doing wrong?. My login code: Code: [Select] <?php include('/home/sites/******/MasterConfig/Config.php'); $tbl_name='U_members'; // Table name </p> session_start(); ob_start(); // Connect to server and select databse. mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['MYusername']; $rawpassword=$_POST['MYpassword']; $mypassword=md5($rawpassword); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); $_SESSION['loggedin'] = true; $_SESSION['username'] = $_POST['MYusername']; header("location:/welcome.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> Welcome.php: Code: [Select] <?php include('/home/sites/*********MasterConfig/Config.php'); $tbl_name = "U_items"; // Table name </p> ob_start(); ?> <!DOCTYPE html> <html lang="en"> <head> <?php ob_start(); session_start(); ?> <meta charset="utf-8"> <link rel="stylesheet" href="css/all.css"> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.easing.1.3.js"></script> <script type="text/javascript" src="js/jquery.quicksand.js"></script> <script type="text/javascript" src="js/main.js"></script> <title>Product Filter</title> </head> <body> <?php if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) { } else { mysql_close($_SESSION['connect']); header("location:/index.php"); } ?> <h1> Welcome <?php $_SESSION['username']; ?> </h1> <div id="container"> <ul id="filterOptions"> <li class="active"><a href="#" class="all">All my products</a></li> <li><a href="#" class="Car">My cars</a></li> <li><a href="#" class="champ">My motorbikes</a></li> <li><a href="#" class="league1">My ECO</a></li> <li><a href="#" class="league2">My Art</a></li> </ul> <ul class="ourHolder"> <li class="item" data-id="id-1" data-type="Car"> <?php mysql_select_db("$db_name")or die("cannot select DB"); $SQL = mysql_query('SELECT * FROM ' + $tbl_name + ' WHERE Owner = ' + $_SESSION['username']); while($row = mysql_fetch_row($SQL)); $id=$row['ID']; $photo=$row['PicLink']; $ItemName=$row['Name']; if(isset($_SESSION['userName'])) { print "Your session username: ".$_SESSION['username']. "<br>"; } else { print "Session does not exist"; } ?> <img src="<?php $Photo ?>" alt="<?php $ItemName ?>" /> <h3> <?php $ItemName ?></h3> </li> </li> </ul> </div> </body> </html> File name:loginch.php <? include ("session.php"); include ("Connection.php"); ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>(Welcome)</title> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> </head> <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"> <? $usr = $_POST['userid']; $pass = $_POST['password']; $usr=mysql_real_escape_string($usr); $pass=mysql_real_escape_string($pass); if($rec=mysql_fetch_array(mysql_query("SELECT * FROM signup WHERE userid='$usr' AND password = '$pass'"))){ if(($rec['userid']==$usr)&&($rec['password']==$pass)){ include ("newsession.php"); echo "<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>"; print "<script>"; print " self.location='welcome.php';"; // Comment this line if you don't want to redirect print "</script>"; } } else { session_unset(); echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>"; } ?> </body> </html> File Name:Front.htm Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Home Page</title> <style type="text/css"> #dropDownMenu ul { padding: 5px; margin: 0px; text-decoration: none; list-style-type: none; } #dropDownMenu ul li { display: inline; width: 100px; float: left; text-transform: uppercase; font-size: large; padding: 0px 20px 0px 0px; } #dropDownMenu ul li a { color: #666666; text-decoration: none; line-height: 15px; font-size: medium; } #dropDownMenu ul li ul { visibility: hidden; } #dropDownMenu ul li ul li a { font-size: 0.70em; text-transform: uppercase; } .style1 { text-align: left; } .style2 { text-align: center; } .style3 { margin-left: 0px; } #apDiv1 { position:absolute; width:723px; height:93px; z-index:3; left: 124px; top: -11px; } body { background-color: #69F; } #apDiv2 { position:absolute; width:416px; height:182px; z-index:3; left: 314px; top: 318px; } </style> </head> <body> <div style="position: absolute; width: 929px; height: 564px; z-index: 2; left: 158px; top: 36px" id="layer1"> <div style="position: absolute; width: 193px; height: 90px; z-index: 4; left: 626px; top: 135px; bottom: 579px" id="layer3"> <img src="th_ibm-logo.gif" width="219" height="88" /></div> <div style="position: absolute; width: 711px; height: 178px; z-index: 3; left: 100px; top: 79px" id="layer2"><img src="top_banner_corporate2.gif" width="769" height="203" class="style3" /></div> <div class="style2" id="apDiv1"> <h1><em>WELCOME TO AZ GLOBALCTS</em></h1> </div> <div id="apDiv2"> <form action='loginck.php' method=post> <table border='0' align=center cellpadding='0' cellspacing='0'> <tr id='cat'> <tr> <td bgcolor='#f1f1f1' ><font face='verdana, arial, helvetica' size='2' align='center'> Login ID </font></td> <td bgcolor='#f1f1f1' align='center'><font face='verdana, arial, helvetica' size='2' > <input type ='text' class='bginput' name='userid' ></font></td></tr> <tr> <td bgcolor='#ffffff' ><font face='verdana, arial, helvetica' size='2' align='center'> Password </font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' > <input type ='text' class='bginput' name='password' ></font></td></tr> <tr> <td bgcolor='#f1f1f1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'> <input type='submit' value='Submit'> <input type='reset' value='Reset'> </font></td> </tr> <tr> <td bgcolor='#ffffff' ><font face='verdana, arial, helvetica' size='2' align='center'> <a href='signup.php'>New Member Sign UP</a></font></td> <td bgcolor='#ffffff' align='center'><font face='verdana, arial, helvetica' size='2' ><a href=forgot-password.php> Forgot Password</a> ?</font></td></tr> <tr> <td bgcolor='#f1f1f1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'> </font></td> </tr> </table> </center> </form> </div> </div> </body> </html> Error: Successfully,Logged in Log OUT Click here if your browser is not redirecting automatically or you don't want to wait. "; print ""; } } else { session_unset(); echo "Wrong Login. Use your correct Userid and Password and Try "; } ?> Please help Thanks in advanced Hi this is what I have set up - SQL tables - Members - memberid - primary key Username Password Orders - Orderid - primary key memberid - foreign key orderno In my sql table there are two members and two orders. 1 order is assigned to 1 member and the other order to the other member. After each member logs in I need to 'echo' that order on the page. I've not been able to write any succesful php code that 'gets' the specific order that is related to the member that has signed in. I would appreciate help on this! Thanks Hi. Am trying to make an install script but have run into a problem. ---- variables.php - holds the variables that I need install.php - connects to the database and inserts all the values. Now I have a problem. When I execute the install.php it outputs: Creating tables... Connected to database server Database webleague is selected Players table Games table News table Rules table Games table Vars table Inserting default values Inserting news Inserting rules Inserting themes Inserting vars Done. but doesnt insert ANYTHING into the database. Can anyone help? Variables.php: <?php //start //configure database info $databaseserver = "localhost"; //usually localhost $databasename = "xxxxxxxxx"; //the name of your database $databaseuser = "xxxxxxxxx"; //the name of the database user $databasepass = "xxxxxxxxx"; // the password to your database $directory ="http://xxxxxxxxxxxxxxxxxx" ; //the location of your WebLeague directory (no trailing slash) //configure the tables in the database $playerstable = "webl_players"; //the name of the table that contains information about the players $gamestable = "webl_games"; //the name of the table that stores the played games $newstable = "webl_news"; // the name of the table that stores the news $themestable = "webl_themes"; //the name of the table that stores the themes $varstable = "webl_vars"; //the name of the table that stores various information $rulestable = "webl_rules"; //the name of the table the stores the rules //set some general information on your league $leaguename = "IRC League"; //the name of your league $title = ".: IRC League :."; //the title of your pages $favicon = "$directory/WebLeaguefavicon.ico" ; //the location of the shortcut icon $report = "winner"; //who reports? winner/loser $pointswin = "3"; //the number of points awarded for a win $pointsloss = "-1"; //the number of points awarded for a loss //set the username and password for the admin panel $LOGIN = "xxxxxxxxxx"; //the username to access the admin panel $PASSWORD = "xxxxxxxxx"; //the passoword to access the admin panel // finish ?> And this is install.php: Creating tables...<br><br> <?php include "variables.php"; $db = mysql_connect($databaseserver, $databaseuser, $databasepass) or die("Connection Failure to Database Server"); echo "Connected to database server<br>"; mysql_select_db($databasename, $db) or die ($databasename . " Database not found." . $databaseuser); echo "Database " . $databasename . " is selected<br><br>"; if ($db==false) die("Failed to connect to MySQL server<br>\n"); $sql = "CREATE TABLE $playerstable (player_id int(10) DEFAULT '0' NOT NULL auto_increment, name varchar(40) DEFAULT '' NOT NULL, passworddb varchar(10), mail varchar(50), icq varchar(15), aim varchar (40), country varchar(40), games int(10) DEFAULT '0', wins int(10) DEFAULT '0', losses int(10) DEFAULT '0', points int(10) DEFAULT '0', totalwins int(10) DEFAULT '0', totallosses int(10) DEFAULT '0', totalpoints int(10) DEFAULT '0', totalgames int(10) DEFAULT '0', penalties int(10) DEFAULT '0', staff varchar(10), streakwins int(10) DEFAULT '0', streaklosses int(10) DEFAULT '0', PRIMARY KEY (player_id))"; mysql_query($sql,$db); $sql = "ALTER TABLE $playerstable ADD UNIQUE(name) "; mysql_query($sql,$db); echo"Players table<br>"; $sql = "CREATE TABLE $gamestable (game_id int(10) DEFAULT '0' NOT NULL auto_increment, winner varchar(40), loser varchar(40), date varchar(40), PRIMARY KEY (game_id))"; mysql_query($sql,$db); echo"Games table<br>"; $sql = "CREATE TABLE $newstable (news_id int(10) DEFAULT '0' NOT NULL auto_increment, news text, PRIMARY KEY (news_id))"; mysql_query($sql,$db); echo"News table<br>"; $sql = "CREATE TABLE $rulestable (rules_id int(10) DEFAULT '0' NOT NULL auto_increment, rules text, PRIMARY KEY (rules_id))"; mysql_query($sql,$db); echo"Rules table<br>"; $sql = "CREATE TABLE $themestable (theme_id int(10) DEFAULT '0' NOT NULL auto_increment, name varchar(40), color1 varchar(40), color2 varchar(40), color3 varchar(40), color4 varchar(40), aimthemepic varchar(80), bottomleftpic varchar(80), bottommiddlepic varchar(80), bottomrightpic varchar(80), headerbgpic varchar(80), headermenuleftpic varchar(80), headermenurightpic varchar(80), sideleftpic varchar(80), siderightpic varchar(80), topleftpic varchar(80), topmiddlepic varchar(80), toprightpic varchar(80), PRIMARY KEY (theme_id))"; mysql_query($sql,$db); echo"Games table<br>"; $sql = "CREATE TABLE $varstable (vars_id int(10) DEFAULT '0' NOT NULL auto_increment, theme varchar(20), font varchar(80), fontcolor varchar(40), headerfont varchar(80), numgamespage int(10), numplayerspage int (10), statsview varchar(10), stats1view varchar(10), stats2view varchar(10), stats3view varchar(10), stats4view varchar(10), stats5view varchar(10), stats6view varchar(10), stats7view varchar(10), statsnum int(10), rulesview varchar(10), standingsnogames varchar(10), pctnum varchar(10), hotcoldnum varchar(10), gamesmaxday int(10), PRIMARY KEY (vars_id))"; mysql_query($sql,$db); echo"Vars table<br><br>"; echo"Inserting default values<br>"; $sql = "INSERT INTO $newstable (news) VALUES ('Welcome to WebLeague<br><br>WebLeague is an automated league system, that makes organizing an online league a piece of cake.<br><br>To put your own news here, go to the news section in your admin panel<br><br>Have fun using WebLeague')"; mysql_query($sql,$db); echo"Inserting news<br>"; $sql = "INSERT INTO $rulestable (rules) VALUES ('Insert your rules by going to the rules section in the admin panel')"; mysql_query($sql,$db); echo"Inserting rules<br>"; $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('blue','#0080FF','#000066', '#FFFFFF', '#000099', '/themes/blue/aim.jpg', '/themes/blue/bottomleft.jpg', '/themes/blue/bottommiddle.jpg', '/themes/blue/bottomright.jpg', '/themes/blue/headerbg.jpg', '/themes/blue/headermenuleft.jpg', '/themes/blue/headermenuright.jpg', '/themes/blue/sideleft.jpg', '/themes/blue/sideright.jpg', '/themes/blue/topleft.jpg', '/themes/blue/topmiddle.jpg', '/themes/blue/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('blue2','#66809A','#29293D', '#FFFFFF', '#444466', '/themes/blue2/aim.jpg', '/themes/blue2/bottomleft.jpg', '/themes/blue2/bottommiddle.jpg', '/themes/blue2/bottomright.jpg', '/themes/blue2/headerbg.jpg', '/themes/blue2/headermenuleft.jpg', '/themes/blue2/headermenuright.jpg', '/themes/blue2/sideleft.jpg', '/themes/blue2/sideright.jpg', '/themes/blue2/topleft.jpg', '/themes/blue2/topmiddle.jpg', '/themes/blue2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('red','#FF0000','#660000', '#FFFFFF', '#990000', '/themes/red/aim.jpg', '/themes/red/bottomleft.jpg', '/themes/red/bottommiddle.jpg', '/themes/red/bottomright.jpg', '/themes/red/headerbg.jpg', '/themes/red/headermenuleft.jpg', '/themes/red/headermenuright.jpg', '/themes/red/sideleft.jpg', '/themes/red/sideright.jpg', '/themes/red/topleft.jpg', '/themes/red/topmiddle.jpg', '/themes/red/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('red2','#9A666C','#3D2929', '#FFFFFF', '#664444', '/themes/red2/aim.jpg', '/themes/red2/bottomleft.jpg', '/themes/red2/bottommiddle.jpg', '/themes/red2/bottomright.jpg', '/themes/red2/headerbg.jpg', '/themes/red2/headermenuleft.jpg', '/themes/red2/headermenuright.jpg', '/themes/red2/sideleft.jpg', '/themes/red2/sideright.jpg', '/themes/red2/topleft.jpg', '/themes/red2/topmiddle.jpg', '/themes/red2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('green','#00FF00','#006600', '#FFFFFF', '#009900', '/themes/green/aim.jpg', '/themes/green/bottomleft.jpg', '/themes/green/bottommiddle.jpg', '/themes/green/bottomright.jpg', '/themes/green/headerbg.jpg', '/themes/green/headermenuleft.jpg', '/themes/green/headermenuright.jpg', '/themes/green/sideleft.jpg', '/themes/green/sideright.jpg', '/themes/green/topleft.jpg', '/themes/green/topmiddle.jpg', '/themes/green/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('green2','#6C9A66','#2D3D29', '#FFFFFF', '#446644', '/themes/green2/aim.jpg', '/themes/green2/bottomleft.jpg', '/themes/green2/bottommiddle.jpg', '/themes/green2/bottomright.jpg', '/themes/green2/headerbg.jpg', '/themes/green2/headermenuleft.jpg', '/themes/green2/headermenuright.jpg', '/themes/green2/sideleft.jpg', '/themes/green2/sideright.jpg', '/themes/green2/topleft.jpg', '/themes/green2/topmiddle.jpg', '/themes/green2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('orange','#FF8000','#662200', '#FFFFFF', '#994000', '/themes/orange/aim.jpg', '/themes/orange/bottomleft.jpg', '/themes/orange/bottommiddle.jpg', '/themes/orange/bottomright.jpg', '/themes/orange/headerbg.jpg', '/themes/orange/headermenuleft.jpg', '/themes/orange/headermenuright.jpg', '/themes/orange/sideleft.jpg', '/themes/orange/sideright.jpg', '/themes/orange/topleft.jpg', '/themes/orange/topmiddle.jpg', '/themes/orange/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('orange2','#9A7E66','#3D3129', '#FFFFFF', '#664444', '/themes/orange2/aim.jpg', '/themes/orange2/bottomleft.jpg', '/themes/orange2/bottommiddle.jpg', '/themes/orange2/bottomright.jpg', '/themes/orange2/headerbg.jpg', '/themes/orange2/headermenuleft.jpg', '/themes/orange2/headermenuright.jpg', '/themes/orange2/sideleft.jpg', '/themes/orange2/sideright.jpg', '/themes/orange2/topleft.jpg', '/themes/orange2/topmiddle.jpg', '/themes/orange2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('purple','#9900FF','#330066', '#FFFFFF', '#660099', '/themes/purple/aim.jpg', '/themes/purple/bottomleft.jpg', '/themes/purple/bottommiddle.jpg', '/themes/purple/bottomright.jpg', '/themes/purple/headerbg.jpg', '/themes/purple/headermenuleft.jpg', '/themes/purple/headermenuright.jpg', '/themes/purple/sideleft.jpg', '/themes/purple/sideright.jpg', '/themes/purple/topleft.jpg', '/themes/purple/topmiddle.jpg', '/themes/purple/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('purple2','#83669A','#32293D', '#FFFFFF', '#664466', '/themes/purple2/aim.jpg', '/themes/purple2/bottomleft.jpg', '/themes/purple2/bottommiddle.jpg', '/themes/purple2/bottomright.jpg', '/themes/purple2/headerbg.jpg', '/themes/purple2/headermenuleft.jpg', '/themes/purple2/headermenuright.jpg', '/themes/purple2/sideleft.jpg', '/themes/purple2/sideright.jpg', '/themes/purple2/topleft.jpg', '/themes/purple2/topmiddle.jpg', '/themes/purple2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('black','#666666','#000000', '#FFFFFF', '#999999', '/themes/black/aim.jpg', '/themes/black/bottomleft.jpg', '/themes/black/bottommiddle.jpg', '/themes/black/bottomright.jpg', '/themes/black/headerbg.jpg', '/themes/black/headermenuleft.jpg', '/themes/black/headermenuright.jpg', '/themes/black/sideleft.jpg', '/themes/black/sideright.jpg', '/themes/black/topleft.jpg', '/themes/black/topmiddle.jpg', '/themes/black/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('yellow','#FFEF00','#635200', '#FFFFFF', '#999900', '/themes/yellow/aim.jpg', '/themes/yellow/bottomleft.jpg', '/themes/yellow/bottommiddle.jpg', '/themes/yellow/bottomright.jpg', '/themes/yellow/headerbg.jpg', '/themes/yellow/headermenuleft.jpg', '/themes/yellow/headermenuright.jpg', '/themes/yellow/sideleft.jpg', '/themes/yellow/sideright.jpg', '/themes/yellow/topleft.jpg', '/themes/yellow/topmiddle.jpg', '/themes/yellow/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('yellow2','#9A9666','#3D3A29', '#FFFFFF', '#666644', '/themes/yellow2/aim.jpg', '/themes/yellow2/bottomleft.jpg', '/themes/yellow2/bottommiddle.jpg', '/themes/yellow2/bottomright.jpg', '/themes/yellow2/headerbg.jpg', '/themes/yellow2/headermenuleft.jpg', '/themes/yellow2/headermenuright.jpg', '/themes/yellow2/sideleft.jpg', '/themes/yellow2/sideright.jpg', '/themes/yellow2/topleft.jpg', '/themes/yellow2/topmiddle.jpg', '/themes/yellow2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('pink','#FF00EF','#660066', '#FFFFFF', '#990099', '/themes/pink/aim.jpg', '/themes/pink/bottomleft.jpg', '/themes/pink/bottommiddle.jpg', '/themes/pink/bottomright.jpg', '/themes/pink/headerbg.jpg', '/themes/pink/headermenuleft.jpg', '/themes/pink/headermenuright.jpg', '/themes/pink/sideleft.jpg', '/themes/pink/sideright.jpg', '/themes/pink/topleft.jpg', '/themes/pink/topmiddle.jpg', '/themes/pink/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('pink2','#9A6696','#3C293D', '#FFFFFF', '#664466', '/themes/pink2/aim.jpg', '/themes/pink2/bottomleft.jpg', '/themes/pink2/bottommiddle.jpg', '/themes/pink2/bottomright.jpg', '/themes/pink2/headerbg.jpg', '/themes/pink2/headermenuleft.jpg', '/themes/pink2/headermenuright.jpg', '/themes/pink2/sideleft.jpg', '/themes/pink2/sideright.jpg', '/themes/pink2/topleft.jpg', '/themes/pink2/topmiddle.jpg', '/themes/pink2/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('greenblue','#00FFEA','#006654', '#FFFFFF', '#009999', '/themes/greenblue/aim.jpg', '/themes/greenblue/bottomleft.jpg', '/themes/greenblue/bottommiddle.jpg', '/themes/greenblue/bottomright.jpg', '/themes/greenblue/headerbg.jpg', '/themes/greenblue/headermenuleft.jpg', '/themes/greenblue/headermenuright.jpg', '/themes/greenblue/sideleft.jpg', '/themes/greenblue/sideright.jpg', '/themes/greenblue/topleft.jpg', '/themes/greenblue/topmiddle.jpg', '/themes/greenblue/topright.jpg')"; mysql_query($sql,$db); $sql = "INSERT INTO $themestable (name, color1, color2, color3, color4, aimthemepic, bottomleftpic, bottommiddlepic, bottomrightpic, headerbgpic, headermenuleftpic, headermenurightpic, sideleftpic, siderightpic, topleftpic, topmiddlepic, toprightpic) VALUES ('greenblue2','#679B97','#293D39', '#FFFFFF', '#446666', '/themes/greenblue2/aim.jpg', '/themes/greenblue2/bottomleft.jpg', '/themes/greenblue2/bottommiddle.jpg', '/themes/greenblue2/bottomright.jpg', '/themes/greenblue2/headerbg.jpg', '/themes/greenblue2/headermenuleft.jpg', '/themes/greenblue2/headermenuright.jpg', '/themes/greenblue2/sideleft.jpg', '/themes/greenblue2/sideright.jpg', '/themes/greenblue2/topleft.jpg', '/themes/greenblue2/topmiddle.jpg', '/themes/greenblue2/topright.jpg')"; mysql_query($sql,$db); echo"Inserting themes<br>"; $sql = "INSERT INTO $varstable (theme, font, fontcolor, headerfont, numgamespage, numplayerspage, statsview, stats1view, stats2view, stats3view, stats4view, stats5view, stats6view, stats7view, statsnum, rulesview, standingsnogames, pctnum, hotcoldnum, gamesmaxday) VALUES ('blue','Arial', '#FFFFFF', 'Arial Black', '20', '30', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', '10', 'yes', 'no', '10', '5', '2')"; mysql_query($sql,$db); echo"Inserting vars<br><br>"; echo"Done."; ?> Once again... it says its done when i execute the code in the browser but is not inserting anything into my database. Weird... if (($update_avatar1 == 'http://images.toxicpets.co.cc/vPets/Acara11.gif') OR ($update_avatar1 == 'http://images.toxicpets.co.cc/vPets/Aisha5.gif')) { mysql_query("UPDATE avatar SET avatar = '$update_avatar1' WHERE username = '$username' AND game = '$game'") or die ("Database error: ".mysql_error()); mysql_query("INSERT INTO avatar ($update_avatar1 WHERE id = '$userid')"); This is an avatar System But It Is Not Inserting Into The Database Hi guys..... I'm having a problem that I've been tearing my hair out over for way too long. I'm hoping that some of you may be able to help me or at least point me in the right direction. I'm using MySQL 5.0.91 (via PHPmyAdmin from GoDaddy). This query should basically grab the data from the Facebook API and insert it into the database. It's not doing that. After inserting the data, it queries the database, and redirects the user to their profile page (USERNAME.php). Because there is no data in the database for that user, it has no idea what their username is, so it redirects them to ".php"....yes, that is "[dot]php". I'm not entirely sure how to debug this either. I've tried a few var_dump()'s with not much luck. Is there a specific order in which this stuff needs to be in? Maybe that's the problem, so I'm also including a screenshot from PHPmyAdmin of the database table. Here's the code: // user not in db, insert details if(!empty($user)){ $apiGet = array( 'method' => 'users.getinfo', 'uids' => $uid, 'fields' => 'uid, name, first_name, last_name, pic_square, pic_big, sex, email, birthday_date, activities, interests, status, about_me' //theses are the fields it pulls from the Facebook API ); // create array to hold returned values $fbi = $facebook->api($apiGet); // insert details $iString = "oauth_provider, oauth_uid, username, name, first_name, last_name, sex, pic_big, email, joined, lastLogon, birthday_date, user_activities, user_interests, user_status, user_about_me"; $iArray = array(); //the following are the values of the fields array_push($iArray,'facebook'); array_push($iArray,$user['id']); array_push($iArray,$user['name']); array_push($iArray,$fbi[0]['name']); array_push($iArray,$fbi[0]['first_name']); array_push($iArray,$fbi[0]['last_name']); array_push($iArray,$fbi[0]['sex']); array_push($iArray,$fbi[0]['pic_big']); array_push($iArray,$fbi[0]['email']); array_push($iArray,time()); array_push($iArray,time()); array_push($iArray,$fbi[0]['birthday_date']); array_push($iArray,$fbi[0]['user_activities']); array_push($iArray,$fbi[0]['user_interests']); array_push($iArray,$fbi[0]['user_status']); array_push($iArray,$fbi[0]['user_about_me']); var_dump($email); $db->insert('users',$iArray,$iString); $where = "oauth_uid = '{$uid}'"; $db->select('*','users',$where); $result = $db->getResult(); // the next line creates a profile page. After that, there are lines that point the user to that page. createProfile($result['username']); I've added some comments to it to articulate what is going on. Thanks in advance! Alex I have these two files and I need to solve the problem that I need the user data in the role column to be taken when logging in. I have written it so that the data can be extracted from the database, but it does not work for me that it is “forwarded” from process.php to admin.php . Please don’t know what the error is that the admin.php file doesn’t want to load $ _SESSION['Role'] from process.php ? Thanks to everyone for helping and here is the code: process.php <?php require_once('connect.php'); session_start(); if(isset($_POST['Login'])) { if(empty($_POST['Username']) || empty($_POST['Password'])) { header("location:index.php?Empty= Please Fill in the Blanks"); } else { $query="select * from role_test where Username='".$_POST['Username']."' and Password='".md5($_POST['Password'])."'"; $result=mysqli_query($con,$query); if(mysqli_fetch_assoc($result)) { $_SESSION['User']=$_POST['Username']; while($row = mysqli_fetch_array($result) ){ $_SESSION['Role']=$row['role']; } header("location:admin.php"); } else { header("location:index.php?Invalid= Please Enter Correct User Name and Password "); } } } else { echo 'Not Working Now Guys'; } ?>
admin.php <?php session_start(); if(!(isset($_SESSION['User']))) { header("Location: index.php"); exit(0); } ?> <!DOCTYPE html> <html> <head> <title>Role</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <?php $_SESSION['Role']=$role; echo $role; ?> </body> </html>
I am creating a music blogging site however the main page will only show one video the code is below anyone have any ideas? " <?php //open database $connect = mysql_connect("******","username","password") or die("Not connected"); mysql_select_db("collegebooxboox") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'Title' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'Content' field in the table $messsage = mysql_result($result,$loops,"message"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz. $link </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> " I'm not sure I know how to explain what I want to allow you to understand. I'm working on a ventilation app that has different fan sizes. In the input php file I have a dropdown list that's populated by what's in the database. I'd like a results page that lists the fan size and number of each size and the cfm's each fan kicks out. the problem is that I don't know how to do anything with it other than hard code it. What I'd like, is for it to also pull all of the fan sizes and list them, that way the database can be fluid. This is the code I'd like to replace with some sort of loop. //9" fan $results = mysql_query("SELECT * FROM fan WHERE size=9", $link); while ($row = mysql_fetch_array($results)) { $capacity9 = $row['capacity']; }; //--------------------------------------------------------- //10" fan $results = mysql_query("SELECT * FROM fan WHERE size=10", $link); while ($row = mysql_fetch_array($results)) { $capacity10 = $row['capacity']; }; //--------------------------------------------------------- //14" fan $results = mysql_query("SELECT * FROM fan WHERE size=14", $link); while ($row = mysql_fetch_array($results)) { $capacity14 = $row['capacity']; }; //--------------------------------------------------------- //16" fan $results = mysql_query("SELECT * FROM fan WHERE size=16", $link); while ($row = mysql_fetch_array($results)) { $capacity16 = $row['capacity']; }; //--------------------------------------------------------- //18" fan $results = mysql_query("SELECT * FROM fan WHERE size=18", $link); while ($row = mysql_fetch_array($results)) { $capacity18 = $row['capacity']; } //--------------------------------------------------------- //20" fan $results = mysql_query("SELECT * FROM fan WHERE size=20", $link); while ($row = mysql_fetch_array($results)) { $capacity20 = $row['capacity']; }; //--------------------------------------------------------- //24" fan $results = mysql_query("SELECT * FROM fan WHERE size=24", $link); while ($row = mysql_fetch_array($results)) { $capacity24 = $row['capacity']; }; //--------------------------------------------------------- //36" fan $results = mysql_query("SELECT * FROM fan WHERE size=36", $link); while ($row = mysql_fetch_array($results)) { $capacity36 = $row['capacity']; }; Hi there I would be most grateful is someone could tell me why my data is not being entered into my database and not responding with an email confirmation link. Thanks in advance. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <? include('config.php'); // table name $tbl_name="temp_members_db"; // Random confirmation code $confirm_code=md5(uniqid(rand())); // values sent from form $name=$_POST['name']; $email=$_POST['email']; $country=$_POST['country']; // Insert data into database $sql="INSERT INTO $tbl_name(confirm_code,name,email,password,country) VALUES('$confirm_code','$name','$email','$password','$country')"; $result=mysql_query($sql); // if suceesfully inserted data into database, send confirmation link to email if($result){ // ---------------- SEND MAIL FORM ---------------- // send e-mail to ... $to=$email; // Your subject $subject="Your confirmation link here"; // From $header="from: your name <your email>"; // Your message $message="Your Comfirmation link \r\n"; $message.="Click on this link to activate your account \r\n"; $message.="http://www.yourweb.com/confirmation.php?passkey=$confirm_code"; // send email $sentmail = mail($to,$subject,$message,$header); } // if not found else { echo "Not found your email in our database"; } // if your email succesfully sent if($sentmail){ echo "Your Confirmation link Has Been Sent To Your Email Address."; } else { echo "Cannot send Confirmation link to your e-mail address"; } ?> </body> </html> I am having trouble pulling a youtube embedded code from my database. Everything else comes out fine however it just doesnt pull anything out where the embedded code is supposed to be. Any ideas I put the code below. All help would be greatly appreciated, also if anyone is feeling generous and would like to help me some more please message me I have a couple other small questions. Code: [Select] <?php //open database $connect = mysql_connect("Database","name","password") or die("Not connected"); mysql_select_db("database") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'Title' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'Content' field in the table $messsage = mysql_result($result,$loops,"message"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz. </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> Hello, I recently came upon this website and I want to implement something similar. The 'remove' box is what I would like to do with PHP. I have no idea where to start. I would like to be able to search through my database, select one of its components and add it to that window. Within that window I would also like to be able to remove it. Does anyone know where I should go from there? here is the site: http://www.sealandserpent.org/schedgen/schedulegenerator.php hello. please could someone help me with this conundrum im trying to pull my content dynamically. im almost there but im stuck with some code. so i have a layout with 3 columns and in each column i have a place holder. ph01, ph02, ph03 each page has its own id and depending on what the page id is i what to pull different elements into the 3 placeholders. so for this code in the database i have the following: table name: placeholders pages_id = page id ph_number = placeholder number contElements_id = element ids id pages_id ph_number contElements_id 1 1 1 1, 2, 3 2 1 2 4, 5, 6 3 1 3 7, 8, 9 table name: contelements name = name of the element id name 1 E1 2 E2 3 E3 4 E4 5 E5 6 E6 7 E7 8 E8 9 E9 SO, page_ID=1 has 3 placeholders and they should show: ph01 should display = E1, E2, E3 ph02 should display = E4, E5, E6 ph03 should display = E7, E8, E9 this is the code im trying to put together. on the page im using this include function in the left, center and right columns. Code: [Select] $phNo = "1"; echo include_admin_contElements($phNo, $pageID); $phNo = "2"; echo include_admin_contElements($phNo, $pageID); $phNo = "3"; echo include_admin_contElements($phNo, $pageID); now this is where the problem is.... i think in the function file i have this but its a mess.. Code: [Select] function include_admin_contElements($phNo, $pageID){ $PH = Placeholders::find_all(); foreach ($PH as $PHs){ $PHid = $PHs->id; $PHpid = $PHs->pages_id; $PHce = $PHs->contElelments_id; $PHn = $PHs->ph_number; if($pageID == $PHpid){ $CE = Contelements::find_by_PHce($PHce); foreach ($CE as $CEs){ echo $CEid = $CEs->id; echo $CEname = $CEs->name; } } } } - so the idea is i get $phNo, $pageID from the page, - then find all the placeholders in the database Quote Placeholders::find_all(); - then if the $pageID is the same as the $PHpid in the placeholder database Quote if($pageID == $PHpid){ get the content elents for that page. - then i want to get the elements that belong to that page using Quote Contelements::find_by_PHce($PHce); but that does not work Code: [Select] public static function find_by_PHce($PHce=0){ $sql = "SELECT * FROM ".self::$table_name." WHERE id=".$PHce.""; $result_array = self::find_by_sql($sql); return $result_array; } anyway... im stuck. this code doesn't even seperate the 3 different placeholders. it needs a more experienced eye.. its a mess please help thanks ricky Hi guys, I am building a website with basic e-commerce functionality, using php and using xampp to test it. I am having issues when attempting to submit a quantity (into table orders) using a form and validating it against an existing value (from table products), giving a response on whether there is sufficient quantity in the second table. I am then, in another page (same one performing the validations), attempting to then show a result based on the initial quantity entered, with a summary of the order details and calculation of the quantity * price to display a total as well. This has all been built from scratch, however I may have taken the wrong approach for these two pages... any assistance or insight as to where I am going wrong would be greatly appreciated. Here is the page I have placed the products, existing quantity and a text field they are able to enter their desired quantity: Code: [Select] <?php session_start(); require_once "../database/db.php"; require_once "../includes/functions.php"; $page_title = 'Product Catalogue'; include_once "header.php"; $conn = mysqli_connect ($dbhost, $dbuser, $dbpassword, $dbname); $query = "SELECT * from products"; $result = mysqli_query($conn, $query); if (!$result) { include_once "header.php"; die ("Error, could not query the database"); } else { $rows = mysqli_num_rows($result); if ($rows>0) { while ($row = mysqli_fetch_array($result)) { ?> <form> <br /> <br /> <br /> <table> <tr> <td style="width: 200px">Product Code:</td> <td><?php echo $row['ProductCode']; ?></td> </tr> <tr> <td>Product Name:</td> <td><?php echo $row['ProductName']; ?></td> </tr> <tr> <td>Product Description:</td> <td><?php echo $row['ProductDescription']; ?></td> </tr> <tr> <td>Product Colour:</td> <td><?php echo $row['ProductColour']; ?></td> </tr> <tr> <td>Product Price:</td> <td>$<?php echo number_format($row['ProductPrice'],2); ?></td> </tr> <tr> <td>Product Image:</td> <td><img src="<?php echo $row['ProductImagePath']?>"/></td> </tr> <tr> <td>Quantity in Stock:</td> <td><?php echo $row['ProductQuantity']; ?></td> </tr> </table> </form> <form method="post"action="processQuantity.php"> <table> <tr> <td style="width: 200px">Quantity:</td> <td><input type="number" name="Quantity" id="Quantity" value="<?php if (isset ($quantity)) echo $quantity; ?>"size = "20" /></td> <td><input type="submit" name="Purchase" value= "Purchase" /></td> </tr> </table> </form> <hr /> <?php } include "footer.html"; } } ?> Here is the page that I am using to validate the data as well as show a result based on the entered amount: Code: [Select] <?php session_start(); require_once "../includes/functions.php"; require_once "../database/db.php"; $quantity = $_POST['Quantity']; $productquantity = $_POST['ProductQuantity']; $orderid = $_POST['orderid']; $productcode = $_POST['productcode']; $productprice = $_POST['productprice']; $total = $quantity * $productprice; $error_message = ''; if ($error_message != '') { include_once "displayCatalogue-PlaceOrder.php"; exit(); $conn = mysqli_connect ($dbhost, $dbuser, $dbpassword, $dbname); if (!$conn) { echo "Error"; } else { //sanitise date $scustomerid = sanitiseMySQL($customerid); $sproductcode = sanitiseMySQL($productcode); $squantity = sanitiseMySQL($quantity); $sproductprice = sanitiseMySQL($productprice); $sorderdate = sanitiseMySQL($orderdate); $query = "select productquantity from products where productcode = '$sproductcode'"; $result = msqli_query ($conn, $query); $productquantity = mysqli_num_rows($result); if ($quantity < $productquantity) { $error_message = "You cannot order more than what is currently instock"; include_once "displayCatalogue-PlaceOrder.php"; exit (); } else { $row = mysqli_fetch_row($result); $query = "INSERT into orders (customerid, productcode, quantity, productprice, orderdate) values ('$scustomerid', $sproductcode', '$squantity', '$sproductprice', '$sorderdate')"; $result = mysqli_query($conn, $query); $row = mysqli_affected_rows($conn); if ($row > 0) { include "header.php";?> <h3>Order Confirmation</h3> <p>Thank you, your order is now being processed.</p> <table> <tr> <td style="width: 200px">Order Number:</td> <td><?php echo $orderid; ?></td> </tr> <tr> <td>Product Code:</td> <td><?php echo $productcode; ?></td> </tr><tr> <td>Quantity:</td> <td><?php echo $quantity; ?></td> </tr> <tr> <td>Price:</td> <td><?php echo $productPrice; ?></td> </tr> <tr> <td>Total Cost of Order:</td> <td><?php echo $total; ?></td> </tr> </table> <?php include "footer.html"; } else { $error_message ="Error placing your order, please try again"; include "displayCatalogue-PlaceOrder.php"; exit(); } } } } //this is used to validate the quantity entered against what is available in the database ?> ok, so an android app I am working on needs to read from an online database and display the results dynamically. This works fine, but then when I press a button in my UI, I need it to add a new row into the same database. When I test the app and click the button, it doesn't throw any exceptions or anything and once it finsihes the process goes right back to letting me do w/e I need on the UI. When I test the PHP script through the browser, it goes through all the echos I have in the script and reaches the bottom of the script no problem, however it doesn't add the row... I am at a loss here... Maybe you all can help. Here is my PHP file: [syntax="php"] <?php mysql_connect("localhost","XXXXX","XXXXX"); mysql_select_db("bonafie0_mm"); echo "connected to database"; mysql_query("INSERT INTO Comments (user, comment) VALUES ('".$_REQUEST['user']."', ".$_REQUEST['comment']."')"); echo "done. "; mysql_close(); ?> [/syntax] and for those of you who are experienced with java and/or the android SDK, here is my android code: [syntax="java"] private void postComment() { String user = editName.getText().toString(); String comment = editComment.getText().toString(); OutputStream os = null; ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(); nameValuePair.add(new BasicNameValuePair("user", user)); nameValuePair.add(new BasicNameValuePair("comment", comment)); try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(ROTM_POST_URL); post.setEntity(new UrlEncodedFormEntity(nameValuePair)); HttpResponse response = client.execute(post); } catch(IOException e) { Toast.makeText(RoTM.this, "Unable to post comments", Toast.LENGTH_SHORT).show(); } editName.setText(""); editComment.setText(""); } [/syntax] Any ideas? I posted this on the only two reputable android dev forums I could find, but no one has been able to help me as of yet... Since I am fairly confident in my java abilities, I figured my problem probably lies in my PHP code. Hi, first time poster here. Pretty new to PHP. Yesterday my PHP code was inserting into my MySQL database fine and as of today it isn't inserting anything into the database. Is there any common error in my PHP code that i'm forgetting? I'm using XAMPP. I think I may be posting in the wrong area. Also any pointers on my code would be appreciated. Below is my code: <html> <head> <title> Sign up! </title> </head> <body> <form id = "signup" method = "post" action = "<?php echo $_SERVER['PHP_SELF'];?>" onsubmit= "return formValidator()"> Please enter your name: <input type = "text" id = "name"> <br /> Please enter the password you would like: <input type ="password" id = "password"/> <br /> Please enter your Date Of Birth : <select type ="text" size = "1" id = "dayofbirth"/> <option value = "1"> 01 </option> <option value = "2"> 02 </option> <option value = "3"> 03 </option> <option value = "4"> 04 </option> <option value = "5"> 05 </option> <option value = "6"> 06 </option> <option value = "7"> 07 </option> <option value = "8"> 08 </option> <option value = "9"> 09 </option> <option value = "10"> 10 </option> <option value = "11"> 11 </option> <option value = "12"> 12 </option> <option value = "13"> 13 </option> <option value = "14"> 14 </option> <option value = "15"> 15 </option> <option value = "16"> 16 </option> <option value = "17"> 17 </option> <option value = "18"> 18 </option> <option value = "19"> 19 </option> <option value = "20"> 20 </option> <option value = "21"> 21 </option> <option value = "22"> 22 </option> <option value = "23"> 23 </option> <option value = "24"> 24 </option> <option value = "25"> 25 </option> <option value = "26"> 26 </option> <option value = "27"> 27 </option> <option value = "28"> 28 </option> <option value = "29"> 29 </option> <option value = "30"> 30 </option> <option value = "31"> 31 </option> </select> <select type ="text" size = "1" id = "monthofbirth"/> <option value = "1">January</option> <option value = "2">February</option> <option value = "3">March</option> <option value = "4">April</option> <option value = "5">May</option> <option value = "6">June</option> <option value = "7">July</option> <option value = "8">August</option> <option value = "9">September</option> <option value = "10">October</option> <option value = "11">November</option> <option value = "12">December</option> </select> <select type ="text" size = "1" id = "yearofbirth"/> <option value = "1994">1994</option> <option value = "1993">1993</option> <option value = "1992">1992</option> <option value = "1991">1991</option> <option value = "1990">1990</option> <option value = "1989">1989</option> <option value = "1988">1988</option> <option value = "1987">1987</option> <option value = "1986">1986</option> <option value = "1985">1985</option> <option value = "1984">1984</option> <option value = "1983">1983</option> <option value = "1982">1982</option> <option value = "1981">1981</option> <option value = "1980">1980</option> <option value = "1979">1979</option> <option value = "1978">1978</option> <option value = "1977">1977</option> <option value = "1976">1976</option> <option value = "1975">1975</option> <option value = "1974">1974</option> <option value = "1973">1973</option> <option value = "1972">1972</option> <option value = "1971">1971</option> <option value = "1970">1970</option> <option value = "1969">1969</option> <option value = "1968">1968</option> <option value = "1967">1967</option> <option value = "1966">1966</option> <option value = "1965">1965</option> <option value = "1964">1964</option> <option value = "1963">1963</option> <option value = "1962">1962</option> <option value = "1961">1961</option> <option value = "1960">1960</option> <option value = "1959">1959</option> <option value = "1958">1958</option> <option value = "1957">1957</option> <option value = "1956">1956</option> <option value = "1955">1955</option> <option value = "1954">1954</option> <option value = "1953">1953</option> <option value = "1952">1952</option> <option value = "1951">1951</option> </select> <br /> Please enter your e-mail address: <input type ="text" id = "email"/> <br /> Please enter your address: <input type ="text" id = "address"/> <br /> Please enter your city: <input type ="text" id = "city"/> <br /> Please enter your postcode <input type ="text" id = "postcode"/> <br /> Please enter your telephone number: <input type ="text" id = "telephoneno"/> <br /> <input type= "submit" id = "submit" value ="Submit me!"/> </body> <?php $conn = mysql_connect("localhost", "root", "") or die("cannot connect server "); mysql_select_db("nightsout") or die ("cannot find database"); if(isset($_POST['submit'])) { $username = $_POST['name']; $password = $_POST['password']; $day = $_POST['dayofbirth']; $month = $_POST['monthofbirth']; $year = $_POST['yearofbirth']; $date = ($year.'-'.$month.'-'.$day); $email = $_POST['email']; $address = $_POST['address']; $city = $_POST['city']; $postcode = $_POST['postcode']; $telephoneno = $_POST['telephoneno']; $duplicate = mysql_query("SELECT * FROM users WHERE emailaddress = '$email'", $conn) or die('Cannot Execute:'. mysql_error()); if(mysql_num_rows($duplicate) == 0) { mysql_query("INSERT INTO users (username, password, DOB, emailaddress, address, city, postcode, telephonenumber) VALUES ('{$username}', '{$password}', '{$date}', '{$email}' ,'{$address}', '{$city}', '{$postcode}', '{$telephoneno}')"); }else if(mysql_num_rows($duplicate) > '1') { ?> <p>This E-mail address already exists please use another one or <a href="home.php">Login.</a> </p> <?php } } mysql_close($conn); ?> Many thanks. |