PHP - How To Truncate Some Of Data Before Entry Into Database?
Hello all.
I am finishing up a paypal IPN php script and was wondering how I can take some data and cut some of it off before I enter it into the mysql database? Heres what I have. $payment_date = HH:MM:SS DD Mmm YY, YYYY PST This comes from paypal. I want to in my code take that and automatically cut off the HH:MM:SS part. So my question is, how can I take a known piece of data and automatically trim the first 9 spots off of it? Something like: $payment_date = HH:MM:SS DD Mmm YY, YYYY PST Minus 1 thru 9 of $payment_date = $result $payment_date2 = $result Any help? Thanks! Similar Tutorialsi'm trying to get the username of the last person to enter something into a database table,and display it an html table. the problem is, the query is failing, and i get the error "Table 'forum.posts' doesn't exist". if in the error message "forum" means the name of the database, and "posts" the name of the table, there is something wrong, as they both exist. the code i'm using is below $list = "SELECT * FROM section_main ORDER BY section_title"; $result = mysql_query($list) or die ("Query failed"); $numofrows = mysql_num_rows($result); for($j = 0; $j < $numofrows; $j++) { $row = mysql_fetch_array($result); echo "<tr><th>". $row['section_title']."</th></tr>"; $query2 = "SELECT * FROM section_sub WHERE section_id = '".$row['section_id']."' ORDER BY section_sub_title"; $result2 = mysql_query($query2) or die("Select Error :" . mysql_error()); $numofrows2 = mysql_num_rows($result2); for($i = 0; $i<$numofrows2; $i++){ $row2 = mysql_fetch_array($result2); echo "<tr><td><a href='display_forum.php?id={$row2[section_sub_id]}'>".stripslashes($row2[section_sub_title])."</a></td><td>"; $new = mysql_query("Select * FROM posts WHERE section_sub_id = '".$row2['section_sub_id'] . " ' ") or die ("Select Error :" . mysql_error()); //this is where the error message is from $lastpost = mysql_fetch_assoc($new); echo $lastpost['username']; echo"</td></tr>"; } } i've checked that the names of the tables and fields in the queries are correct, but i cant think of anything else that might be wrong. any help would be great. I'm working on an old cms I built a few years ago and for some reason my Delete page isn't working. It has to be something simple I'm overlooking. The database connection is made just above this code and is pulling the thumb and title listed by id. When I push delete I'm getting the cmd=delete&id=2 passed on so something is up with my last if statement (I think). Here is the code: if(!isset($cmd)) { //display all the news $result = mysql_query("select * from verizon order by id"); //run the while loop that grabs all the news scripts while($r=mysql_fetch_array($result)) { //grab the title and the ID of the enws $title=$r["title"];//take out the title $id=$r["id"];//take out the id $thumb=$r["thumb"]; echo "<div id='delete'> <table> <tr> <td width='350px'><strong>$title</strong></td><td><a href='verizondelete.php?cmd=delete&id=$id'> Delete</a></td> </tr> <td colspan='2' align='center'><img src='../upload/verizon/$thumb'></td> </table> </div><br />"; } } if($cmd=="delete") { $sql = "DELETE FROM verizon WHERE id='$id'"; $result = mysql_query($sql); echo "<h1 style='text-align:center;'>deleted!</h1>"; } } ?> Hi I'm very much a newbie to PHP and am struggling with a registration and login problem. The registration part is fine - the password is emailed out fine, I check the database and the entry is there, the password is encrypted. but when the user tries to log in.... if (mysql_num_rows($result) == 0) .... it returns 0? and the access denied page is shown. I'm thinking it is something to do with the sql database encryption? I'm completely lost here and would appreciate some guidance Thanks in advance Jan Hi everyone, I need a little bit of help finishing off my code. Ive managed to get this far. Code: [Select] <?php mysql_connect("") or die ("Not Connected to MYSQL"); echo "</br>"; mysql_select_db("") or die ("Not Connected to DB"); // Database Connection stuff $partialNumber = $_POST['partialNumber']; // Post the Partial number $partialNumber = strtoupper($partialNumber); $numberSearch = mysql_query("SELECT * FROM product_option_value_description WHERE name LIKE '%$partialNumber%'") or die (mysql_error()); // Query to select the key number //Query to get product ID // $productId = "SELECT product_id FROM product_option_value_description"; //Query to get product ID // while ($keyNumber = mysql_fetch_array($numberSearch)) { $id = $keyNumber['product_id']; // Query for the images // $query = "SELECT image FROM product WHERE product_id = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result) or die(mysql_error()); $query2 = "SELECT product_option_id FROM product_option_value WHERE product_id = '$id'"; $result2 = mysql_query($query2); $row2 = mysql_fetch_array($result2) or die(mysql_error()); $query3 = "SELECT product_option_value_id FROM product_option_value WHERE product_id = '$id'"; $result3 = mysql_query($query3); $row3 = mysql_fetch_array($result3) or die(mysql_error()); ?> <div> <br /><br /> Key Number: <? echo $keyNumber['name']; ?></a> <form action="http://www.co.uk/teststore/index.php?route=checkout/cart" method="post" enctype="multipart/form-data" id="product"> <br /> <table style="width: 100%;"> <tr> <td> Colour: <select name="option[<? echo $row2['product_option_id']; ?>]"> <option value="<? echo $row3['product_option_value_id']; ?>"></option> </select></td> </tr> </table> <div class="content"> Qty: <input type="text" name="quantity" size="3" value="1" /> <input type="hidden" name="product_id" value="<? echo $id; ?>" /> <input name="submit" type="submit" value="Add to Cart" /> </div> </form> <? echo $row3['product_option_value_id']; ?> </div> <br /> <img height="150" width="150" src='http://www.co.uk/teststore/image/<? echo $row['0']; ?>'/> <? } ?> And here is my SQL Table code. Code: [Select] product_option_value_id product_option_id product_id 599 302 49 598 302 49 589 297 42 588 297 42 So as you can probably tell, it is a search program that looks for products on a shopping cart. The products will have different option values, and the php script will grab the option values and echo them in a form to post back to the cart to add the product to the basket. The problem is that the "product_option_value_id" can have lots of different values, but my code echos only the first one it finds. So when I click the add to cart button, it will only add the first option value for the product it finds. For some reason I am having a hard time explaining this, so I hope someone can help me. Thanks for looking. Hey guys, im new around here, and i have just recently started teaching myself PHP, by looks of this site i seem very experienced but im eager to learn I seem to get an error with this code. The point of this code is to look into my database and pull out all entries with the first name _____ (whatever the user inputs) Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\searchans.php on line 12 Code: Filename:search.php Code: [Select] <html> <form action='searchans.php' method='POST'> First Name: <input type='text' name='firstname'><br> <input type='submit' value='Search'> </form> </html>Code: Filename:searchans.php Code: [Select] <?php $firstname = $_POST['firstname']; $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } $query = mysql_query("SELECT * FROM Persons WHERE FirstName='$firstname'"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName'] . " " . $row['Age']; echo "<br />"; } ?> No errors come up when I run this but it just doesn't delete the entry. <? $rec = $_POST['stock']; if (!$rec){ die ('Please eneter a stock number'); } $link = mysql_connect("xxxx","xxx","xxx"); mysql_select_db('wadkin', $link) or die( "Unable to select database"); mysql_query("DELETE FROM 'wadkin'.'stocklist' WHERE 'stocklist'.'Stock Number' = $rec") or die ('Query failed'); mysql_close($link); ?> Can someone please correct, (btw I have also tried... "DELETE FROM stocklist WHERE 'Stock Number' = $rec") Hi, Would someone please give me some assistance on how to display random products from my database I need to display a maximum of 6 images and there link in two rows of 3 so; [image] [image] [image] [image] [image] [image] and each image would have something like; <a href="<? echo $row['product_link'] ?>"><img src="<? echo $row['product_image'] ?>"/></a> but i don't know how to display these at random and make sure only 6 appear at a time. Thanks for any help, hope you understand what im trying to explain Dear All, I am developing a website www.computationalphotography.in on which I need to register new users. I have designed an HTML form for this purpose, but will need help with writing the code for checking and validating the data in the respective fields. The code for my web form is below and the address of the website is www.computationalphotography.in/registration.php: Code: [Select] <html> <head> <title> Photography Experiment Registration </title> </head> <body> <h1> Questionnaire </h1> <h3> We would like to know about your background and interests in photography. For each multiple-choice question, please circle all answers that apply.</h3> <form method="post" action="registration.php"> Name <input name="name" type="text"> <br> <br> <input name="email" type="text"> <br> <br> 1.) Roughly How many pictures do you take each year? <br> <br> <input name="radios" type="radio" value="a"> a) a few: <10 in a year <br> <input name="radios" type="radio" value="b"> b) many: probably 100's a photos a year <br> <input name="radios" type="radio" value="c"> c) a lot: probably 1000's of photos a year <br> <br> 2.) Do you share your pictures with anyone? <br> <input name="radios" type="radio" value="a"> a) No <br> <input name="radios" type="radio" value="b"> b) Yes, but only with friends or family <br> <input name="radios" type="radio" value="c"> c) Yes, I share with friends or family and also post on public sites such as Flickr, Picasaweb, or Snapfish for anyone to see. <br> <input name="radios" type="radio" value="d"> d) Yes, I share frequently and I have also published my photos in books or magazines, or exhibitde my photos in shows. <br> <br> 3.) How much training in photography have you had? <br> <input name="radios" type="radio" value="a"> a) None <br> <input name="radios" type="radio" value="b"> b) Some, but it's self-taught from books or websites <br> <input name="radios" type="radio" value="c"> c) Quite a bit: I have taken courses in photography <br> <input name="radios" type="radio" value="d"> d) A lot:I have completed a degreee or certificate in the subject <br> <br> 4.) How do you describe yourself as a photographer? <br> <input name="radios" type="radio" value="a"> a) A novice:someone who takes a few pictures occasionally <br> <input name="radios" type="radio" value="b"> b) An amateur:someone who takes many photos, but doesn't usually share them <br> <input name="radios" type="radio" value="c"> c) An enthusiast:someone who loves to take pictures, possibly shows them with oters on public sites, or who might own a DSLR, or frequently uses a camera in other than "automatic mode" <br> <input name="radios" type="radio" value="d"> d) An expert:skilled photographer who has published their work, or exhibited their work in shows, or has been paid for their work <br> <br> 5.) Do you have artistic training or exposure? <br> <input name="radios" type="radio" value="a"> a) No <br> <input name="radios" type="radio" value="b"> b) I visit museums or art galleries <br> c) I have studied art: please describe <br> <textarea name="data5c" cols="50" rows="5"> </textarea> <br> d) I am a practicing artist: please describe <br> <textarea name="data5d" cols="50" rows="5"> </textarea> <br> <br> 6.) Some optional information, if you don't mind. We respect your privacy. <br> <br> Age <br> <textarea name="6a" cols="1" rows="1"> </textarea> <br> <br> Gender <br> <input name="radios" type="radio" value="a"> a) Male <br> <input name="radios" type="radio" value="b"> b) Female <br> <br> Languages Spoken <br> <textarea name="6b" cols="25" rows="2"> </textarea> <br> <br> Languages Read <br> <textarea name="6c" cols="25" rows="2"> </textarea> <br> <br> <br> <input type="submit" value="Send"> <input type="reset" value"Reset"> </form> </body> </html> Kindly help me out with this issue. Thank you for your help in this regard. Need help in achieving a data entry grid. I have two tables am_user (idam_user, name) and am_activity (idam_act, act) with the data Data for am_user is 1, John 2, Mary 3, Kate Data for am_activity is 1, Cooking 2, Cleaning 3, Painting I have a third table that stores the role played by each user for the activities. am_role (idam_role, role) 1, Manage 2, Observe 3, Documents I want my User table to be my header, Activity table to my 1st column and Role table to populate the data grid John Mary Kate Cooking Manage Document Observe Cleaning Document null Manage Painting Observe Document Manage By putting two while loops I am able to generate the header and 1st column but I need help in populating the grid in between. Also I want my data entry area (rows and column besides header and 1st column) to have lookup where they can select values from the am_role table. So, John can "Manage" "Painting" tomorrow if he wants to The two while loops are Code: [Select] $query = "select idam_user, Name "; $query .= " from am_user "; $result = mysql_query($query) or die(mysql_error()); // display data in table echo "<center>"; echo "<table>"; echo "<tr>"; echo "<th></th>"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo '<th>' . $row['name'] . ' '; echo "</th>"; } echo "</tr>"; $query = "select idam_act, act "; $query .= " from am_activity "; $result = mysql_query($query) or die(mysql_error()); // display data in table // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo '<tr>'; echo '<td>' . $row['act'] . '</td>'; echo '</tr>'; } // close table> echo "</table>"; echo "</center>"; Please advise if this thought is realistic and how can I achieve it. Thanks in anticipation. hey guys, I'm getting a problem uploading my csv file to mysql database, the code on the top half just makes sure that I don't import data that I don't want into the database, numbers that are too high or too low on certain rows, and the second half is importing the array that I create from the csv file into the database however I'm getting the following error
Duplicate entry 'Array' for key 'strProductCode'
Now I've never had this error before and I'm not sure what's causing it so any help would be very much appreciated
$data = array(); if (($handle = fopen("stock.csv", "r")) !== FALSE) { while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { // only add rows to the array where the 4th column value is greater than or equal to 10 if(($row[3] >= 10 && $row[4] >= 5) OR ($row[3] >= 0 AND $row[4] > 5)){ if($row[4] < 1000){ $data[] = $row; } } } foreach ($data as &$value) { mysql_query("INSERT INTO tblProductData (intProductDataId, strProductCode, strProductName, strProductDesc, strProductStock, strProductCost, dtmDiscontinued, dtmAdded, stmTimestamp) VALUES(null, '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', 'time', 'added', 'time') ") or die(mysql_error()); } } Hello PHPfreaks members, I want my PHP coding to read/fetch my database's first attribute/entry like the first number of the client in that first row and then fetch it to be shown on PHP so that it will show '1'. How would I do that? Here's the table of my example database (MySQL) I know the command to select the line via the database is this: SELECT * FROM CUSTOMER WHERE CUST_NO=1; Can anyone point out what's wrong with my feedback.php? It used to work fine and I don't think I did anything but it stopped working - i.e. I had it on a site which I never looked at and when I did look at it I noticed the rubbish written to the database had inexplicably stopped being written there some months ago..... since then I've tried to clean it up and use it elsewhere ( I'm a baby at php and most else) but I can't get it to go right. In this attempt it was giving me the dreaded 'headers already written..' error and I (after googling) took out all the blank space I could and extra comments and what not and stuck in some debugging prints for me and now I get no errors but I get nothing written to the database and no email sent to me. If anyone cares to look at it to help me out, here it is, warts and all, with just the names changed to protect the innocent. <? // mail it $mailto = 'med@yahoo.com' ; $subject = "Ploverpark Feedback Form" ; $formurl = "feedback.html" ; $errorurl = "error.html" ; $thankyouurl = "thankyou.html" ; $uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $username = $_POST['username'] ; $firstname = $_POST['firstname'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $secondname = $_POST['secondname'] ; $country = $_POST['country'] ; $phone = $_POST['phone'] ; // do write to database now--------------------------- $link = mysql_connect("mydb.com", "my_pkguest", "password") or die("Could not connect : " . mysql_error()); print "Connected successfully<p>"; $DB = "my_pkguest"; $table = "clients"; mysql_select_db($DB) or die ("Database $DB not select.." . mysql_error()); print "Successfully select the Database: $DB "; $query = "INSERT INTO $table(username,firstname,secondname,email,country,phone,comments) values('$username','$firstname','$secondname','$email','$country','$phone','$comments')"; print "Successfully inserted to table: $table "; //------------------------------------------------------ $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } print "Now past the if isset "; //if (empty($name) || empty($email) || empty($comments)) { // header( "Location: $errorurl" ); // exit ; //} if ( ereg( "[\r\n]", $username ) || ereg( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } print "Now past the if ereg "; if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "UserName of sender: $username\n" . "Firstname of sender: $firstname\n" . "Secondname of sender : $secondname\n" . "Country of sender : $country\n" . "Phone number of sender: $phone\n" . "Email of sender: $email\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; print "Now past the messageproper "; mail($mailto, $subject, $messageproper, "From: \"$username\" <$email>" . $headersep . "Reply-To: \"$username\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" ); print "Now past the mail"; //header( "Location: $thankyouurl" ); // exit ; ?> I'm making a login area for the hotels in a booking system, where they enter their hotels' information, policy, and room rates but I want to make the room rates when it appears for clients, it appears with a percentage (commission) added to what the Hotel representative will enter So what's better? it should be added in the admin area of the hotels and gets saved in the database with the commission or I should add it in the booking form so the code grab the rate from the database, multiply it by the percentage and echo the result? I'm creating a newsletter and the unsubscribe isn't deleting the database entry like I'm asking it to. Everything else works fine, it even successfully says the user has been removed, but it doesn't actually delete the database entry. I've spent two days trying to figure out why. Here's the code:
Newsletter sign up: <?php //DB Connect Info $servername = ""; $database = ""; $username = ""; $password = ""; // Create connection $conn = mysqli_connect($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } /*$createTable = $conn->prepare ("CREATE TABLE IF NOT EXISTS email_user ( id int(11) NOT NULL AUTO_INCREMENT, email varchar(200) NOT NULL, hash varchar(250) NOT NULL, PRIMARY KEY (id) )"); $createTable->execute(); */ function input_security($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $email = input_security($_POST['email']); $insertData = input_security($insertData); if(isset($_POST['submit'])) { extract($_POST); if($email!="") : $email=mysqli_real_escape_string($conn,$email); $emailval = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/'; if(preg_match($emailval, $email)) : $db_check=$conn->query("SELECT * FROM email_user WHERE email='$email'"); $count=mysqli_num_rows($db_check); if($count< 1) : $hash=md5($email.time()); $link = '/unsubscribe.php?key='.$hash; // Change your domain $fetch=$conn->query("INSERT INTO email_user(email,hash) VALUES('$email','$hash')"); $to="$email"; //change to ur mail address $strSubject="Maintenance Fee Relief, LLC | Email Subscription"; $message = '<p>Thank you for subscribing with us.</p>' ; $message .= '<p>Click here to unsubscribe your email : <a href="'.$link.'">unsubscribe</p>' ; $headers = 'MIME-Version: 1.0'."\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n"; $headers .= "From: info@"; $mail_sent=mail($to, $strSubject, $message, $headers); $msg_sucess="Your request has been accepted!."; else : $msg="This $email email address is already subscribe with us."; endif; else : $msg="Please enter your valid email id"; endif; else : $msg="Please fill all mandatory fields"; endif; } ?> <div class="newsletter-sign-up-header-form"> <div id="logerror"><?php echo @$msg; ?><?php echo @$msg_sucess; ?></div> <form method="post"> <span><input type="email" name="email" placeholder="Email Address - Join Newsletter" class="newsletter-sign-up-header-email" required></span> <span><button name="submit" value="submit" title="Submit" class="newsletter-sign-up-header-submit-button">Submit</button></span> </form> </div> <?php //DB Connect Info $servername = ""; $database = ""; $username = ""; $password = ""; // Create connection $conn = mysqli_connect($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?> <?php if(@$_GET['key']!=""): $hash=mysqli_real_escape_string($conn,$_GET['key']); $fetch=$conn->query("SELECT * FROM email_user WHERE hash = '$hash'"); $count=mysqli_num_rows($fetch); if($count==1) : $row=mysqli_fetch_array($fetch); $conn->query("DELETE email_user WHERE id='$user_id'"); $msg="Your email id unsubscribe with us"; else : $msg="Please click valid link."; endif; else : header("Location:404.php"); endif; ?> <!doctype html> <html lang="en"> <head> <title>Unsubscribe</title> </head> <body> <div align="center"> <h2><?php echo $msg; ?></h2> <a href="https://www.--.com">--.com</a> </div> Quote
Hello there,
I would be really grateful if someone could advice please, how do I find this pesky entry in the 'db' table? This is what it says,
"Found an entry in the 'db' table with empty database name; Skipped." MySQL version is 5.5.40
I am pretty much stuck on it. Does it mean the table's name is db? Plus, I am not sure I understand the wording of it too. The empty database name cannot exist by default as it won't allow you to create a database without a name in the first place. I do not even know how and where to begin to look for it because honestly speaking I do not quite understand the phrase itself, because it does not make much sense to me. I would really highly appreciate it if someone could explain and suggest how do I find the... "whatever it says" :-) and to fix it. Many thanks in advance!
P.S. I know this warning may easily and safely be ignored as it is of minor inconvenience and not that important the more so as MySQL is working fine but my curiosity is just running wild for two reasons: 1. I do not really understand what this warning message is trying to tell me and 2. How do I find and adjust it to turn off the warning.
Simple regular things as running myisamchk -r *.MYI on where MySQL is did not help as this warning is actually out of scope of what myisamchk can fix.
And yes, I've Googled it long enough but couldn't seem to come up with anything reasonable solutions.
Thankful for any suggestions / pointers / assistance / comments at all.
Edited by Klaipedaville, 29 October 2014 - 06:17 AM. Newbie here, I am actually a math teacher working on creating a simulated store front for my students where they keep up with inventory, budgeting etc. Everyday my students will have to look at how much product is in stock, how much product was sold, and then input how much should be ordered for the next day. I am working on an answer key that will be used to validate students input but the 'quantity' and 'sold' fields will be relative to the most recent post. Right now the code below pulls all the rows under 'quantity', but I need it to only pull the most recent post. I have done my best to search the forum and try to find how to do this, but admittedly I am not even really sure what to be searching for. Any help would be great. Code: [Select] <?php $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myDatabase", $con); $result = mysql_query("SELECT * FROM myTable"); while($row = mysql_fetch_array($result)) { $quantity = $row['quantity']; $sold = $row['numbersold']; $needed = $row['remaining']; echo $needed-($quantity-$sold); } mysql_close($con); ?> I am trying to set up a item entry page form.png: Upon submission it shows unsuccessful even though I have checked the fields on mysql table and seem to be good am I missing something? Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="Product_Entry"> <TABLE> <TR> <TD>Product ID</TD><TD><input name="SKU_ProductID" value="<?php if (isset($_post['SKU_ProductID'])) echo $_POST['SKU_ProductID']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Merchant SKU ID</TD><TD><input name="SKU_MerchSKUID" value="<?php if (isset($_post['SKU_MerchSKUID'])) echo $_POST['SKU_MerchSKUID']; ?>" type="text" size="18" maxlength="30" /></TD> </TR> <TR> <TD>Game Title</TD><TD><input name="Game_Title" value="<?php if (isset($_post['Game_Title'])) echo $_POST['Game_Title']; ?>" type="text" size="40" maxlength="40" /></TD> </TR> <TR> <TD>Platform</TD><TD><input name="Platform" value="<?php if (isset($_post['Platform'])) echo $_POST['Platform']; ?>" type="text" size="20" maxlength="20" /></TD> </TR> <TR> <TD>Genre</TD><TD><input name="Genre" value="<?php if (isset($_post['Genre'])) echo $_POST['Genre']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Weight</TD><TD><input name="Weight" value="<?php if (isset($_post['Weight'])) echo $_POST['Weight']; ?>" type="text" size="7" maxlength="7" /></TD> </TR> <TR> <TD>Supplier</TD><TD><input name="Supplier" Value="<?php if (isset($_post['Supplier'])) echo $_POST['Supplier']; ?>" type="text" size="25" maxlength="25" /></TD> </TR> <TR> <TD>Suppliers Price</TD><TD><input name="Supplier_Price" value="<?php if (isset($_post['Supplier_Price'])) echo $_POST['Supplier_Price']; ?>" type="text" size="10" maxlength="12" /></TD> </TR> <TR> <TD>Cashback</TD><TD><input name="Cashback" value="<?php if (isset($_post['Cashback'])) echo $_POST['Cashback']; ?>" type="text" size="6" maxlength="8" /></TD> </TR> <TR> <TD>Cashback Amount</TD><TD><input name="Cashback_Amount" value="<?php if (isset($_post['Cashback_Amount'])) echo $_POST['Cashback_Amount']; ?>" type="text" size="7" maxlength="11" /></TD> </TR> <TR> <TD><input type="hidden" name="submitted" value="true"/></TD><TD><input name="Submit" type="submit" value="Add_Product" /></TD> </TR></form></TABLE> <?php # Product Entry $page_title = 'Product Entry'; if (isset($_POST['Submit'])) { $errors = array(); if (empty($_POST['SKU_ProductID'])) { $errors[] = 'Please enter Product ID.'; } else { $sid = trim($_POST['SKU_ProductID']); } if (empty($_POST['SKU_MerchSKUID'])) { $errors[] = 'Please enter Merchant SKU.'; } else { $mid = trim($_POST['SKU_MerchSKUID']); } if (empty($_POST['Game_Title'])) { $errors[] = 'Please enter Game Title.'; } else { $gt = trim($_POST['Game_Title']); } if (empty($_POST['Platform'])) { $errors[] = 'Please enter Platform.'; } else { $pl = trim($_POST['Platform']); } if (empty($_POST['Genre'])) { $errors[] = 'Please enter Genre.'; } else { $ge = trim($_POST['Genre']); } if (empty($_POST['Weight'])) { $errors[] = 'Please enter Weight.'; } else { $we = trim($_POST['Weight']); } if (empty($_POST['Supplier'])) { $errors[] = 'Please enter Supplier.'; } else { $sup = trim($_POST['Supplier']); } if (empty($_POST['Supplier_Price'])) { $errors[] = 'Please enter Supplier Price.'; } else { $sp = trim($_POST['Supplier_Price']); } if (empty($_POST['Cashback'])) { $errors[] = 'Please enter Cashback %.'; } else { $cb = trim($_POST['Cashback']); } if (empty($_POST['Cashback_Amount'])) { $errors[] = 'Please enter Cashback Amount.'; } else { $cba = trim($_POST['Cashback_Amount']); } if (empty($errors)) { require_once ('connect.php'); [b]$q = "INSERT INTO `Products` (`SKU_ProductID`, `SKU_MerchSKUID`, `Game_Title`, `Platform`, `Genre`, `Weight`, `Supplier`, `Supplier_Price`, `Cashback`, `Cashback_Amount`) VALUES ('$sid', '$mid', '$gt', '$pl', '$ge', '$we', '$sup', '$sp', '$cb', '$cba')"; $r = @mysql_query ($dbc, $q); if ($r) { // If it ran OK. // Print a message: echo '<h1>Thank you!</h1> <p>Product Inserted!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection.[/b] // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { echo '<H1>Error!</H1> <p class="error">The Following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } ?> If there is anything else needed let me know Hello,
I've tried to get a dynamic table from an external page, and searching for entries in it, so i used a dynamic XLS file using php excel reader. I only exported the file, but i couldn't search for data.
Can i get some help please ?
I'm trying to have a running total of the number of views an image gets. My test file works perfectly every time. The actual file, image_win.php, does not and after much testing can't see what's wrong. This files STRANGENESS: the first two views count fine, with 1 added the total in the field image_visit. But every time after that 2 is added to the total in image_visit. Very bizarre. Thanks for taking a look -Allen Code: [Select] <?php ////////TEST IMAGE_WIN //////////THIS WORKS include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $art_id = 372; $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = image_visit +1 WHERE user_id = '$owner_id'"); ?> <?php //////// image_win.php /////////THIS DOES NOT WORK $user_id=$_SESSION['user_id']; include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $image_link = $_GET['image_link']; $art_id = $_GET['art_id']; ?> <!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" /> <meta name="viewport" content="width=device-width, height=device-height, target-densityDpi=device-dpi"> <title>Image Window</title> </head> <body bgcolor="#000000" leftmargin="0"> <div align="center" > <img src="slir/w640-h535/<?php echo $path.$image_link.$postCat; ?>" /> <?php $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = (image_visit +1) WHERE user_id = '$owner_id' "); ?> MOD EDIT: code tags added. Alright, wasn't quite sure how to summarize this in the title, but I want to: Check if a user status is "active" or not based on the UserName input. I have a table witch holds: Code: [Select] VarChar Username Var CharPassWord int Active Ted TedsPW 1 something like the above(assuming it formatted correctly. In my php script I will want to input a variable for Username to check for: inputUN in this example would be "Ted". $UserNameToCheck = $_GET['inputUN']; Then I want to check for that UserName in the database, if it exists, I want pull the value for the "Active" field for just that UserName and echo it. Thanks for any help. |