PHP - After Refresh The Input Gets Inserted Again In The Database!
After I've successfully inputted something in my script and then click refresh in Chrome with "Right Click -> Reload", the same thing that I've inputted before gets re-inserted AGAIN into the database, thus resulting in multiple versions of the same thing in the MySQL database.
How can I prevent that? p.s. Chrome is warning with a pop up of repeated action, and when I then click continue the repeated insertion of the data occurs, and I'd like to prevent the repeated insertion. Similar TutorialsHi all, Thanks for reading. I'm running a script using jQuery that auto-refreshes a <div> on the index page from an external PHP script to get all the rows in a database and display them on the index page. The script works great - here it is as follows: Code: [Select] <script type="text/javascript"> $(document).ready(function() { $("#responsecontainer").fadeOut("fast").load("getrows.php").fadeIn("slow"); var refreshId = setInterval(function() { $("#responsecontainer").fadeOut("fast").load('getrows.php').fadeIn("slow"); }, 5000); $.ajaxSetup({ cache: false }); }); </script> The getrows.php script I'm working with looks like this: Code: [Select] <?php $rowsQuery = mysql_query("SELECT * FROM Happenings WHERE HappeningDate='$today'"); if (mysql_num_rows($rowsQuery) == 0) { $happeningsToday = "There are no happenings today."; } else { $allHappeningsToday = 1; while ($getHappeningsToday = mysql_fetch_array($rowsQuery)) { $happeningName = stripslashes($getHappeningsToday['HappeningName']); $happeningDate = $getHappeningsToday['HappeningDate']; $happeningDescription = $getHappeningsToday['HappeningDescription']; if ($allHappeningsToday == 1) { $happeningsToday .= " <div class=\"box\"> <p>".$happeningName." | ".$happeningDate." | ".$happeningDescription." </div>"; $allHappeningsToday = 2; } else { $happeningsToday .= " <div class=\"box\"> <p>".$happeningName." | ".$happeningDate." | ".$happeningDescription." </div>"; $allHappeningsToday = 1; } } } echo $happeningsToday; ?> This script works great as well. Currently, the auto-refresh jQuery script as you can see if getting and fading in/out all of the rows. Off of the above getrows.php script, is there a way after I could get only the newly created rows since the last refresh and only fade those in and out while leaving the others already loaded by the auto-refresh script to not fade in/out? Any ideas, thoughts or suggestions would be unbelievably helpful. Thank you very much. Hello all! I'm having a problem inserting an array into my database. My database is connected when I run the script but my table isn't being populated. Please help! Here's my table structure followed by the php: CREATE TABLE `demographic` ( `uid` bigint(20) unsigned NOT NULL, `first_name` varchar(50) default NULL, `last_name` varchar(50) default NULL, `email` varchar(200) default NULL, `link` varchar(255) default NULL, `affiliations` varchar(255) default NULL, `birthday` varchar(50) default NULL, `current_location` varchar(200) default NULL, `education_history` varchar(500) default NULL, `work` mediumtext, `hometown_location` varchar(400) default NULL, `interests` varchar(200) default NULL, `locale` varchar(50) default NULL, `movies` varchar(500) default NULL, `music` varchar(500) default NULL, `political` varchar(200) default NULL, `relationship_status` varchar(100) default NULL, `sex` varchar(10) default NULL, `tv` varchar(200) default NULL, `status` tinyint(4) default NULL, `created` datetime default NULL, `updated` datetime default NULL, PRIMARY KEY (`uid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; <?php $link = mysql_connect('host', 'user', 'pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('database'); if (!$db_selected) { die ('Can\'t use beta : ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); include_once "fbmain.php"; $config['baseurl'] = "baseurl"; //if user is logged in and session is valid. if ($fbme){ //collect some data using legacy api $param = array( 'method' => 'users.getinfo', 'uids' => $fbme['id'], 'fields' => 'birthday_date, interests, locale, political, relationship_status, affiliations', 'callback' => '' ); try{ $info = $facebook->api($param); } catch(Exception $o){ error_log("Legacy Api Calling Error!"); } //using graph api //array data $workInfo = getWorkInfoAsString($fbme); $education = getEducationAsString($fbme); $moviesArr = $facebook->api("/me/movies"); $musicArr = $facebook->api("/me/music"); $televisionArr = $facebook->api("/me/television"); //format some api data $movies = getArrayDataAsString($moviesArr['data']); $music = getArrayDataAsString($musicArr['data']); $television = getArrayDataAsString($televisionArr['data']); //data from legacy api $networks = ''; if (!empty($info[0]['affiliations'])){ $flag = true; foreach ($info[0]['affiliations'] as $item){ if (!$flag) $networks.= ' # '; $networks .= $item['name']; $flag = false; } } $now = date("Y-m-d G:i:s"); $insData = array( 'uid' => $fbme['id'], 'first_name' => $fbme['first_name'], 'last_name' => $fbme['last_name'], 'email' => isset($fbme['email']) ? $fbme['email'] : '', 'link' => $fbme['link'], 'affiliations' => $networks, 'birthday' => $info[0]['birthday_date'], 'current_location' => isset($fbme['location']['name']) ? $fbme['location']['name'] : '', 'education_history' => $education, 'work' => $workInfo, 'hometown_location' => isset($fbme['hometown']['name']) ? $fbme['hometown']['name'] : '', 'interests' => $info[0]['interests'], 'locale' => $info[0]['locale'], 'movies' => $movies, 'music' => $music, 'political' => $info[0]['political'], 'relationship_status' => $info[0]['relationship_status'], 'sex' => isset($fbme['gender']) ? $fbme['gender'] : '', 'tv' => $television, 'status' => '0', 'created' => $now, 'updated' => $now, ); $this->db->insert('demographic', $insData); } function getWorkInfoAsString($fbme, $delim = '#', $partDelim = ' | '){ $info = ""; $flag = false; if (empty($fbme['work'])) return ''; foreach($fbme['work'] as $item){ if ($flag) $info .= $partDelim; $flag = true; $info .= (isset($item['employer']['name']) ? $item['employer']['name'] : '' ). $delim . (isset($item['location']['name']) ? $item['location']['name'] : '' ). $delim . (isset($item['position']) ? $item['position']['name'] : '' ). $delim . (isset($item['start_date']) ? $item['start_date'] : '' ). $delim . (isset($item['end_date']) ? $item['end_date'] : '' ); } return $info; } function getEducationAsString($fbme, $delim = '#', $partDelim = ' | '){ $info = ""; $flag = false; if (empty($fbme['education'])) return ''; foreach($fbme['education'] as $item){ if ($flag) $info .= $partDelim; $flag = true; $info .= (isset($item['school']['name']) ? $item['school']['name'] : '' ). $delim . (isset($item['year']['name']) ? $item['year']['name'] : ''); } return $info; } function getArrayDataAsString($data, $delim = '#', $partDelim = ' | '){ $info = ""; $flag = false; foreach($data as $item){ if ($flag) $info .= $partDelim; $flag = true; $info .= $item['name']; } return $info; } ?> Ugh. Ive been asking so many questions, betcha already know my name. Hahah. Anyways, I know I already asked a question like this, but this is different. One of the values I am trying to insert into a database is simply not working. Here is the columnes in my mysql database: c_id commet story user date_added star Every value but 'commet' is getting inserted into database. NO error, no mysql errror. I have racked my brain trying to figure out what is wrong with the script. Here is my code: Code: [Select] <?php $idget = $_GET['id']; mysqlConnect(); //submit story if(isset($_POST['submit'])) { $com_form = mysql_real_escape_string(bb($_POST['commet'])); $rat_form = $_POST['rat']; $story_form = $idget; $user = $_SESSION['user']; $date = date("Y-m-d"); $query1 = " INSERT INTO story_commets(star, story, user, date_added, commet) VALUES($rat_form, '$story_form', '$user', '$date', '$com_form') "; mysql_query($query1) or die(mysql_error()); //} } // desplay reviews $query3 = " SELECT * FROM story_commets WHERE story = '$idget' ORDER BY date_added "; $select3 = mysql_query($query3) or die(mysql_error()); //$x=1; $ratav = array(); //if(mysql_num_rows($select3) == 0) //{ echo '<div id="message"> No Reviews Yet.... <>'; //} //else //{ while($rows3 = mysql_fetch_assoc($select3)) { $commetdb = $rows3['commet']; $user_com_db = $rows3['user']; $datedb = $rows3['date_added']; $stardb = $rows3['star']; //get profile picture $query4 = " SELECT * FROM login_info WHERE user = '$user_com_db' "; $select4 = mysql_query($query4) or die(mysql_error()); $rows4 = mysql_fetch_assoc($select4) or die(mysql_error()); $profile_pic = $rows4['profile_picture']; $user_id = $rows4['id']; echo " <div class='rev_cont'> <div class='info'> <img src='$profile_pic' /> <a href=?p=profile&id=$user_id> $user_com_db </a> <> <br /> <div class='rev'> <strong> $stardb/10 </strong> <br /> $commetdb <> <div id='date'> <em> Date Added: $datedb </em> <> <> <hr /> "; $ratav[]=$stardb; } $sum = array_sum($ratav); $count = count($ratav); $av = $sum / $count; $avf = round($av, 1); echo"<div id='message'> Rating Avarage: $avf /10 <>"; //} if (isset($_SESSION['user'])) { echo" <p> Did you like this story? Did you hate it? Give it a rating and let the author know!</p> <form action='?p=review&id=$idget' method='post' target='_self'> <label> Your rating is on a scale of 1-10 </label> <select name='rat'> <option> 1 </option> <option> 2 </option> <option> 3 </option> <option> 4 </option> <option> 5 </option> <option> 6 </option> <option> 7 </option> <option> 8 </option> <option> 9 </option> <option> 10 </option> </select> <label> Commets: </label> <textarea name='commet' cols='70' rows='9'></textarea> <input name='story' type='hidden' value='$idget' /> <br /> <input type='submit' value = 'Post' name='submit' /> </form> "; } else { echo "<div id='message'> Sign in to post a review! <>"; } ?> Here are the specifics if you want it. Here is the response part of the code: Code: [Select] <?php if(isset($_POST['submit'])) { $com_form = mysql_real_escape_string(bb($_POST['commet'])); $rat_form = $_POST['rat']; $story_form = $idget; $user = $_SESSION['user']; $date = date("Y-m-d"); $query1 = " INSERT INTO story_commets(star, story, user, date_added, commet) VALUES($rat_form, '$story_form', '$user', '$date', '$com_form') "; mysql_query($query1) or die(mysql_error()); //} } ?> Here is the form part of my code: Code: [Select] <?php if (isset($_SESSION['user'])) { echo" <p> Did you like this story? Did you hate it? Give it a rating and let the author know!</p> <form action='?p=review&id=$idget' method='post' target='_self'> <label> Your rating is on a scale of 1-10 </label> <select name='rat'> <option> 1 </option> <option> 2 </option> <option> 3 </option> <option> 4 </option> <option> 5 </option> <option> 6 </option> <option> 7 </option> <option> 8 </option> <option> 9 </option> <option> 10 </option> </select> <label> Commets: </label> <textarea name='commet' cols='70' rows='9'></textarea> <input name='story' type='hidden' value='$idget' /> <br /> <input type='submit' value = 'Post' name='submit' /> </form> "; } else { echo "<div id='message'> Sign in to post a review! <>"; } ?> Its probably something really mundane. HelP! hello every body...
two
I'm creating an IPN in paypal for my membership site but the problem I'm facing is that on successfull verification of the purchase, four rows are getting inserted in the database...
The code is
<?php require '../db.php'; $paypalmode = '.sandbox'; $req = 'cmd=' . urlencode('_notify-validate'); foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $req); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$paypalmode.'.paypal.com')); $res = curl_exec($ch); curl_close($ch); if (strcmp ($res, "VERIFIED") == 0) { $transaction_id = $_POST['txn_id']; $payerid = $_POST['payer_id']; $firstname = $_POST['first_name']; $lastname = $_POST['last_name']; $payeremail = $_POST['payer_email']; $paymentdate = $_POST['payment_date']; $paymentstatus = $_POST['payment_status']; $mdate= date('Y-m-d h:i:s',strtotime($paymentdate)); $otherstuff = json_encode($_POST); $date = date("y-m-d"); $q = $pdo->connect()->query("INSERT INTO payment (mid,username,amount,paypal_id,txn_id,received_date) VALUES('{$_SESSION['user_id']}','{$_SESSION['uname']}','{$_POST['mc_gross']}','{$_POST['payer_email']}','{$_POST['txn_id']}','$date')"); $q->execute(); $q1 = $pdo->connect()->query("UPDATE members SET amount_loaded = amount_loaded + {$_SESSION['amount']} WHERE mid = '{$_SESSION['user_id']}'"); $q1->execute(); //header("Location: funds.php"); echo "verified"; } ?>two for the payment and in the members table, the amount is getting doubled. (i.e if anybody purchases For $2, it shows $4 in the database....) Any help will be really appreciated... Hello everyone.
It seems like my code is not working properly.
i have tried both mysqli and PDO to insert data into database,but it only takes me back to same page again,without doing nothing in the database (been checking this a few times to be sure).
both php and html code are on the same page.
Could anyone point me to the missing link in my code?
here's my code (HTML & PHP) :
<form action="" id="SignUpForm" autocomplete="on" style="display:none" method="post"> <!-- Form is Hidden until the user is clicking the "Sign Up" button. --> <input type="hidden" name="Language" value="English"> Fill up the following fields:<br><br> First name:<input type="text" name="fname" required><br><br> Last name: <input type="text" name="lname" required><br><br> Age: <input type="number" name="UserAge" min="1" max="120" required><br><br> Gender: <input type="radio" name="Gender" value="male">Male<br> <input type="radio" name="Gender" value="Female">Female<br> E-mail Address: <input type="email" name="email" autocomplete="off" required><br><br> Pick your new password: <input type="password" maxlength=”40” name="Password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"> Add password strength checker here.<br><br> <!-- Uses regular expression. --> Confirm Password: <input type="password" maxlength=”40” name="ConfirmPassword" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,40}"><br><br> <!-- A better way is to use onblur to check user's type match. --> <hr> <script> (function(){ $("#submit").click(function(){ $(".error").hide(); //Bind an event handler to the "error" JavaScript event. var hasError = false; var passwordVal = $("#Password").val(); var checkVal = $("#ConfirmPassword").val(); if (passwordVal == '') { $("#Password").after('<span class="error">Please enter a password.</span>'); hasError = true; } else if (checkVal == '') { $("#ConfirmPassword").after('<span class="error">Please re-enter your password.</span>'); hasError = true; } else if (passwordVal != checkVal ) { $("#ConfirmPassword").after('<span class="error">Passwords do not match.</span>'); hasError = true; } if(hasError == true) {return false;} }); }); </script> <script> //The validationMessage property of a DOM node contains the message the browser displays to the user when a node's validity is checked and fails. document.getElementById("name").validationMessage; document.getElementById("lname").validationMessage; document.getElementById("UserAge").validationMessage; document.getElementById("Gender").validationMessage; document.getElementById("email").validationMessage; document.getElementById("Password").validationMessage; document.getElementById("ConfirmPassword").validationMessage; </script> Now let's go through your prefered food. Check the appropriate boxed beyond.<br><br> This will help us to better understand your food discipline:<br> <p style="text-align:center"><b> Meat And Poultry:</b></p> <div id="MeatCheckBox"> <input type="checkbox" name="FoodTypes[]" value="Hamburger">Hamburger<br> <input type="checkbox" name="FoodTypes[]" value="Steak">Steak<br> <input type="checkbox" name="FoodTypes[]" value="GroundBeef">Ground Beef<br> <input type="checkbox" name="FoodTypes[]" value="Bacon">Bacon<br> <input type="checkbox" name="FoodTypes[]" value="Beef">Beef<br> <input type="checkbox" name="FoodTypes[]" value="Salami">Salami<br> <input type="checkbox" name="FoodTypes[]" value="Chicken">Chicken (In all its forms)<br> <input type="checkbox" name="FoodTypes[]" value="NoMeat">I don't eat meat at all (Vegeterian/Vegan)<br> </div> <p style="text-align:center"><b> Fish And Seafood:</b></p> <div id="FishAndSeaFood"> <input type="checkbox" name="FoodTypes[]" value="Fish">Fish<br> <input type="checkbox" name="FoodTypes[]" value="Sushi">Sushi<br> <input type="checkbox" name="FoodTypes[]" value="CannedFish">Canned Fish<br> <input type="checkbox" name="FoodTypes[]" value="Oysters">Seafood<br> <input type="checkbox" name="FoodTypes[]" value="SmokedSalmon">Smoked Salmon<br> </div> <div id="Vegetables"> <p style="text-align:center"><b> Do you eat vegtables?</b></p><br> <input type="radio" name="YesOrNo" value="Yes">Yes <!-- Give both options the same name,Because they are related. --> <input type="radio" name="YesOrNo" value="No">No<br> </div> <hr> <p>Do you workout as part of your lifestyle?</p><br> <input type="radio" name='workout_options' value='valuable' data-id="DoWorkout" class="workout_options" /> I do workout occasionally <input type="radio" name='workout_options' value='valuable' data-id="DoNotWorkout" class="workout_options" /> I am not working out<br><br><br> <section> <div id=DoWorkout class="workout_options"><p>We see you're not having any exercise at the moment.<br><br>Did you know that doing some kind of activity like running or cardio 3 times a week improve your life quality?<br><br>We'll help you go straight from zero to hero!</p></div> <div id=DoNotWorkout class="workout_options">What type of workout you're working on at the moment? Please choose from the options beyond:<br><br><br> <input type="checkbox" name="Cardio" value="Cardio" data-id="Cardio"/>Cardio/Aerobics<br><br> <input type="checkbox" name=" Weight_Lifting" value=" Weight_Lifting" data-id="Weight_Lifting"/>Weight Lifting/ Anaerobics</div><br> </section> <input type="submit" value="Sign Up!" id="submit"> </div> </form>PHP/PDO: <?php // connnecting to MYSQL with PDO. // Connection data (server_address, database, username, password) $hostdb = 'localhost'; $namedb = 'caf_users'; $userdb = 'root'; $passdb = 'mypassword'; if (isset($_POST['SignUpButton'])) { $yesOrNo=$_POST["YesOrNo"]; $firstName=$_POST["fname"]; $lastName=$_POST["lname"]; $userGender=$_POST["Gender"]; $emailAddress=$_POST["email"]; //check if user entered the exact password twice. if ($_POST["password"] === $_POST["confirm_password"]) { $password=$_POST["password"]; $hash = password_hash($passwod, PASSWORD_DEFAULT);} // The first parameter is the password string that needs to be hashed, //and the second parameter specifies the algorithm that should be used for generating the hash. //encrypted by bcrypt algorithm. else { echo "Passwords are mismatched. Please try again."; }; $userAge=$_POST["UserAge"]; // Display message if successfully connect, otherwise retains and outputs the potential error try { $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); //Initiate connection witht the PDO object instance. $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 echo 'Connected to database'; // Define an insert query $sql = "INSERT INTO `users` ('Workout','first_name','last_name','gender','Email_Address','Password','User_Age') VALUES ($YesOrno,$fname,$lname,$Gender,$email,$password,$UserAge)"; $count = $conn->exec($sql); $conn = null; // Disconnect if($count !== false) echo 'Number of rows added: '. $count; } catch(PDOException $e) { echo $e->getMessage(); } } ?>Thank you in advance, Osher. Am a newbie in php. Since I can't insert values to the database with respect to a user Id or with any other token using WHERE clause. I.e "INSERT INTO receipts(date) VALUES(example) where id="**....." If I need to fetch several values of column for a particular user, how do I go about it? Thank you!!! Hi Is it necessary to hash stored access and refresh tokens that are stored in a database. Both these tokens have limited lifespan (access token - 20 minutes but refresh token is 14 days). The reason I ask is I have hashed the tokens using the password_hash function but a user can have multiple active sessions if they want (so there is a sessions table with user id (not username), access token, token expiry date/time, refresh token and refresh token expiry date/time. So in order to refresh the access token I have to do a look up to see which session it relates to, what I have found is that I must retrieve all rows where the refresh token hasn't expired and then run password_verify against the tokens stored with the tokens provided to check each session to see if they match. What I have found is that it takes a while to run the password_verify function (by design I think) for each row (could be many if the users has been silly and logged in lots of time) which would cause an unacceptable delay when calling an API with an access token that needs refreshing (my tests resulted in times upwards of 30 seconds for a user who has around 10 active sessions). If both tokens were not hashed the same action to refresh a token for a user who has 10 active sessions takes less than a second which is much more acceptable. Edited December 15, 2018 by mds1256hi all i am having a big problem that i have been trying to find out what is going on for weeks. i have a echo script that echos data that is in my database, and if i have to refresh the page it will add blank data in my database and the top echo info is blank as well. how can i fix this, and i was wanting to know how do i echo out my info in a textarea. i added a jepg to show you what i mean. here is my code echoforms.php <?php error_reporting(0); require_once('demo.php'); /*Open the connection to our database use the info from the config file.*/ $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); $sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms"; $results = mysql_query($sql); if (!$results) { die('Invalid query: ' . mysql_error()); } while($result = mysql_fetch_array( $results )){ echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">'; echo date("d/m/y"); echo '<p>Company Name: ' . $_POST['company_name'] . '</p>'; echo '<p>Contact Name: ' . $_POST['contact_name'] . '</p>'; echo '<p>Address: ' . $_POST['address'] . '</p>'; echo '<p>Street Number: ' . $_POST['street_number'] . '</p>'; echo '<p>Postcode: ' . $_POST['postcode'] . '</p>'; echo '<p>Contact Number: ' . $_POST['contact_number'] . '</p>'; echo '<p>Contact Email: ' . $_POST['contact_email'] . '</p>'; echo '<p>Budget: ' . $_POST['budget'] . '</p>'; echo '<p>Description: ' . $_POST['description'] . '</p>'; echo '</div>'; } ?> ok, so I have this code to start with: Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['username'])) { echo 'Please <a href="/login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql_1.php"; // Place Session variable 'id' into local variable $username1 = $_SESSION['username']; ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT hometown, about, month, day, year, id FROM general WHERE user='$username1'"); while($row = mysql_fetch_array($sql)){ $userid = $row["userid"]; $hometown = $row["hometown"]; $about = $row["about"]; $month = $row["month"]; $day = $row["day"]; $year = $row["year"]; $userid1 = $row["id"]; } $sql = mysql_query("SELECT * from sessions WHERE username='$username1'"); while($row = mysql_fetch_array($sql)){ $name1 = $row["name"]; } ?> <?php if($month == "January"){ $month2 =="1";}else if($month =="February"){$month2 =="2";}else if($month =="March"){$month2 =="3";}else if($month =="April"){$month2 =="4";}else if($month =="May"){$month2 =="5";}else if($month =="June"){$month2 =="6";}else if($month =="July"){$month2 =="7";}else if($month =="August"){$month2 =="8";}else if($month =="September"){$month2 =="9";}else if($month =="October"){$month2 =="10";}else if($month =="November"){$month2 =="11";}else if($month =="December"){$month2 =="12";} ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * from pics WHERE user='$username1'"); while($row = mysql_fetch_array($sql)){ $link123 = $row["link"]; } ?> <?php if(isset($_SESSION['username'])) { $query = "SELECT sport FROM sports where user ='$username1'"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($sport) = $row; $cs .= "$sport<br> "; }} ?> <!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> <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script> <script language="javascript" type='text/javascript'> function hideDiv() { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById('hideShow').style.visibility = 'hidden'; } else { if (document.layers) { // Netscape 4 document.hideShow.visibility = 'hidden'; } else { // IE 4 document.all.hideShow.style.visibility = 'hidden'; } } } function showDiv() { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById('hideShow').style.visibility = 'visible'; } else { if (document.layers) { // Netscape 4 document.hideShow.visibility = 'visible'; } else { // IE 4 document.all.hideShow.style.visibility = 'visible'; } } } </script> <script language="javascript" type='text/javascript'> function hideDiv1() { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById('apDiv4').style.visibility = 'hidden'; } else { if (document.layers) { // Netscape 4 document.apDiv4.visibility = 'hidden'; } else { // IE 4 document.all.apDiv4.style.visibility = 'hidden'; } } } function showDiv1() { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById('apDiv4').style.visibility = 'visible'; } else { if (document.layers) { // Netscape 4 document.apDiv4.visibility = 'visible'; } else { // IE 4 document.all.apDiv4.style.visibility = 'visible'; } } } </script> <style type="text/css"> #apDiv1 { position:absolute; left:0px; top:0px; width:100%; height:50px; z-index:1; background-color: #000; padding: 0px; text-align: left; } #menu { position:absolute; top:15px; width:411px; height:34px; z-index:41; right: 0px; } </style> <link rel="stylesheet" href="css/structure.css" type="text/css" /> <link rel="stylesheet" href="css/form.css" type="text/css" /> <!-- JavaScript --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/ libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript"> $(function() { $(".submit").click(function() { var name = $("#name").val(); var dataString = 'name='+ name; if(name=='') { $('.success').fadeOut(200).hide(); $('.error').fadeOut(200).show(); } else { $.ajax({ type: "POST", url: "join.php", data: dataString, success: function(){ $('.success').fadeIn(200).show(); $('.error').fadeOut(200).hide(); $(document).ready(function(){ $('#submit').click(function(){ var a = $("#name").val(); if(a != "") { $.post("join.php",{ }, function(response){ $('#posting').prepend($(response).fadeIn('slow')); $("#name").val("what's on your mind?"); }); } }); }); } }); } return false; }); }); </script> <style type="text/css"> .error{ color:#d12f19; font-size:12px; } .success{ color:#006600; font-size:12px; } </style> <link href="Spry-UI-1.7/css/Menu/basic/SpryMenuBasic.css" rel="stylesheet" type="text/css" /> <script src="Spry-UI-1.7/includes/SpryDOMUtils.js" type="text/javascript"></script> <script src="Spry-UI-1.7/includes/SpryDOMEffects.js" type="text/javascript"></script> <script src="Spry-UI-1.7/includes/SpryWidget.js" type="text/javascript"></script> <script src="Spry-UI-1.7/includes/SpryMenu.js" type="text/javascript"></script> <script src="Spry-UI-1.7/includes/plugins/MenuBar2/SpryMenuBarKeyNavigationPlugin.js" type="text/javascript"></script> <script src="Spry-UI-1.7/includes/plugins/MenuBar2/SpryMenuBarIEWorkaroundsPlugin.js" type="text/javascript"></script> <style type="text/css"> /* BeginOAWidget_Instance_2141544: #MenuBar */ /* Settable values for skinning a Basic menu via presets. If presets are not sufficient, most skinning should be done in these rules, with the exception of the images used for down or right pointing arrows, which are in the file SpryMenuBasic.css These assume the following widget classes for menu layout (set in a preset) .MenuBar - Applies to all menubars - default is horizontal bar, all submenus are vertical - 2nd level subs and beyond are pull-right. .MenuBarVertical - vertical main bar; all submenus are pull-right. You can also pass in extra classnames to set your desired top level menu bar layout. Normally, these are set by using a preset. They only apply to horizontal menu bars: MenuBarLeftShrink - The menu bar will be horizontally 'shrinkwrapped' to be just large enough to hold its items, and left aligned MenuBarRightShrink - Just like MenuBarLeftShrink, but right aligned MenuBarFixedLeft - Fixed at a specified width set in the rule '.MenuBarFixedLeft', and left aligned. MenuBarFixedCentered - - Fixed at a specified width set in the rule '.MenuBarFixedCentered', and centered in its parent container. MenuBarFullwidth - Grows to fill its parent container width. In general, all rules specified in this file are prefixed by #MenuBar so they only apply to instances of the widget inserted along with the rules. This permits use of multiple MenuBarBasic widgets on the same page with different layouts. Because of IE6 limitations, there are a few rules where this was not possible. Those rules are so noted in comments. */ #MenuBar { background-color:#000000; font-family: Arial, Helvetica, sans-serif; /* Specify fonts on on MenuBar and subMenu MenuItemContainer, so MenuItemContainer, MenuItem, and MenuItemLabel at a given level all use same definition for ems. Note that this means the size is also inherited to child submenus, so use caution in using relative sizes other than 100% on submenu fonts. */ font-weight: normal; font-size: 16px; font-style: normal; padding:0; border-color: #000000 #000000 #000000 #000000; border-width:0px; border-style: none none none none; } /* Caution: because ID+class selectors do not work properly in IE6, but we want to restrict these rules to just this widget instance, we have used string-concatenated classnames for our selectors for the layout type of the menubar in this section. These have very low specificity, so be careful not to accidentally override them. */ .MenuBar br { /* using just a class so it has same specificity as the ".MenuBarFixedCentered br" rule bleow */ display:none; } .MenuBarLeftShrink { float: left; /* shrink to content, as well as float the MenuBar */ width: auto; } .MenuBarRightShrink { float: right; /* shrink to content, as well as float the MenuBar */ width: auto; } .MenuBarFixedLeft { float: left; width: 80em; } .MenuBarFixedCentered { float: none; width: 80em; margin-left:auto; margin-right:auto; } .MenuBarFixedCentered br { clear:both; display:block; } .MenuBarFixedCentered .SubMenu br { display:none; } .MenuBarFullwidth { float: left; width: 100%; } /* Top level menubar items - these actually apply to all items, and get overridden for 1st or successive level submenus */ #MenuBar .MenuItemContainer { padding: 0px 0px 0px 0px; margin: 0; /* Zero out margin on the item containers. The MenuItem is the active hover area. For most items, we have to do top or bottom padding or borders only on the MenuItem or a child so we keep the entire submenu tiled with items. Setting this to 0 avoids "dead spots" for hovering. */ } #MenuBar .MenuItem { padding: 0px 24px 0px 0px; background-color:#000000; border-width:0px; border-color: #cccccc #ffffff #cccccc #ffffff; border-style: none solid none solid; } #MenuBar .MenuItemFirst { border-style: none none none none; } #MenuBar .MenuItemLast { border-style: none solid none none; } #MenuBar .MenuItem .MenuItemLabel{ text-align:center; line-height:1.4em; color:#ffffff; background-color:#000000; padding: 6px 15px 6px 39px; width: 10em; width:auto; } .SpryIsIE6 #MenuBar .MenuItem .MenuItemLabel{ width:1em; /* Equivalent to min-width in modern browsers */ } /* First level submenu items */ #MenuBar .SubMenu .MenuItem { font-family: Arial, Helvetica, sans-serif; font-weight: normal; font-size: 14px; font-style: normal; background-color:#ffffff; padding:0px 2px 0px 0px; border-width:0px; border-color: #cccccc #cccccc #cccccc #cccccc; /* Border styles are overriden by first and last items */ border-style: solid solid none solid; } #MenuBar .SubMenu .MenuItemFirst { border-style: solid solid none solid; } #MenuBar .SubMenu .MenuItemFirst .MenuItemLabel{ padding-top: 6px; } #MenuBar .SubMenu .MenuItemLast { border-style: solid solid solid solid; } #MenuBar .SubMenu .MenuItemLast .MenuItemLabel{ padding-bottom: 6px; } #MenuBar .SubMenu .MenuItem .MenuItemLabel{ text-align:left; line-height:1em; background-color:#ffffff; color:#333333; padding: 6px 12px 6px 5px; width: 7em; } /* Hover states for containers, items and labels */ #MenuBar .MenuItemHover { background-color: #666666; border-color: #cccccc #cccccc #cccccc #cccccc; } #MenuBar .MenuItemWithSubMenu.MenuItemHover .MenuItemLabel{ background-color: #666666; /* consider exposing this prop separately*/ color: #ffffff; } #MenuBar .MenuItemHover .MenuItemLabel{ background-color: #666666; color: #ffffff; } #MenuBar .SubMenu .MenuItemHover { background-color: #666666; border-color: #666666 #cccccc #cccccc #cccccc; } #MenuBar .SubMenu .MenuItemHover .MenuItemLabel{ background-color: #666666; color: #ffffff; } /* Submenu properties -- First level of submenus */ #MenuBar .SubMenuVisible { background-color: #ffffff; min-width:0%; /* This keeps the menu from being skinnier than the parent MenuItemContainer - nice to have but not available on ie6 */ border-color: #ffffff #ffffff #ffffff #ffffff; border-width:0px; border-style: none none none none; } #MenuBar.MenuBar .SubMenuVisible {/* For Horizontal menubar only */ top: 100%; /* 100% is at the bottom of parent menuItemContainer */ left:0px; /* 'left' may need tuning depending upon borders or padding applied to menubar MenuItemContainer or MenuItem, and your personal taste. 0px will left align the dropdown with the content area of the MenuItemContainer. Assuming you keep the margins 0 on MenuItemContainer and MenuItem on the parent menubar, making this equal the sum of the MenuItemContainer & MenuItem padding-left will align the dropdown with the left of the menu item label.*/ z-index:10; } #MenuBar.MenuBarVertical .SubMenuVisible { top: 0px; left:100%; min-width:0px; /* Do not neeed to match width to parent MenuItemContainer - items will prevent total collapse */ } /* Submenu properties -- Second level submenu and beyond - these are visible descendents of .MenuLevel1 */ #MenuBar .MenuLevel1 .SubMenuVisible { background-color: #ffffff; min-width:0px; /* Do not neeed to match width to parent MenuItemContainer - items will prevent total collapse*/ top: 0px; /* If desired, you can move this down a smidge to separate top item''s submenu from menubar - that is really only needed for submenu on first item of MenuLevel1, or you can make it negative to make submenu more vertically 'centered' on its invoking item */ left:100%; /* If you want to shift the submenu left to partially cover its invoking item, you can add a margin-left with a negative value to this rule. Alternatively, if you use fixed-width items, you can change this left value to use px or ems to get the offset you want. */ } /* IE6 rules - you can delete these if you do not want to support IE6 */ /* A note about multiple classes in IE6. * Some of the rules above use multiple class names on an element for selection, such as "hover" (MenuItemHover) and "has a subMenu" (MenuItemWithSubMenu), * giving the selector '.MenuItemWithSubMenu.MenuItemHover'. * Unfortunately IE6 does not support using mutiple classnames in a selector for an element. For a selector such as '.foo.bar.baz', IE6 ignores * all but the final classname (here, '.baz'), and sets the specificity accordingly, counting just one of those classs as significant. To get around this * problem, we use the plugin in SpryMenuBarIEWorkaroundsPlugin.js to generate compound classnames for IE6, such as 'MenuItemWithSubMenuHover'. * Since there are a lot of these needed, the plugin does not generate the extra classes for modern browsers, and we use the CSS2 style mutltiple class * syntax for that. Since IE6 both applies rules where * it should not, and gets the specificity wrong too, we have to order rules carefully, so the rule misapplied in IE6 can be overridden. * So, we put the multiple class rule first. IE6 will mistakenly apply this rule. We follow this with the single-class rule that it would * mistakenly override, making sure the misinterpreted IE6 specificity is the same as the single-class selector, so the latter wins. * We then create a copy of the multiple class rule, adding a '.SpryIsIE6' class as context, and making sure the specificity for * the selector is high enough to beat the single-class rule in the "both classes match" case. We place the IE6 rule at the end of the * css style block to make it easy to delete if you want to drop IE6 support. * If you decide you do not need IE6 support, you can get rid of these, as well as the inclusion of the SpryMenuBarIEWorkaroundsPlugin.js script. * The 'SpryIsIE6' class is placed on the HTML element by the script in SpryMenuBarIEWorkaroundsPlugin.js if the browser is Internet Explorer 6. This avoids the necessity of IE conditional comments for these rules. */ .SpryIsIE6 #MenuBar .MenuBarView .MenuItemWithSubMenuHover .MenuItemLabel /* IE6 selector */{ background-color: #666666; /* consider exposing this prop separately*/ color: #ffffff; } .SpryIsIE6 #MenuBar .MenuBarView .SubMenu .MenuItemWithSubMenuHover .MenuItemLabel/* IE6 selector */{ background-color: #666666; /* consider exposing this prop separately*/ color: #ffffff; } .SpryIsIE6 #MenuBar .SubMenu .SubMenu /* IE6 selector */{ margin-left: -0px; /* Compensates for at least part of an IE6 "double padding" version of the "double margin" bug */ } /* EndOAWidget_Instance_2141544 */ #apDiv2 { position:absolute; left:5px; top:75px; width:591px; height:284px; z-index:2; } #hideShow { position:absolute; left:84px; top:211px; width:506px; height:47px; z-index:2; } #apDiv3 { position:absolute; left:4px; top:354px; width:306px; height:45px; z-index:3; } #apDiv4 { position:absolute; left:82px; top:275px; width:290px; height:34px; z-index:4; } #apDiv5 { position:absolute; left:17px; top:205px; width:861px; height:172px; z-index:2; } .fullname { position:relative; left:0px; width:100px; height:30px; z-index:4; top:25px; background-color:black; color:white; text-align: center; } #apDiv5 #TabbedPanels1 .TabbedPanelsContentGroup .TabbedPanelsContent.TabbedPanelsContentVisible #form1 table tr td { text-align: right; } </style> <script type="text/xml"> <!-- <oa:widgets> <oa:widget wid="2141544" binding="#MenuBar" /> </oa:widgets> --> </script> <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #apDiv6 { position:absolute; left:4px; top:54px; width:162px; height:147px; z-index:3; } </style> </head> <body onLoad="javascript:TabbedPanels1.showPanel(<?php echo $_COOKIE['index'];?>)"> <?php $birthday1 = "$year-$month2-$day"; ?> <div id="apDiv1"> <div id="menu"> <ul id="MenuBar" class="MenuBarHorizontal"> <li><a href="index.php">Home</a> </li> <li><a href="profile.php">Profile</a></li> <li><a class="MenuBarItemSubmenu" href="#">Account</a> <ul> <li><a href="settings.php">Account Settings</a> </li> <li><a href="privacy.php">Privacy Settings</a></li> <li><a href="logout.php">Logout</a></li> </ul> </li> </ul> <script type="text/javascript"> // BeginOAWidget_Instance_2141544: #MenuBar var MenuBar = new Spry.Widget.MenuBar2("#MenuBar", { widgetID: "MenuBar", widgetClass: "MenuBar MenuBarRightShrink", insertMenuBarBreak: true, mainMenuShowDelay: 100, mainMenuHideDelay: 200, subMenuShowDelay: 200, subMenuHideDelay: 200 }); // EndOAWidget_Instance_2141544 </script> </div> <a href="/main.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image1','','/hover.png',1)"><img src="/main.png" name="Image1" width="600" height="50" border="0" id="Image1" /></a> </div> <?php // Process the form if it is submitted if ($_POST['general']) { $city1 = $_POST['city']; $hometown1 = $_POST['hometown']; $about1 = $_POST['about']; $sql = mysql_query("UPDATE general SET city='$city1', hometown='$hometown1', about='$about1' WHERE id='$userid1'")or die(mysql_error()); $message ='Your Account info has been saved'; echo "<font color = 'red'>"; echo $message; echo "</font>"; } // close if post ?> <div id="apDiv5"> <div id="TabbedPanels1" class="VTabbedPanels"> <ul class="TabbedPanelsTabGroup"> <li class="TabbedPanelsTab" tabindex="0">Basic Info</li> <li class="TabbedPanelsTab" tabindex="0">Profile Picture</li> <li class="TabbedPanelsTab" tabindex="0">Sports</li> <li class="TabbedPanelsTab" tabindex="0">Activities</li> <li class="TabbedPanelsTab" tabindex="0">Contact Info</li> </ul> <div class="TabbedPanelsContentGroup"> <div class="TabbedPanelsContent"><form id="form1" name="form1" method="post" action=""> <label for="city"></label> <table width="496" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="157" scope="col">Current City:</td> <td width="333" scope="col"><div align="left"> <input type="text" name="city" id="city" value="<?php echo $city; ?>" /> </div></td> </tr> <tr> <td>Hometown:</td> <td><div align="left"> <label for="hometown"></label> <input type="text" name="hometown" id="hometown" value="<?php echo $hometown; ?>" /> </div></td> </tr> <tr> <td>Birthday:</td> <td><div align="left"><?php echo $month;?> <?php echo $day; ?>, <?php echo $year; ?></div></td><tr><td></td><td> <div align="left"><?php //calculate years of age (input string: YYYY-MM-DD) function birthday ($birthday){ list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; } echo birthday($birthday1). " years old"; ?></div></td></tr></td> </tr> <tr> <td>About Me: </td> <td><label for="about"></label> <textarea name="about" id="about" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td><div align="left"><input name="general" id="general" type="submit" value="Save information" class="fullname" /></div></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form></div> <div class="TabbedPanelsContent"><form enctype="multipart/form-data" action="profile.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="900000000000000000000000000000000000000000000000000000000000000000000000000" /> Choose a file to upload: <div id="dynamicInput"> <p>Entry 1</p> <p> <br> <input type="file" name="uploadedfile[]"> </p> </div> <input type="submit" value="Upload File" id="submit" name="submit" /> </form> <?php if($_POST['submit']){ // Where the file is going to be placed $target_path = 'images/'.$username1.'/'; foreach ($_FILES["uploadedfile"]["name"] as $key => $value) { $uploadfile = $target_path . basename($_FILES["uploadedfile"]["name"][$key]); $uploadfile1 = basename($_FILES["uploadedfile"]["name"][$key]); //echo $uploadfile; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { $sql = mysql_query("UPDATE pics SET link='$uploadfile', name='$uploadfile1' WHERE user='$username1'")or die(mysql_error()); $sql = mysql_query("UPDATE facebook_posts SET pic='$uploadfile' WHERE f_name='$name1'")or die(mysql_error()); $sql = mysql_query("UPDATE facebook_posts_comments SET pic='$uploadfile' WHERE f_name='$name1'")or die(mysql_error()); echo $value . ' uploaded<br>'; } } } ?> </div> <div class="TabbedPanelsContent"><form autocomplete="off" enctype="multipart/form-data" method="post" name="form"> <div class="info" style="padding-left:20px"> <h2> </h2> <div></div> <div> <p>Sport: <input id="name" name="name" type="text" class="field text medium" value="" maxlength="255" tabindex="1" /> </p> <p></p> </div> <div></div> </div> <div class="buttons"> <input type="submit" value="Submit" style=" background:#0060a1; color:#FFFFFF; font-size:14px; border:1px solid #0060a1; margin-left:12px" class="submit" name="submit" id="submit"/><span class="error" style="display:none"> Please Enter Valid Data</span><?php if($_POST['submit']){ ?><span class="success" style="display:none"> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// <?php $sql123 = mysql_query("SELECT id, sport, user FROM sports WHERE user='$username1'"); while($row = mysql_fetch_array($sql123)){ $id = $row["id"]; $sport1 .= $row["sport"]; $user = $row["user"];} echo $sport1; ;} ?></span> </div> </form></div> <div class="TabbedPanelsContent">Content 4</div> <div class="TabbedPanelsContent">Content 5 </div> </div> </div> </div> <div id="posting" align="center"> <?php include_once "posting.php"; ?> </div> <div id="apDiv6"><?php echo '<img src="'.$link123.'" width="162""/>'; ?></div> <script type="text/javascript"> var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1"); </script> </body> </html> My goal is to make it so that where the really long comment(well with no words), is at that it runs after the ajax at the begining of the script so that the database input it does shows up in that result. here is the code of join.php Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['username'])) { echo 'Please <a href="/login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql_1.php"; // Place Session variable 'id' into local variable $username1 = $_SESSION['username']; ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT hometown, about, month, day, year, id FROM general WHERE user='$username1'"); while($row = mysql_fetch_array($sql)){ $userid = $row["userid"]; $hometown = $row["hometown"]; $about = $row["about"]; $month = $row["month"]; $day = $row["day"]; $year = $row["year"]; $userid1 = $row["id"]; } $sql = mysql_query("SELECT id, sport, user FROM sports WHERE user='$username1'"); while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $sport1 = $row["sport"]; $user = $row["user"]; } if($_POST) { $sport=$_POST['name']; mysql_query("INSERT INTO sports (id, sport, user) VALUES ('$userid1', '$sport', '$username1')"); }else { } ?> <html> <head> </head> <body> <?php echo $sport1; ?> </body> </html> I hope this makes sense. so once again, I need the results that the code by the long comment(sorta) will basically run after the ajax uses join.php to input info into the dbase. or is there a better way to do this? currently the results are loading even before the page loads. so that it returns the results when it is supposed to, it just didn't query the database at the right time. At the moment I collect data from an .XML file and it gets inserted into a database and it works great however the way in which the .xml files work has changed and I need to update my script to accommodate,
before everything was processed by 1x .xml file and i collected data, now its done via 2x .xml files.
So here is my current script;
<?php // INCLUDE DB CONNECTION FILE include("includes/connect.php"); // CHANGE THE VALUES HERE include("includes/config.php"); // URL FOR XML DATA $url = "https://api.eveonline.com/corp/StarbaseList.xml.aspx?keyID=".$keyID."&vCode=".$vCode.""; // RUN XML DATA READY FOR INSERT $xml = simplexml_load_file($url); // Loop Through Names $insertValues = array(); $modifiedTS = date('Y-m-d h:i:s'); foreach ($xml->result->rowset[0] as $value) { //Prepare the values $itemID = $value['itemID']; $typeID = mysql_real_escape_string($value['typeID']); $locationID = $value['locationID']; $moonID = $value['moonID']; $state = mysql_real_escape_string($value['state']); $stateTimestamp = mysql_real_escape_string($value['stateTimestamp']); $onlineTimestamp = $value['onlineTimestamp']; $standingOwnerID = $value['standingOwnerID']; //Create and run ONE INSERT statement (with UPDATE clause) $insert = "INSERT INTO `ecmt_poslist` (itemID,typeID,locationID,moonID,state,stateTimestamp,onlineTimestamp,standingOwnerID,last_modified) VALUES('$itemID','$typeID','$locationID','$moonID','$state','$stateTimestamp','$onlineTimestamp','$standingOwnerID','$modifiedTS') ON DUPLICATE KEY UPDATE state='$state', stateTimestamp='$stateTimestamp', onlineTimestamp='$onlineTimestamp', last_modified = '$modifiedTS'"; mysql_query($insert) or die(mysql_error()); //ERROR CHECKING OPTION ONLY! //echo $insert; //echo "<br><br>"; }; //UPDATE last time this script ran and insert timestamp into Database $timeNow = date('Y-m-d H:i:s', strtotime('-1 hour')); $insertTime = "UPDATE `ecmt_API` SET time=1, time='$timeNow'"; mysql_query($insertTime) or die(mysql_error()); //Run query to delete records that were not just inserted/updated $delete = "DELETE FROM `ecmt_poslist` WHERE last_modified < '$modifiedTS'"; mysql_query($delete) or die(mysql_error()); ?>and here is the wiki page about the .xml file and its data; http://wiki.eve-id.n...tarbaseList_XML i now need it to collect more data from a 2nd .xml file but the url will include the $itemID of the items pulled by the above script; http://wiki.eve-id.n...rbaseDetail_XML now i guess i need to put the code in the above foreach loop so I can say for each $itemID gather data from the second .xml file and input into a seperate table in my database named: `ecmt_poslistdetails` but i have no idea where to start as the rowset and layout of the 2nd .xml file is different, can anyone help me.. i'm not even sure if I wrote out this post to make sense from someone looking in from outside or not. its hard to explain. but hopefully the links provided will help. Ultimately I hope to have 2 tables in my database ecmt_poslist and ecmt_poslistdetails both containing the data from the above 2x .xml files. Hi guys I have created a profile page where users can update their profile. what I need to do is to echo back the users details in the inout text I have name and telephone number any ideas how to do it? here is my code <?php session_start(); include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $telephonenumber = addslashes(strip_tags($_POST['telephonenumber'])); $query = "UPDATE users SET name = ' $name' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE users SET telephonenumber = ' $telephonenumber' WHERE username='$username'"; $result = mysql_query($query); } ?> <form action='updateprofile.php' method='POST'> Company Name:<br /> <input type='text' name='name'><p /> <input type='text' name='telephonenumber'><p /> <input type='submit' name='register' value='Register'> </form> _______ the reason i want to do this is because when user is updating the name field the empty input text for telephone number ovverides the telephone number field in the database. I would aprreciate your help guys, I am trying to create a website that after you receive an email you have to use the email address and password to confirm account. Then the next page allows you to change your password. I want to save the users email from the first page and use it in the SQL statement in the second page to locate the user in the DB and update the data. There must be some problem with the way I have my code logically set up. It will make it to the 2nd step but then it will go back to the main email confirmation page. <?php include('common.php'); include('db.php'); session_start(); session_register('umail'); session_register('password'); session_register('pwd1'); session_register('pwd2'); if(!isset($_POST['email']) && !isset($_POST['password'])) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "BLOCKED URL"> <html> <head> This is a test of my patience</head> <meta http-equov="Content-Type" content="text/html; charset=iso-8859-1"/> </head> <body> <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> Email: <input type="text" name="email" size="8" /> password:<input type="password" name="password" size="8" /> <input type ="submit" name ="submit" value ="submit" /> </form> </body> </html> <? exit; } else { $umail = $_SESSION['umail'] = $_POST['email']; $password = $_SESSION['password'] = $_POST['password']; dbConnect("web2"); $sql ="SELECT * FROM `user` WHERE email ='$umail'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if(!$result) error('Contact DB admin'); if($result='') error('not in db'); if($_SESSION['umail'] != $row['email'] && $_SESSION['password'] != $row['password']) error('Wrong email or password'); } if(!isset($_POST['pwd1']) && !isset($_POST['pwd2'])) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "BLOCKED URL"> <html> <head> This is a test of my patience</head> <meta http-equov="Content-Type" content="text/html; charset=iso-8859-1"/> </head> <body> <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> password: <input type="text" name="pwd1" size="8" /> password confirmation:<input type="password" name="pwd2" size="8" /> <input type ="submit" name ="submit" value ="submit" /> </form> </body> </html> <? } else { $pwd1 = $_SESSION['pwd1'] = $_POST['pwd1']; $pwd2 = $_SESSION['pwd2'] = $_POST['pwd2']; if($_SESSiON['pwd1'] == $_SESSION['pwd2']) { dbConnect("web2"); mysql_query("UPDATE user SET password ='$pwd1' WHERE email ='$umail'"); $sql="SELECT * FROM 'user' WHERE email='$umail'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if($_SESSION['pwd1'] != $row['password']) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "(BLOCKED URl"> <html> <head> This is a test of my patience</head> <meta http-equov="Content-Type" content="text/html; charset=iso-8859-1"/> </head> <body> <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> password: <input type="text" name="pwd1" size="8" /> password confirmation:<input type="password" name="pwd2" size="8" /> <input type ="submit" name ="submit" value ="submit" /> </form> </body> </html> <? } else { error(' the man'); session_unset(); session_destroy(); } } } ?> Hi, I need some help here, the one which I have highlighted in red, 'dob' and 'gender', are not inputting any values into my database table. I'm just wondering did I miss out something important, or should I change the 'type' in my database table? Thanks <?php $dob = $_POST['dob']; $gender = $_POST['gender']; /**INSERT into tutor_profile table**/ $query2 = "INSERT INTO tutor_profile (name, nric, dob, gender, race) VALUES ('$name', '$nric', '$dob', '$gender', '$race')"; $results2 = mysqli_query($dbc, $query2) or die(mysqli_error()); ?> <html> <div> <label for="dob" class="label">Date Of Birth</label> <input name="dob" type="text" id="dob"/> </div> </html> <!--Race--> <div> <label for="race" class="label">Race</label> <?php echo '<select name="race" id="race"> <option value="">--Please select one--</option>'; $dbc = mysqli_connect('localhost', '111', '111', '111') or die(mysqli_error()); $query = ("SELECT * FROM race ORDER BY race_id ASC"); $sql = mysqli_query($dbc, $query) or die(mysqli_error()); while($data = mysqli_fetch_array($sql)) { echo'<option value="'.$data['race_id'].'">'.$data['race_name'].'</option>'; } echo '</select><br/>'; mysqli_close($dbc); ?> </div> Hi people. I have a form which inputs into a database. Here is the code that inserts a yes no option... Code: [Select] <select name = "consent"> <option value = "Yes" <?php if ($_POST['consent'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option> <option value = "No" <?php if ($_POST['consent'] == 'No') { echo 'selected="selected"'; } ?>>No</option> </select> However, I have been asked if I can make it a yes or no checkbox instead. Please can you tell me how I need to code it so that the "yes" or "no" is recorded in the DB. At the moment I just have this Code: [Select] <input name="consent" type="checkbox" value="Yes" />Yes<br /> <input name="consent" type="checkbox" value="No" />No<br /> Thanks in advance VinceG "BACK" or REFRESH: Preventing database interaction / code execution how to prevent database interaction / code execution when user presses back or refresh button? can i detect? can i disable back/refresh? Before I get into my problem a couple of things. First, this is a work project. My organization cannot afford a full time developer so as a database guy I'm being asked to develop a web based data system using php/html/mysql/javacript/etc. So I am not asking anyone to help me cheat or violate an honor code for a school project. Also I am having to learn PHP on the fly, by the seat of my pants. Second, my organization is using a version of PHP older that 5.5.X and I am powerless to update the version. So I know that some of the syntax I am using has been deprecated in more recent PHP versions. I don't mean to sound snarky or ungrateful but I really need some help solving this problem versus unhelpful comments about deprecated code. Third I am adapting code from the guys at TechStream so H/T to them. Here is what I am trying to build. My office helps other offices in my large organization manage their records through the creation of a file plan. We are currently using a clunky, user-unfriendly Access database that was created back in 2009. I am tasked to transition that Access hoopty into a proper, web-based, user friendly system. The index.php form page consists of 2 parts. You can see the original TechStream demo he http://demo.techstre...ssing-with-PHP/ I've adapted the top part of the form ("Travel Information") for my users to enter information about their office such as Office Name, Office Code, Office Chief, Creator (the user), Status and date. I've adapted the bottom part of the form ("Passenger Details") to be "Folder Details". This is an html table where users can add up to 10000 rows to list all the folders for their office by entering the folder name in the text box and then assign descriptors to each folder using the drop down menus. I've changed the drop down menus to reflect the descriptors we need, i.e. file-series, classification, media type. The user needs the flexibility to add folders as the number of folders will vary between offices. This adding and deleting of folders is accomplished dynamically through a javascript script.js file. Now, here's my problem. When the user clicks submit button that fires a php script that runs an insert into query to place the array data into the backend mysql database. However, when the foreach loop is only inserting the office office from the top portion of the form with the first folder in the bottom portion of the form. In other words let's say the user fills out the top part with his office information and then adds 5 folders into the html table at the botton. The first folder will be inserted into the database table with both office information and folder information. However the subsequent 4 folders will have their folder information inserted into the table but the office information fields will be null. The office information needs to be inserted with each folder the user adds to the html table piece. I suspect that my foreach loop is only capturing that office information on the first iteration of the loop and then flushing or deleting the office information after the first loop. Also, I suspect there is some disconnect between the html table for entering individual folders and the top part of the form that is not in html format. Any help I can get is most welcome. Thanks in advance! Code is below. index.php <?php session_start(); if(!isset($_SESSION['myusername'])) { header('Location:index.php'); } echo $_SESSION['myusername']; echo '<a href="logout.php"><span>Logout</span></a></li>'; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Records Management File Plan Application</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" type="text/css" href="css/default.css"/> <script type="text/javascript" src="js/script.js"></script> </head> <body> <form action="InsertFileDetailArraytoDB.php" class="register" method="POST"> <h1>Office File Plan Application/h1> <fieldset class="row1"> <legend>Office Information</legend> <p> <label>Office Code * </label> <input name="officecode[]" type="text" required="required"/> <label>Date* </label> <select class="date" name="day[]"> <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 name="month[]"> <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 name="year[]"> <option value="2013">2013 </option> <option value="2014">2014 </option> <option value="2015">2015 </option> <option value="2016">2016 </option> </select> </p> <p> <label>Office Chief* </label> <input name="officechief[]" required="required" type="text"/> <label>Status* </label> <select name="status[]"> <option value="Draft">Draft </option> <option value="Submitted">Submitted </option> <option value="Approved">Approved </option> </select> </p> <p> <label>Creator * </label> <input name="creator[]" required="required" type="text"/> </p> <div class="clear"></div> </fieldset> <fieldset class="row2"> <legend>Folder Details</legend> <p> <input type="button" value="Add Folder" onClick="addRow('dataTable')" /> <input type="button" value="Remove Folder" onClick="deleteRow('dataTable')" /> <p>(All actions apply only to entries with check marked check boxes.)</p> </p> <table id="dataTable" class="form" border="1"> <tbody> <tr> <p> <td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td> <td> <label>Folder Name</label> <input type="text" required="required" name="BX_NAME[]"> </td> <td> <label for="BX_fileseries">File Series</label> <select id="BX_fileseries required="required" name="BX_fileseries[]"> <option>100-01-Inspection and Survey/PII-NO</option> <option>200-02-Credit Card Purchases/PII-NO</option> <option>300-07-Time and Attendance/PII-YES</option> </td> <td> <label for="BX_classification">Classification</label> <select id="BX_classification" name="BX_classification" required="required"> <option>Unclassified</option> <option>Confidential</option> <option>Secret</option> <option>Top Secret</option> <option>Ridiculous Top Secret</option> <option>Ludicrous Top Secret</option> </select> </td> <td> <label for="BX_media">Media</label> <select id="BX_media" name="BX_media" required="required"> <option>Paper</option> <option>Shared Drive</option> <option>Film</option> <option>Floppy Disk</option> <option>Mixed</option> <option>Other</option> </select> </td> </p> </tr> </tbody> </table> <div class="clear"></div> </fieldset> <input class="submit" type="submit" value="File Plan Complete »" /> <div class="clear"></div> </form> </body> </html>PHP script with foreach loop to loop through the array from index.php and insert into database: InsertFileDetailArrayToDB.php /* When the user has finished entering their folders, reviewed the form inputs for accuracy and clicks the submit button, this will loop through all folder entries and using the SQL insert into query will place them in the database. When it completes data insertion it will redirect the user back to the file detail input form*/ <?php /*this part requires the user to be logged in and allows their user name to be included in the insert into query. If you remove the "ob_start();" piece it will screw up the header statement down at the botton. See the comments by the header statement for an explanation of its purpose*/ ob_start(); session_start(); if(!isset($_SESSION['myusername'])) { header('Location:index.php') } /*these two lines would ordinarily display the user name and a link a allowing the user to log out. However this php script does not output anything so the user will never it.*/ echo $_SESSION['myusername']; echo '<a href="logout.php"><span>Logout</span></a></li>'; ?> <?php /*this include statement connects this script to the MySQL database so the user form inputs can be inserted into the file_plan_details table*/ include ('database_connection.php'); foreach($_POST['BX_NAME'] as $row=>$BX_NAME) { $BX_NAME1 = mysql_real_escape_string($_POST['BX_NAME'); $officecode1 = mysql_real_escape_string($_POST['officecode'][$row]); $username1 = mysql_real_escape_string($_SESSION['myusername'][$row]); $day1 = mysql_real_escape_string($_POST['day'][$row]); $month1 = mysql_real_escape_string($_POST['month'][$row]); $year1 = mysql_real_escape_string($_POST['year'][$row]); $creator1 = mysql_real_escape_string($_POST['creator'][$row]); $officechief1 = mysql_real_escape_string($_POST['officechief'][$row]); $status1 = mysql_real_escape_string($_POST['status'][$row]); $BX_fileseries1 = mysql_real_escape_string($_POST['BX_fileseries'][$row]); $BX_classification1 = mysql_real_escape_string($_POST['BX_classification'][$row]); $BX_media1 = mysql_real_escape_string($_POST['BX_media'][$row]); $fileplandetailinsert1 = "INSERT INTO file_plan_details (folder_name, office_code, user_name, day, month, year, creator, office_chief, status, file_series, classification, media) VALUES ('$BX_NAME1','$officecode1','$username1','$day1','$month1','$year1','$creator1','$officechief1','$status1','$BX_fileseries1','$BX_classification1','$BX_media1')"; mysql_query($fileplandetailinsert1); } /*this header statement redirects the user back to the folder detail input form after it inserts data into the db After I build a main navigation page, I will switch out index.php with whatever I name the script that will produce the main navigation page*/ header('Location:index.php'); ?>script.js function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; if(rowCount < 10000){ // limit the user from creating fields more than your limits var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; } }else{ alert("Maximum Passenger per ticket is 5."); } } function deleteRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { // limit the user from removing all the fields alert("Cannot Remove all the Passenger."); break; } table.deleteRow(i); rowCount--; i--; } } } Edited by mac_gyver, 17 December 2014 - 01:13 PM. code tags around posted code please We recently upgraded from PHP4 to PHP5 and the below script that was working perfectly in 4 has completely stopped working and I can't figure out why for the life of me. I'm not an experienced PHP programmer--I've done some forms, but this is the first time I've used a database. What needs to (and was) happen: A user enters their username in the form and gets a readout of their participation so far that month. The problem(s): I know that it's storing the variable 'user' because it echoes it back properly, but the database is no longer allowing me to select the row based on that variable. I know it's not that I can't connect to the database because if instead of '$user' I change the code to a username I know is in there, I get the proper readout. This all started as soon as I transferred over to PHP5--before that, no problems at all. The database information is all correct, I just took it out for privacy's sake. <form id="feedback" method="post" action="index.php"> <input name="user" type="text" value="Enter user name" size="20" maxlength="50" /><br /> <input name="send" id="send" type="submit" value="Submit" /> </form> <?php if (isset($_POST['user'])) { $_session['user'] = $_POST['user']; } ?> <p>You entered your username as: <strong><? echo $_session['user'];?></strong>. If this is not correct or you do not see your information below, please re-enter your username and click Submit again.</p> <?php $con = mysql_connect("database","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT * FROM March WHERE Username='$user'") or die ('Error: '.mysql_error ()); while($row = mysql_fetch_array($result)) { echo "<table border='0'>"; echo "<tr>"; echo "<td><strong>Username:</strong> </td><td>" . $row['Username'] . "</td></tr>"; echo "<tr><td><strong>Mar. 2 Discussion:</strong></td><td>" . $row['Mar2Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 2 Poll:</strong></td><td>" . $row['Mar2P'] . "</td></tr>"; echo "<tr><td><strong>Mar. 9 Discussion:</strong></td><td>" . $row['Mar9Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 9 Poll:</strong></td><td>" . $row['Mar9P'] . "</td></tr>"; echo "<tr><td><strong>Mar. 16 Discussion:</strong></td><td>" . $row['Mar16Q'] . "</td></tr>"; echo "<tr><td><strong>Mar. 16 Poll:</strong></td><td>" . $row['Mar16P'] . "</td></tr>"; echo "<tr><td><strong>March Participation To-Date:</strong></td><td>" . $row['Participation'] . "</td></tr>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> ANY help would be greatly appreciated! I've got a couple hundred people who use this on a regular basis and are starting to ask why it's not working. I have some code where I am inserting a record into a database. Code: [Select] <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('./includes/config.inc.php'); require_once (MYSQL); $add_cat_errors = array(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check for a name: if (empty($_POST['product'])) { $add_cat_errors['product'] = 'Please enter the name!'; } // Check for a description: if (empty($_POST['prod_descr'])) { $add_cat_errors['prod_descr'] = 'Please enter the description!'; } // Check for a category: if (!isset($_POST['cat']) || !filter_var($_POST['cat'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $add_product_errors['cat'] = 'Please select a category!'; } // Check for a price: if (empty($_POST['price']) || !filter_var($_POST['price'], FILTER_VALIDATE_FLOAT) || ($_POST['price'] <= 0)) { $add_cat_errors['price'] = 'Please enter a valid price!'; } // Check for an image: if (is_uploaded_file ($_FILES['image']['tmp_name']) && ($_FILES['image']['error'] == UPLOAD_ERR_OK)) { $file = $_FILES['image']; $size = ROUND($file['size']/1024); // Validate the file size: if ($size > 512) { $add_cat_errors['image'] = 'The uploaded file was too large.'; } // Validate the file type: $allowed_mime = array ('image/gif', 'image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png'); $allowed_extensions = array ('.jpg', '.gif', '.png', 'jpeg'); $image_info = getimagesize($file['tmp_name']); $ext = substr($file['name'], -4); if ( (!in_array($file['type'], $allowed_mime)) || (!in_array($image_info['mime'], $allowed_mime) ) || (!in_array($ext, $allowed_extensions) ) ) { $add_cat_errors['image'] = 'The uploaded file was not of the proper type.'; } // Move the file over, if no problems: if (!array_key_exists('image', $add_cat_errors)) { // Create a new name for the file: $new_name = (string) sha1($file['name'] . uniqid('',true)); // Add the extension: $new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext); // Move the file to its proper folder but add _tmp, just in case: $dest = "../db/images/$new_name"; if (move_uploaded_file($file['tmp_name'], $dest)) { // Store the data in the session for later use: $_SESSION['image']['new_name'] = $new_name; $_SESSION['image']['file_name'] = $file['name']; // Print a message: echo '<h4>The file has been uploaded!</h4>'; } else { trigger_error('The file could not be moved.'); unlink ($file['tmp_name']); } } // End of array_key_exists() IF. } elseif (!isset($_SESSION['image'])) { // No current or previous uploaded file. switch ($_FILES['image']['error']) { case 1: case 2: $add_cat_errors['image'] = 'The uploaded file was too large.'; break; case 3: $add_cat_errors['image'] = 'The file was only partially uploaded.'; break; case 6: case 7: case 8: $add_cat_errors['image'] = 'The file could not be uploaded due to a system error.'; break; case 4: default: $add_cat_errors['image'] = 'No file was uploaded.'; break; } // End of SWITCH. } // End of $_FILES IF-ELSEIF-ELSE. // Check for a stock: if (empty($_POST['stock']) || !filter_var($_POST['stock'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $add_cat_errors['stock'] = 'Please enter the quantity in stock!'; } if (empty($add_cat_errors)) { $query = 'INSERT INTO product (product, product_descr, catID, price, image, stock) VALUES (?, ?, ?, ?, ?, ?)'; // Prepare the statement: $stmt = mysqli_prepare($dbc, $query); // For debugging purposes: // if (!$stmt) echo mysqli_stmt_error($stmt); // Bind the variables: mysqli_stmt_bind_param($stmt, 'isssdi', $name, $desc, $_POST['cat'], $_POST['price'], $_SESSION['image']['new_name'], $_POST['stock']); // Make the extra variable associations: $name = strip_tags($_POST['product']); $desc = strip_tags($_POST['prod_descr']); // Execute the query: mysqli_stmt_execute($stmt); if (mysqli_stmt_affected_rows($stmt) == 1) { // If it ran OK. // Print a message: echo '<h4>The product has been added!</h4>'; // Clear $_POST: $_POST = array(); // Clear $_FILES: $_FILES = array(); // Clear $file and $_SESSION['image']: unset($file, $_SESSION['image']); } else { // If it did not run OK. trigger_error('The product could not be added due to a system error. We apologize for any inconvenience.'); unlink ($dest); } } // End of $errors IF. } else { // Clear out the session on a GET request: unset($_SESSION['image']); } // End of the submission IF. require_once ('./includes/form_functions.inc.php'); ?> <form enctype="multipart/form-data" action="add_product.php" method="post" accept-charset="utf-8"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" /> Product<br /><?php create_form_input('product', 'text', $add_cat_errors); ?> Description<br /><?php create_form_input('prod_descr', 'textarea', $add_cat_errors); ?> Category<br /><select name="cat"<?php if (array_key_exists('cat', $add_cat_errors)); ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = 'SELECT catID, cat FROM category ORDER BY cat ASC'; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['cat']) && ($_POST['cat'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('cat', $add_cat_errors)) echo $add_product_errors['cat']; ?> Price<br /><?php create_form_input('price', 'text', $add_cat_errors); ?> Image<br /><?php // Check for an error: if (array_key_exists('image', $add_cat_errors)) { echo $add_cat_errors['image'] . '<br /><input type="file" name="image"/>'; } else { // No error. echo '<input type="file" name="image" />'; // If the file exists (from a previous form submission but there were other errors), // store the file info in a session and note its existence: if (isset($_SESSION['image'])) { echo "<br />Currently '{$_SESSION['image']['file_name']}'"; } } // end of errors IF-ELSE. ?> Stock<br /><?php create_form_input('stock', 'text', $add_cat_errors); ?> <input type="submit" value="Add This Product" class="button" /> </fieldset> </form> However, I have a problem - i get this error message; An error occurred in script 'C:\Users\David Morgan\Desktop\WEBSITES\hairz_&_graces\site\admin\add_product.php' on line 124: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given How do I solve this as I think I have everything in place (variable associations, etc)? Hello, I am attempting to create a script where a user puts a text string into a form and clicking on submit. Then it adds that text string to a mysql database and gives the user a link back to it. Something like mysite.com/key.php?id=4 and when going to that link it will display the text string from the database but printed in an image. I wrote something up but I cannot get it to work. I may be a little in over my head. Any help is appreciated.
The way I coded this all to work is the user inputs the information into index.php which givekey.php inserts that into the database. I have not yet figure out how to do this in one single step. After that I wanted it to navigate directly to key.php which would display the key and the link to that page with the ?key=XX attribute. getkey.php <?php require_once 'dbinfo.php'; // database connection $id = $_GET['id']; // do some validation here to ensure id is safe $link = mysql_connect($servername, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } @mysql_select_db($database) or die( "Unable to select database"); $sql = "SELECT ukey FROM keycode WHERE id=$id"; $result = mysql_query("$sql"); $row = mysql_fetch_assoc($result); mysql_close($link); header("Content-type: image/png"); echo $row['ukey']; ?> key.php <html> <head> <title>Your Key Is Ready</title> </head> <body> <img src="getkey.php?id=1" width="175" height="200" /> </body> </html>index.php <html> <head> <title></title> </head> <body> <section id="mid_section"> <div id="boxes"> <h1> Testing input key </h1> <br/> <form id="myform" action="givekey.php" method="post"> Key:<br /> <input type="text" value="ukey"> Source:<br /> <input type="radio" value="hb">HB<br /> <input type="radio" value="ig">IG<br /> <input type="radio" value="other">Other<br /> <button id="sub">Submit</button> </form> </body> </html>givekey.php <?php include_once('dbinfo.php'); $conn = mysql_connect($servername, $username, $password); $db= mysql_select_db($database); $ukey =$_POST['ukey']; $hb =$_POST['hb']; $ig =$_POST['ig']; $other =$_POST['other']; if(mysql_query("INSERT INTO `keycode`(`ukey`) VALUES ([$ukey]); INSERT INTO `source`(`hb`,`ig`,`other`) VALUES ([$hb],[$ig],[$other]);")) ?> Edited by chrisb302, 13 November 2014 - 12:18 AM. As a complete newbie to php and webdesigning i have a following problem.I would like to retrieve the data from database and display it in a drop down menu.Then i should allow the user to select the values from drop down list along with other details,in other words i have to embed the drop down output as the form input for the user and store the form data in another table.I am running a xampp server and i am using php 5.4 version.Please help.My code is as follows.In this case project_name is displayed as the drop down output.but how do i use the same drop down output as a input in the form. <html> <head></head> <body> <?php error_reporting(E_ALL ^ E_DEPRECATED); include 'connect.php' ; $tbl_name="projects"; $sql="SELECT project_name FROM $tbl_name "; $result=mysql_query($sql); if($result === FALSE) { die(mysql_error()); } ?> <form name="resources" action="hourssubmit.php" method="post" > <?php echo "<select name='project_name'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['project_name'] ."'>" . $row['project_name'] ."</option>"; } echo "</select>"; ?> </form> </body> </html> |