PHP - Inserting Values Via Php To Sql Database
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 ?> Similar TutorialsIs it possible to use for loop to insert values into database using for loop? Or what would be the another way to insert these values into the database if the number of values being entered differs from one time to another? Here is basically what I am trying to do: mysql_query("INSERT INTO MaxMillionsNum SET Day='$weekday', DrawDate='$CompleteDate', DateTime='$timestamp', for($i=1; $i<=$SetNumber; $i+=1){ for($j=0; $j<7; j+=1){ $NumberName="Number".$i.$v[$j];//Generating name of database field $$NumberName=$Match[0][$j];//Here I would store the $Match value into the fieldname name created above } } Tries='$RunCounter'"); Hello there,
I'm really new at PHP and I've been reading several beginner tutorials so please accept my apologies for any stupid questions I may ask along the way.
I've gotten as far as installing XAMPP, set up a database plus PHP form and I'm struggling to figure out how to insert values from an array into my database.
I've learnt the code in one particular way (see beginner tutorials) so I was wondering if you could help me keeping this in mind. I know there'll be a million better ways to do what I'm doing but I fear I will be bamboozled with different code or differently structured code.
Anyway the tutuorials I'm reading don't see to cover how I can insert an array of values into my database, just singular values.
In the attached file, I have 10 rows of 2x text inputs (20 text inputs total). Each row allows the user to enter a CarID and CarTitle. I've commented out the jQuery which validates the inputs so I can build a rudimentary version of this validation with PHP.
I thought that because the line $sql="INSERT INTO carids_cartitles (CarID, CarTitle) VALUES ($id, $title)"; is inside the foreach, means that for each pair of values from the form it'd insert to the database.
It doesn't do this. If I enter two or more CarIDs and CarTitles, only one pair of values gets saved to the database.
I'm sorry if I haven't explained this well enough, any questions please let me know.
Many thanks for your help in advance.
Attached Files
form.php 4.43KB
5 downloads I have posted one set of values into my database and it worked fine but when i input another set they wont go inside unless i changes the value of the primary index colum. I want to be able to insert a new values regardless of the primary index value. Any idears...? Hello all Ok here is the problem... I want when a user inputs the requested data to the text fields , the script to insert those data in the prope table depending on the choise the user does by choosing one option from the drop down menu. Below is the php code (apparently not working) $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } $site_type = $_REQUEST['category_selection']; if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Web_Sites")) { $insertSQL = sprintf("INSERT INTO partner_sites (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Blogs")) { $insertSQL = sprintf("INSERT INTO partner_blogs (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "link_submission") && ($site_type = "Directories")) { $insertSQL = sprintf("INSERT INTO partner_directories (url, url_title, anchor_text, `description`, webmaster_name, webmaster_email, category) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['url_field'], "text"), GetSQLValueString($_POST['title_field'], "text"), GetSQLValueString($_POST['anchor_field'], "text"), GetSQLValueString($_POST['description_field'], "text"), GetSQLValueString($_POST['webmaster_nane_field'], "text"), GetSQLValueString($_POST['webmaster_email_field'], "text"), GetSQLValueString($_POST['category_selection'], "text")); mysql_select_db($database_content_conn, $content_conn); $Result1 = mysql_query($insertSQL, $content_conn) or die(mysql_error()); } And the html form <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="link_submission" id="link_submission"> <table width="630" border="0" align="center" cellpadding="5" cellspacing="5"> <tr> <td width="76">URL:*</td> <td width="519"><label for="url_field"></label> <span id="sprytextfield1"> <label for="url_field"></label> <input name="url_field" type="text" id="url_field" size="50" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td> </tr> <tr> <td>Anchor Text:*</td> <td><label for="anchor_field"><span id="sprytextfield2"> <input type="text" name="anchor_field" id="anchor_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>URL Title:*</td> <td><label for="title_field"><span id="sprytextfield3"> <input type="text" name="title_field" id="title_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>Description:*</td> <td><span id="sprytextarea1"> <label for="description_field"></label> <textarea name="description_field" id="description_field" cols="45" rows="3"></textarea> <span id="countsprytextarea1"> </span><span class="textareaRequiredMsg">A value is required.</span><span class="textareaMaxCharsMsg">Exceeded maximum number of characters.</span></span></td> </tr> <tr> <td>Webmaster Name:*</td> <td><label for="textfield2"><span id="sprytextfield4"> <input type="text" name="webmaster_nane_field" id="webmaster_nane_field" /> <span class="textfieldRequiredMsg">A value is required.</span></span></label></td> </tr> <tr> <td>Webmaster E-mail:*</td> <td><label for="textfield3"><span id="sprytextfield5"> <input name="webmaster_email_field" type="text" id="webmaster_email_field" size="40" /> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></label></td> </tr> <tr> <td>Category:*</td> <td><span id="spryselect1"> <label for="category_selection"></label> <select name="category_selection" id="category_selection"> <option>Select An Option</option> <option value="Web_Sites">Web Sites</option> <option value="Blogs">Blogs</option> <option value="Directories">Directories</option> </select> <span class="selectRequiredMsg">Please select an item.</span></span></td> </tr> <tr> <td> </td> <td><label for="select"></label> <input type="submit" name="button" id="button" value="Url Submission" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="link_submission" /> </form> Im begging for your help..... Hey guys, I am kind of new to php but I am stuck on this question. I have a mySQL database and table set up called members. I have some data in the table and I want to be able to add certain things to a paticular row in the table based off the ID number of the row. One of the values of the table is an auto incremeted ID number. I want to add a text value called message to a specified ID number. How do I go about doing that. I have this code already but it doesn't seem to work. Code: [Select] $sql = "INSERT INTO members (message) VALUES ('$_POST[message]',(SELECT id FROM members WHERE id='$_POST[id]'))"; Any Ideas? Thanks I want to take data from one table and insert it into another in the same database, the problem is the two tables have different values so it wouldn't be as simple as using an INSERT INTO script. From table 1 I want to extract a row ID as well as a field called systems. I then want to insert that into the second table which is structured, Id (null) Name (games) Value (the data given from Systems in the other) ID2 (the ID from the other table) Category (news) Any ideas how I can go about this? Hi People i'm a newb at this so bare with me but i currently have a php file called Newkpi.php which has a select statement in. this selects data from a table called "StaffList". this then populates the page with a html table with 14 records (this will increase/decrease over time) i then have some extra text boxes to enter more detail into like service amaount service date and so on. when i click the submit button i want it to cycle through each row and insert the data into a separate table called "Services". however i cannot for the life of me get this to work and need some help with it. people find attached the code for Newkpi and see if you can help me with this. in total i want it to take the names from stafflist and populate Services with the names and the extra detail which is entered on the page Much Thanx in advance SLOWIE So first of all, I have a confession, I used Dreamweaver to take care of all my database work. Pheww. Now that I got that of my chest, I am having problems, not only with my lack of experience working with databases, but with my script also. I need to insert multiple checkbox values into my database into the same cell. So I have searched around and I thought I had found a fairly good approach, but with Dw's hodgepodge of overcomplicated mess, I am finding problems integrating it. The error I am getting post submission is "Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\gov\ballot.php on line 10 Column 'involvement' cannot be null" So if you would, could you debug my script and give me some instruction along to way so that I can learn a little something too? Here is my script: <?php require_once('Connections/ballot.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "Ballot")) { $insertSQL = sprintf("INSERT INTO votes (`first`, `last`, gender, grade, involvement, schedule, party, `time`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['first'], "text"), GetSQLValueString($_POST['last'], "text"), GetSQLValueString($_POST['gender'], "text"), GetSQLValueString($_POST['grade'], "text"), GetSQLValueString($_POST['involvement'], "text"), GetSQLValueString($_POST['schedule'], "text"), GetSQLValueString($_POST['party'], "text"), GetSQLValueString($_POST['time'], "text")); mysql_select_db($database_ballot, $ballot); $Result1 = mysql_query($insertSQL, $ballot) or die(mysql_error()); $insertGoTo = "thanks.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_ballot, $ballot); $query_Recordset1 = "SELECT * FROM votes"; $Recordset1 = mysql_query($query_Recordset1, $ballot) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!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>Please Place your Vote Below</title> </head> <body style="background-image:url(images/bg.jpg); background-repeat:repeat-x; background-color:#000000;"> <table align="center" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" border="0"> <tr><td> <div style="border:thin; border-color:000000; border-style:groove; width:700px; background-color:ffffff;"> <div align="center"><a href="index.php"><img src="images/header.jpg" alt="Mock Elections 2010" /></a></div> <div style="margin:10px; margin-top:30px;"> Before continuing to vote, in order to count your vote, we ask that you please ensure you are adhereing to the following guidelines: </div> <div style="margin:30px"> <p>- When putting your name, remember to put your full legal name. NO nicknames.<br /> - Be sure that all your information is valid otherwise your vote will not be counted. <br /> </p> </div> <div style="margin-left:150px; margin-right:150px; margin-top:50px;"> <form action="<?php echo $editFormAction; ?>" method="POST" name="Ballot"> First Name: <input type="text" name="first" /><br /> Last Name: <input type="text" name="last" /><br /> <div>Gender: <label> Male <input type="radio" value="Male" name="gender" /></label> <label>Female <input type="radio" value="Female" name="gender" /></label> </div> Grade: <select name="grade"> <option selected="selected"> </option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="Teacher">Teacher</option> <option value="Staff">Staff</option> </select><br /> <div>Involvement: <label> <input type="checkbox" name="involvement[]" value="Athletics" id="involvement_0" /> Athletics</label> <label> <input type="checkbox" name="involvement[]" value="Co-Curricular" id="involvement_1" /> Co-Curricular</label> <label> <input type="checkbox" name="involvement[]" value="Clubs" id="involvement_2" /> Clubs</label> </div> <div>Schedule: <label><input type="radio" value="C4" name="schedule" />C4</label> <label><input type="radio" value="All Day" name="schedule" />All Day Hauser Student</label> </div> <div>Party: <label><input type="radio" value="PokePartay" name="party" />PokePartay</label> <label><input type="radio" value="Equilibrium" name="party" />Equilibrium Party</label> </div> <br /> <input type="Submit" value="Submit" /> <input type="hidden" value="<?php $tz = new DateTimeZone('America/Indianapolis'); $date = new DateTime('now', $tz); echo $date->format('m-d-Y h:i:s') . "\n"; ?>" name="time" /> <?php if (isset($_POST['submit'])) { $involvements = $_POST['involvement']; foreach($involvements as $involvement) { $query2 = "INSERT INTO votes (involvement) VALUES ('$involvement')"; $result2 = mysql_query($ballot, $query2) or die(mysql_error()); } } ?> <input type="hidden" name="MM_insert" value="Ballot" /> </form> </div> <br /> <br /> <br /> <br /> </div> </td> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Thanks, Philip Ulrich Hello, I am currently trying to learn php from a book called PHP for Absolute Beginners where it teaches you how to build a blog by "hand". All nice and good until i got to the submit an entry and save it to my database process. I'm using PDO with INSERT prepared statement like so, from a separate update.inc.php file: Code: [Select] $sql = "INSERT INTO entries (title, entry) VALUES (?,?)"; $stmt = $db->prepare($sql); $stmt -> execute(array($title, $entry)); $stmt ->closeCursor(); I have attached screenshots of my database in mysql. What could be the problem? Remeber I am an "ABSOLUTE BEGINNER" :p . Thank you $username = $_POST['uid']; $email = $_POST['mail']; $password = $_POST['pwd']; $passwordRepeat = $_POST['pwd-repeat']; $date = $_POST['date2']; $stream = $_POST['relationship']; $sql1 = "INSERT INTO users (uidUsers, emailUsers, pwdUsers, relationship) VALUES (?, ?, ?, ?);"; $sql2 = "INSERT INTO Family1 (username, application_filed, relationship) VALUES (?, ?, ?);"; $sql3 = "INSERT INTO Family2 (username, application_filed, relationship) VALUES (?, ?, ?);"; mysqli_query($sql1, $conn); mysqli_query($sql2, $conn); mysqli_query($sql3, $conn); $stmt = mysqli_stmt_init($conn); if (!mysqli_stmt_prepare($stmt, $sql2)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) ($username==$_SESSION['uid'] and $stream =='nursing'); mysqli_stmt_execute($stmt); } if (!mysqli_stmt_prepare($stmt, $sql3)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { mysqli_stmt_bind_param($stmt, "sss", $username, $date, $stream); $result = mysqli_stmt_get_result($stmt); if ($row = mysqli_fetch_assoc($result)) ($username==$_SESSION['uid'] and $stream =='doctoral'); mysqli_stmt_execute($stmt); } if (!mysqli_stmt_prepare($stmt, $sql1)) { header("Location: ../signup.php?error=sqlerror"); exit(); } if (!mysqli_stmt_prepare($stmt, $sql1)) { header("Location: ../signup.php?error=sqlerror"); exit(); } else { $hashedPwd = password_hash($password, PASSWORD_DEFAULT); mysqli_stmt_bind_param($stmt, "ssss", $username, $email, $hashedPwd, $stream); mysqli_stmt_execute($stmt); header("Location: ../signup.php?signup=success"); exit(); I was wondering if someone could point me in the right direction. I have this code. They idea I had behind it is to insert values into different tables depending on variables being passed. So when user fills out a form and selects $stream="nursing" I want results to go to table 'users' and 'Family1', but not 'Family2' table. and if user selects $stream='doctoral' results should go to table 'users' and  'Family2', and not go to 'Family1' But with my query I get results go to both table and also users table. And there is no restriction to what users selects, variable $stream being passed no matter what it is. Is this the wrong way to go here? Did I completely mess up the logic? 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... 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 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 after cloasing connection of database i still got the values form database. Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; if(!$result){ echo "cont fetch data"; }else{ $row= mysql_fetch_array($result); echo "id".$row[0]."usrname".$row[1]."passwped".$row[2]."date".$row[3]."time".$row[4]; } // echo "<html>"; //echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; // echo "<thead>"; // echo"<tr>"; // echo "<th>"; // echo ID; // echo"</th>"; // echo" <th>";echo Username; echo"</th>"; // echo"<th>";echo Password; echo"</th>"; // echo"<th>";echo Last_logged_date; echo "</th>"; // echo "<th>";echo Last_logged_time; echo "</th>"; // echo" </tr>"; // echo" </thead>"; // echo" <tbody>"; //while($row= mysql_fetch_array($result,MYSQL_BOTH)){ // echo "<tr>"; // echo "<td>"; // echo $row[0]; // echo "</td>"; // echo "<td>"; // echo $row[1]; // echo "</td>"; // echo "<td>"; // echo $row[2]; // echo "</td>"; // echo "<td>"; // echo $row[3]; // echo "</td>"; // echo "<td>"; // echo $row[4]; // echo "</td>"; // echo "</tr>"; // } // echo" </tbody>"; // echo "</table>"; // echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values from doatabase session is destroyed".$_SESSION['admin']; ?> session is destroyed but database connection is not closed. thanks Hey all Im working on an assignment for school and currently I am trying to inser the variable $uid which currently = 2.. But for someone reason when the post happens it inserts a 0 instead of a 2. Here is my insert Code: [Select] mysql_query( "INSERT INTO blog_posts (title, post, author_id, date_posted) ". "VALUES ('$btitle', '$bpost', '$uid', CURDATE())" ); information 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] im trying to write a script takes an xml files with tv show info, splits it into the show and the eppisode info and the place it into a table, i have got it to proccess all the info and print it out on a web page, but i cant, for the life of me, get it to insert said data into the table, it seems to be just ignoring the code and prints out the data as if nothing happens, no errors or anything. here is my code (abit messy but im only just starting and its my test.php) Code: [Select] <?php $tvdb_mirror = "http://www.thetvdb.com/api/"; $tvdb_time = "http://www.thetvdb.com/api/Updates.php?type=none"; $dbname = "mediadb"; $dbuser = "root"; $dbpass = ""; $dbserv = "127.0.0.1"; $rss = simplexml_load_file('sample.xml'); $showName = "Show Name = ".$rss->Series->SeriesName; print $showName; print "<br />Show Discription = ".$rss->Series->Overview; print "<br />"; mysql_connect('127.0.0.1', 'root', ''); @mysql_select_db('mediadb') or die("Unable to select database"); foreach ($rss->Episode as $item) { $seasonnum = $item->Combined_season; $EpisodeNumber = $item->EpisodeNumber; if($EpisodeNumber < 10){ $EpisodeNumber = "0".$EpisodeNumber; }; $EpisodeName = $item->EpisodeName; $Overview = $item->Overview; $airdate = $item->FirstAired; $tvdbid = $item ->id; $query = "INSERT INTO eppisodes VALUES('', '1', ".$EpisodeName.", ".$Overview.", ".$airdate.", '1', ".$tvdbid.", '-1', ".$seasonnum.", ".$EpisodeNumber.")"; mysql_query($query); print "<br />".$showName." - ".$seasonnum."x".$EpisodeNumber." - ".$EpisodeName." Overview:<br />".$Overview; } mysql_close(); ?> i am a noob @ php and mysql, but i have doubke and triple checked the names of the db and table. here is an sql dump of my db Code: [Select] -- phpMyAdmin SQL Dump -- version 3.3.5 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Nov 13, 2010 at 12:48 PM -- Server version: 5.1.49 -- PHP Version: 5.3.3 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `mediadb` -- -- -------------------------------------------------------- -- -- Table structure for table `eppisodes` -- CREATE TABLE IF NOT EXISTS `eppisodes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `showID` int(11) NOT NULL, `eppname` varchar(255) NOT NULL, `eppdesc` longtext NOT NULL, `airdate` date NOT NULL, `format` int(11) NOT NULL, `tvdbid` varchar(20) NOT NULL, `dohave` tinyint(1) NOT NULL, `season` varchar(2) NOT NULL, `eppisode` varchar(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `eppisodes` -- -- -------------------------------------------------------- -- -- Table structure for table `shows` -- CREATE TABLE IF NOT EXISTS `shows` ( `id` int(100) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `description` longtext NOT NULL, `TVDBID` int(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `shows` -- INSERT INTO `shows` (`id`, `name`, `description`, `TVDBID`) VALUES (1, 'higogo', 'some info', 67546); any help would be very much appericiated. fyi im running win7 with easyPHP 5.3.3 with php 5.3.3, mysql 5.1.49 apache 2.2.16 Hey all I really need help with a project I am doing. I need to create a website with a registration form that checks if the user exists if not to add the user details to my local database MySQL. My webpage looks like it should, it connects with the database but when I enter a new user it does nothing when it should save the new user to the database! I am guessing my problem is within the if...else section. Please help my code is: Code: [Select] <?php include('connect.php'); //connection details to database in a connect.php page $name = ""; $surname = ""; $username = ""; $password = ""; $confirmp = ""; $errorMessage = ""; $num_rows = 0; //if form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST'){ //get values from fields $submit = $_POST['Submit']; $title = $_POST['title']; $name = $_POST['name']; $surname = $_POST['surname']; $username = $_POST['username']; $password = $_POST['password']; $confirmp = $_POST['confirmp']; //getting string lengths $nameLength = strlen($name); $surnameLength = strlen($surname); $usernameLength = strlen($username); $passwordLength = strlen($password); $confirmpLength = strlen($confirmp); //testing if strings are between certain numbers if ($nameLength > 1 && $nameLength <= 20) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Name must be between 2 and 20 characters" . "<br>"; } if ($surnameLength >= 2 && $surnameLength <= 50) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Surname must be between 2 and 50 characters" . "<br>"; } if ($usernameLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Username must be 6 characters long" . "<br>"; } if ($passwordLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Password must be 6 characters long" . "<br>"; } if ($confirmpLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Password must be 6 characters long" . "<br>"; } if ($errorMessage == "") { $query = "SELECT * FROM user WHERE username = '$username' AND password = '$password'"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); //check to see if the $result is true if ($num_rows = 1){ $errorMessage = "Username already exists"; } else { if($password == $confirmp){ $query = "INSERT INTO user (title, name, surname, username, password) VALUES ('$title', '$name', '$surname', '$username', '$password')"; $result = mysql_query($query); session_start(); $_SESSION['login'] = "1"; header ("Location: login.php"); } else { $errorMessage = "Passwords do not match!"; } } } else { $errorMessage = "Error Registering"; } } else { $errorMessage = "Please enter your details"; } ?> <html> <head> <title>Mia's Beauty Products</title> </head> <body> <p><img src = "banner1.jpg" width = "975" height = "95" alt = "Mia's Beauty Product" /></p> <br> <p align= "center"><a href="register.php">Register</a> | <a href="login.php">Login</a> | <a href="insert.php">Insert</a> | <a href="list.php">List</a></p> <form method = "post" action = "register.php"> <table> <tr><td>Title:</td><td><select name = "title"> <option>Miss</option> <option>Mrs</option> <option>Mr</option> </select></td></tr> <tr><td>Name:</td><td><input name = "name" type = "text" value ="<?php print $name;?>"></td></tr> <tr><td>Surname:</td><td><input name = "surname" type = "text" value ="<?php print $surname;?>"></td></tr> <tr><td>Username:</td><td><input name = "username" type = "text" value ="<?php print $username;?>"></td></tr> <tr><td>Password:</td><td><input name = "password" type = "password" value ="<?php print $password;?>"></td></tr> <tr><td>Confirm Password:</td><td><input name = "confirmp" type = "password" value ="<?php print $confirmp;?>"></td></tr> <tr><td><input type = "submit" name = "Submit" value = "Submit"></td></tr> </table> </form> <p align= "center"><a href="code.txt">Code</a></p> <br> <?php print $errorMessage; ?> <p><img src = "banner2.jpg" width = "975" height = "95" alt = "Mia's Beauty Product" /></p> </body> </html> Thank you Amanda 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. |