Jump to content

Search the Community

Showing results for tags 'database'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I'm a PHP beginner - I'm not sure what is wrong with this code. The problem: When $qotw is equal to 1 or when it is equal to 2, neither statement is being executed (see code below). I am not getting any errors. What I tried: I tried putting if($qotw = '1') instead of if(qotw == '1') and if(qotw = '2') instead of if(qotw == '2'). In that case the 'cash' increased as it was supposed to. However, when $qotw was equal to 2, the first statement still executed and the second one did not (the 'cash' value was still increasing and the message that should be displayed according to the 2nd IF statement did not show up). The 'cash' value and 'qotw' value should only increase when $qotw is equal to 1. Please help me fix this so that BOTH statements will execute at the appropriate times. Thanks! Here is my code: <?php $con=mysqli_connect("localhost","users","password","users"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //statement1 if($qotw = '1') { mysqli_query($con,"UPDATE users SET cash = cash + $scash WHERE username = '". $_SESSION['username'] . "'"); mysqli_query($con,"UPDATE users SET qotw = 1 + qotw WHERE username = '". $_SESSION['username'] . "'"); } //statement2 if($qotw = '2') { echo "You have already attempted this question."; } mysqli_close($con); ?>
  2. Hello. I want to show in my website all entries from a table, but I only want to show some values in one of the DB columns: Copyright Imagem: <?php echo $row["copyright"]; ?></p> Whati I want is to show all entries for $row["copyright"], except the ones in what the value is "null". The remaining columns, I want to show all of them.
  3. I have my form created, and want to link it to an insert.php file where I can save data to database. Normally, I would have done it like this: <form method="post" action="insert.php"> Although, I have done my form a different way than usual to help security precautions(Reference: http://www.w3schools.com/php/php_form_complete.asp) <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name" value="<?php echo $name;?>"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email" value="<?php echo $email;?>"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Website: <input type="text" name="website" value="<?php echo $website;?>"> <span class="error"><?php echo $websiteErr;?></span> <br><br> Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea> <br><br> Gender: <input type="radio" name="gender" <?php if (isset($gender) && $gender=="female") echo "checked";?> value="female">Female <input type="radio" name="gender" <?php if (isset($gender) && $gender=="male") echo "checked";?> value="male">Male <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="Submit"> </form> My form's action attribute is filled with php code already, so where do I link to my insert.php file now? Can I still put a file name next to the php code that is already there? Can I do it like this, adding an onclick attribute that links to insert.php file?: <input type="submit" name="submit" value="Submit" onclick="insert.php">
  4. Hello I'm new on this forum, I have a commercial project (a software with licence renovation every year), I want to every time I have a new client, register on a mysql database, so when the client pay (on paypal) a licence renovation after the payment redirect to a php login site, when the client get logged show a kind of validator where the client can type the renovation number to generate and show the unlock code at the same time automatically it is sent to the clients email, after that, if the user wants to log in again, show only the unlock code, until the client do a payment and show the validator again, and so on.. Is all this possible? I already have a hosting with php and mysql database, but I don't have any knowledge on php, also I have no idea how to make the validator on a website, but It's based on math operations so I think it wont be a problem
  5. i want to retrieve username from database table and display it where i put the code $username , i'm using the following code to make it work but its giving me an error : <?php require_once("models/config.php"); if (!securePage($_SERVER['PHP_SELF'])){die();} require("models/db-settings.php"); $mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name); $result = $mysqli->query("SELECT user_name FROM upl_users"); // This will move the internal pointer and skip the first row, we don't want that. //$row = mysql_fetch_assoc($result); //echo $row['user_name']; while ( $row = $result->fetch_assoc() ) { $username = $row['user_name'];} $dir = 'uploads/$username/'; if (file_exists($UploadedDirectory)) { mkdir('uploads/$username/', 0777, true); } if(isset($_FILES['FileInput']) && $_FILES['FileInput']['error']== UPLOAD_ERR_OK) { ############ Edit settings ############## $UploadDirectory = 'uploads/$username/'; //specify upload directory ends with / (slash) ########################################## /* Note : You will run into errors or blank page if "memory_limit" or "upload_max_filesize" is set to low in "php.ini". Open "php.ini" file, and search for "memory_limit" or "upload_max_filesize" limit and set them adequately, also check "post_max_size". */ //check if this is an ajax request if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){ die(); } //Is file size is less than allowed size. if ($_FILES["FileInput"]["size"] > 5242880) { die("File size is too big!"); } //allowed file type Server side check switch(strtolower($_FILES['FileInput']['type'])) { //allowed file types case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg': case 'text/plain': case 'text/html': //html file case 'application/x-zip-compressed': case 'application/pdf': case 'application/msword': case 'application/vnd.ms-excel': case 'video/mp4': case 'audio/mp3'; break; default: die('Unsupported File!'); //output error } $File_Name = strtolower($_FILES['FileInput']['name']); $File_Ext = substr($File_Name, strrpos($File_Name, '.')); //get file extention $Random_Number = uniqid(); //Random number to be added to name. $NewFileName = $Random_Number.$File_Ext; //new file name if(move_uploaded_file($_FILES['FileInput']['tmp_name'], $UploadDirectory.$NewFileName )) { die(' Success! File Uploaded.'); }else{ die('error uploading File!'); } } else { die('Something wrong with upload! Is "upload_max_filesize" set correctly?'); } ?> error: it creates the folder named : $username and not retirieves it from database , if i'm logged in and i upload a file then script need to create a folder with my name : admin ; uploads/admin/file.jpg but it makes ; uploads/$username/file.jpg any help thanks in advance
  6. Hi, I have this form which debits a user when they sell an item. This is based on a credit system. The script should ideally check the user has enough credits before posting the item, if not then it should redirect the user to purchase more credits. But instead it takes the user into a negative amount of credits and still writes the transaction and sale data to the mysql db. However when I run the script whilst the user has a negative amount, it does come up with the message saying the user does not have enough credits and redirects the user to purchase more credits. Ideally, I need to make credits stop at 0 and not allow the script to work if this would leave the user with a negative balance. Here is the form. Also it can be tested at www.e-quatics.com username aquaman password ozzy2004 <?php include 'core/init.php'; protect_page(); include 'includes/overall/header.php'; if (empty($_POST) === false) { $required_fields = array('username', 'email', 'category', 'listing_title', 'brand', 'model', 'colour', 'quantity', 'price', 'comments', 'postage_type', 'postage_cost'); foreach($_POST as $key=>$value) { if (empty($value) && in_array($key, $required_fields) === true) { $errors[] = 'Fields marked with an asterisk are required'; break 1; } } if (empty($errors) === true) { if(user_exists($_POST['username']) === false) { $errors[] = 'Sorry, the username \'' . $_POST['username'] . '\' does not exist. Have you registered?'; } if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'A valid email address is required'; } if(empty($category) === false) { $errors[] = 'Please select a category'; } if(empty($listing_title) === false) { $errors[] = 'Please enter a title for your listing'; } if(empty($brand) === false) { $errors[] = 'Please enter a brand'; } if(empty($model) === false) { $errors[] = 'Please enter a model'; } if(empty($colour) === false) { $errors[] = 'Please enter a colour'; } if(empty($quantity) === false) { $errors[] = 'Please enter a quantity'; } if(empty($price) === false) { $errors[] = 'Please enter a price'; } if(empty($comments) === false) { $errors[] = 'Please enter some information about your item'; } if(empty($postage_type) === false) { $errors[] = 'Please enter a postage options'; } if(empty($postage_cost) === false) { $errors[] = 'Please enter the postage cost for this item.'; } } $query = "SELECT SUM(amount) FROM transactions WHERE user_id = {$_SESSION['user_id']}"; if ($result = mysql_query($query)) { $row = mysql_fetch_row($result); if ($row[0] <= 0) { echo "You either have no remaining credits or not enough to complete this transaction. You will be redirected to purchase more."; header( "Refresh:5; url=purchase.php", true, 303); exit(); } } } if (isset($_GET['success']) && empty($_GET['success'])) { echo '<h2>Thank you for submitting your listing. Your account has been debited.</h2>'; } else { if (empty($_POST) === false && empty($errors) === true) { $sale_data = array( 'user_id' => $user_data['user_id'], 'username' => $_POST['username'], 'email' => $_POST['email'], 'category' => $_POST['category'], 'listing_title' => $_POST['listing_title'], 'brand' => $_POST['brand'], 'model' => $_POST['model'], 'colour' => $_POST['colour'], 'quantity' => $_POST['quantity'], 'price' => $_POST['price'], 'comments' => $_POST['comments'], 'postage_type' => $_POST['postage_type'], 'postage_cost' => $_POST['postage_cost'], 'bold' => $_POST['bold'], 'rotate' => $_POST['rotate'] ); $bold = $_POST['bold']; $rotate = $_POST['rotate']; $total = $bold + $rotate + 1; $amount = -$total; $memo = "Debit for Item"; registerTransaction($user_id, $amount, $memo); register_saleItem($sale_data); header('Location: other_items.php?success'); exit(); } else if (empty($errors) === false) { echo output_errors($errors); } ?> <script type="text/javascript" src="jquery.js"></script> <form action="" id="sellForm" method="POST"> <input type="hidden" name="username" value="<?php echo $user_data['username']; ?>"></li> <input type="hidden" name="email" value="<?php echo $user_data['email']; ?>"></li> <h2>Sell your item</h2> <p><strong>A basic listing will cost 1 credit - extras will be added to the total cost of your listing</strong></p> <ul> <li>Category*:</br> <select name="category"> <option value="none">--choose--</option> <option value="air_pumps">Air Pumps</option> <option value="air_stones">Air Stones</option> <option value="aquariums">Aquariums</option> <option value="cleaning">Cleaning & Maintenance</option> <option value="equipment">CO2 Equipment</option> <option value="coral">Coral & Live Rock</option> <option value="decorations">Decorations</option> <option value="feeders">Feeders</option> <option value="filter_media">Filter Media & Accessories</option> <option value="food">Food</option> <option value="gravel">Gravel & Substrate</option> <option value="health_care">Health Care</option> <option value="heaters">Heaters & Chillers </option> <option value="lighting">Lighting & Hoods</option> <option value="meters">Meters & Controllers</option> <option value="deionization">Reverse Osmosis & Deionization </option> <option value="tubing">Tubing & Valves</option> <option value="uv">UV Steriliser Water Pumps</option> <option value="water_tests">Water Tests & Treatment</option> <option value="other">Other Fish & Aquarium</option> </select> </li> <li>Listing Title*:</br> <input type="text" name="listing_title"> <li><strong>Would you like your listing displayed in Bold?: <input type="checkbox" name="bold" value="1"/> 1 Credit</strong> </li> <li>Brand*:</br> <select name="brand"> <option>Choose...</option> <option value="AI (Aqua Illumination)">AI (Aqua Illumination)</option> <option value="Algarde">Algarde</option> <option value="API">API</option> <option value="AquaEl">AquaEl</option> <option value="AquaGro">AquaGro</option> <option value="Aquamedic">Aquamedic</option> <option value="Aquarian">Aquarian</option> <option value="Aquarium Systems">Aquarium Systems</option> <option value="Aquatlantis">Aquatlantis</option> <option value="Arcadia">Arcadia</option> <option value="Azoo">Azoo</option> <option value="BiOrb/Reef One">BiOrb/Reef One</option> <option value="Blagdon">Blagdon</option> <option value="Boyu">Boyu</option> <option value="Classica">Classica</option> <option value="Cloverleaf">Cloverleaf</option> <option value="Deltec/D-D">Deltec/D-D</option> <option value="Dennerle">Dennerle</option> <option value="Eheim">Eheim</option> <option value="ESHa">ESHa</option> <option value="Hagen/Fluval">Hagen/Fluval</option> <option value="Hikari">Hikari</option> <option value="Hobby">Hobby</option> <option value="Hugo Kamishi">Hugo Kamishi</option> <option value="Interpet">Interpet </option> <option value="JMC">JMC</option> <option value="Juwel">Juwel</option> <option value="King British">King British</option> <option value="New Era">New Era</option> <option value="Nishikoi">Nishikoi</option> <option value="NT Labs">NT Labs</option> <option value="Oase">Oase</option> <option value="Ocean Nutrition">Ocean Nutrition</option> <option value="Penn Plax">Penn Plax</option> <option value="Pontec">Pontec</option> <option value="Red Sea">Red Sea</option> <option value="Rena">Rena</option> <option value="Salifert">Salifert</option> <option value="Seachem">Seachem</option> <option value="Seneye">Seneye</option> <option value="SuperFish">SuperFish</option> <option value="Tanktests">Tanktests</option> <option value="Tetra">Tetra</option> <option value="TMC">TMC</option> <option value="Tunze">Tunze</option> <option value="Two Little Fishies">Two Little Fishies</option> <option value="Waterlife">Waterlife</option> <option value="Wave Point">Wave Point</option> <option value="other">Other</option> </select> </li> <li>Model*:</br> <input type="text" name="model"> </li> <li>Colour*:</br> <select name="colour"> <option value="">--choose one--</option> <option value="White">White</option> <option value="Grey">Grey</option> <option value="Black">Black</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Orange">Orange</option> <option value="Red">Red</option> <option value="Multicoloured">Multicoloured</option> <option value="Other">Other</option> </select> </li> <li>Quantity*:</br> <select name="quantity"> <option value="">--choose one--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="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> </select><strong> 1 Credit entitles you to sell up to 25 of the same item. </strong> </li> <li>Price*:<br> <input type="text" name="price"> In UK Pound Sterling </li> <li>Description*:</br> <textarea name="comments"></textarea> </li> <li>Postage Type*:</br> <select name="postage_type"> <option>Choose...</option> <option>Choose...</option> <option disabled>Economy services</option> <option value="UK_CollectPlusTracked">Collect+ Economy Tracked (3 to 5 working days)</option> <option value="UK_HermesTracked">Hermes Tracked (3 to 5 working days)</option> <option value="UK_RoyalMailSecondClassStandard">Royal Mail 2nd Class (2 to 3 working days)</option> <option value="UK_RoyalMailSecondClassRecorded">Royal Mail 2nd Class Signed For (2 to 3 working days)</option> <option value="UK_RoyalMailTracked">Royal Mail Tracked 48 (2 to 3 working days)</option> <option value="UK_RoyalMail48">Royal Mail 48 (2 to 3 working days)</option> <option value="UK_OtherCourier3Days">Other Courier 3 days (3 working days)</option> <option value="UK_OtherCourier5Days">Other Courier 5 days (5 working days)</option> <option value="UK_OtherCourier">Other Courier (3 to 5 working days)</option> <option value="UK_SellersStandardRate">Other Courier 3-5 days (3 to 5 working days)</option> <option disabled>Standard services</option> <option value="UK_RoyalMailFirstClassStandard">Royal Mail 1st Class (1 working day)</option> <option value="UK_RoyalMailFirstClassRecorded">Royal Mail 1st Class Signed For (1 working day)</option> <option value="UK_RoyalMailNextDay">Royal Mail Tracked 24 (1 working day)</option> <option value="UK_RoyalMail24">Royal Mail 24 (1 working day)</option> <option value="UK_CollectPlusStandard">Collect+ Standard (2 working days)</option> <option value="UK_Parcelforce48">Parcelforce 48 (1 to 2 working days)</option> <option value="UK_OtherCourier48">Other 48 Hour Courier (1 to 2 working days)</option> <option disabled>Express services</option> <option value="UK_RoyalMailSpecialDeliveryNextDay">Royal Mail Special Delivery (TM) 1:00 pm (1 working day)</option> <option value="UK_RoyalMailSpecialDelivery9am">Royal Mail Special Delivery (TM) 9:00 am (1 working day)</option> <option value="UK_Parcelforce24">Parcelforce 24 (1 working day)</option> <option value="UK_OtherCourier24">Other 24 Hour Courier (1 working day)</option> <option disabled>Services from outside UK</option> <option value="UK_EconomyShippingFromOutside">Economy Delivery from outside UK (10 to 22 working days)</option> <option value="StandardDeliveryfromOutsideUKwithRoyalMail">Standard Delivery from outside UK with Royal Mail (7 to 13 working days)</option> <option value="UK_StandardShippingFromOutside">Standard Delivery from outside UK (4 to 10 working days)</option> <option value="UK_ExpeditedShippingFromOutside">Express Delivery from outside UK (1 to 3 working days)</option> <option value="UK_FedExIntlEconomy">FedEx International Economy (3 to 4 working days)</option> <option value="UK_TntIntlExp">TNT International Express (2 to 3 working days)</option> <option value="UK_TrackedDeliveryFromAbroad">Tracked delivery from outside UK (2 to 5 working days)</option> <option disabled>Collection</option> <option value="UK_CollectInPerson">Collection in Person </option> </select> </li> <li>Postage Cost*:</br> <input type="text" name="postage_cost"> </li> </ul> <ul> <li>Upload Photo:</br> <input id="file" type="file" name="uploadPhoto"> </li> <li><input type="checkbox" name="rotate" value="10"/><strong>For 10 credits, you can have your listing displayed on our homepage on a rotation basis. </strong> </li> <li> <input type="submit" value="List Item"></li> </ul> </form> <?php } ?> <?php include 'includes/overall/footer.php'; ?> Many Thanks Paul
  7. Hello PHPer's I am having a few problems with my code. I've probably missed something but could do with an outsiders opinion. Basically, I am writing a bit of code where the user can enter some information and an image into a form and save it to the mysql database. For the most part, the code works, If I don't add the image then the content is all saved. However, when I do add an image I am just given my predefined error message from the code. The php debugger is not much use as the connection is for a local host which is stored on a server and not on my PC.... This is the code: $auth = $_POST['auth']; $tit = $_POST['tit']; $band = $_POST['band']; $alb = $_POST['alname']; $rel = $_POST['release']; $stat = $_POST['stat']; $shrt = $_POST['short']; $art = $_POST['art']; $conn = mysqli_connect("localhost","") or die ("Could not connect to database"); if(!is_uploaded_file($_FILES['file']['tmp_name'])) { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } else { if ($_FILES['file']['type'] != "image/gif" && $_FILES['file']['type'] != "image/jpeg" && $_FILES['file']['type'] != "image/jpg" && $_FILES['file']['type'] != "image/x-png" && $_FILES['file']['type'] != "image/png") { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } else { $finame = $_FILES["file"]["name"]; //$ext = end(explode(".", $finame)); $result = move_uploaded_file($_FILES['file']['tmp_name'], "../includes/$finame"); if ($result == 1) { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status,image) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat''$finame'))"; //echo "$naquery"; } else { $query = "INSERT INTO albumreviews (author,title,band,albumname,releasedate,shortdesc,article,albumdate,status) VALUES ('$auth','$tit','$band','$alb','$rel','$shrt','$art',CURDATE(),'$stat')"; //echo "$naquery"; } } } $result = mysqli_query($conn, $query); if($result){ echo "successful"; echo "<BR>"; echo "<a href='http://'>Back to Content Management </a>"; } else { echo "error could not upload article"; echo "<BR>"; echo "<a href='http://'>Back to Content Management </a>"; } mysqli_close($conn); ?> Any help on getting this to upload the image files would be much appreciated. Thanks
  8. <?php include("../../connect.php"); $burger=$row['event_name']; $query=mysql_query("CREATE TABLE $burger (id int(10) AUTO_INCREMENT,event_id char(50), name char(100))")or die (mysql_error()); ?> error : Incorrect table definition; there can be only one auto column and it must be defined as a key
  9. Hey Guys, So i have a while loop bringing back some information for me from my database. pretty basic: $query = 'SELECT * from `db` WHERE `id` = '. $id; $run = mysql_query($query); while($rows = mysql_fetch_assoc($run)){ extract($rows); } Now in this loop i am trying to add a link using an anchor tag: echo '<a href="'.$domain . '">'.$domain.'</a><br>'; ( I WILL USE EXAMPLE LINK DONT CLICK BELOW FOR DEMO PURPOSES) which basically makes something like : http://ExampleLinkDontClick.com Now my issue is that for the life of me i cant understand why my link is being given and shown correctly, but the link is firing as so as you can see the anchor tag is looking for a page that i created or is on file in the directory, instead of going to the designated source of the url. any suggestions ? am i just missing something very basic ? usually this works flawlessly but maybe today is just one of those days .. lol thanks guys -justin7410
  10. Hi guys! I have a slight problem. When I pass values as variables to a sql statement it doesnt work. This is the example: THIS WORKS: <?php require 'DB/dbinc.php'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // changes data in "text" and "text" where title = some title $sql = "UPDATE bloging SET title='Novi Title', tekst='Novi tekst' WHERE title='Update post'"; $count = $conn->exec($sql); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; ?> THIS DOES NOT WORK <?php require 'DB/dbinc.php'; $oldTitle = 'Stari naslov'; $nTitle = 'novinaslov'; $nText = 'novitekst'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // changes data in "text" and "text" where title = some title $sql = "UPDATE bloging SET title=$nTitle, tekst=$nText WHERE title=$oldTitle"; $count = $conn->exec($sql); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; ?> I don't get it why it wont accept variable instead of string text as a value? Thanx in advance!
  11. I'm currently working on a WordPress website project and I am hoping someone can help me out on this. In the registration page, the data entered is stored into the WordPress database. I've also build a connection to store those data into an external database as well. So basically, If a visitor registers on the site, their data info is stored in the WP and external DB. My question is since the external DB relies on checking to see if the submit button has been pressed, do those data input values need to be escaped to prevent sql injection into the external DB since the data submitted to WordPress has already been sql escaped? Thanks for helping.
  12. Hi. Sorry if I've posted in the wrong forum or something - I joined this forum a few seconds ago. I'm trying to create something which displays all of the users in a database table in a drop-down menu. I've tried this code: <?php include 'config.php'; session_start(); $suser = $_SESSION['user']; $con = mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_pass']); mysql_select_db($config['database']); $cpuTable = $config['cpuTable']; $query = mysql_query("SELECT * FROM $cpuTable WHERE suser='$suser'"); while($row = mysql_fetch_assoc($qa)) { $users = $row['username']; echo " <select name='cpuser'> <option value='user'>$users</option> </select>"; } I created two users in the database - "cp_test1" and "cp_test2", tried the code and it outputted this: Instead of listing the users in one drop-down menu, it creates two and lists one in each. Can anyone help? Thanks
  13. the above image is already on the database and i want to display it just like the image below .... can any one give me a little idea on how to get this .... thank you so much ... from PHILIPPINES .. SALAMAT!
  14. Hello Guys, I have a database that is set up something like this: Name Type_a Type_b 3 series Car BMW 1 series Car BMW A class Car Merc C class Car Merc 500 Motorbike XYZ 600 Motorbike XYZ I want to pull this info out of my database and display it like this: Cars: BMW: 1 Series 3 Series Merc A Class Merc C Class Motorbikes: XYZ: 500 600 So far I have this: $result = mysql_query("SELECT * FROM Cars")or die(mysql_error()); while ($row = mysql_fetch_array($result)) { // we get all of the items in this project and put them into a 3 part Array.... $assets= array('Name' => $row['Name], type_a' => $row['Type_A'], 'Type_B' => $row['Type_B']); } print_r($assets); Now this works fine, I end up with a 3 part array containing all of the information I need. The part I am struggling with, is how to get the information back out of the array in a way I can deal with, to produce the above example. Any help? Thanks guys!
  15. Hello Guys/Gurus Please I have an issue, am some months into php and i need your help/assistance. This is the flow. a client register at another site, when we confirm the registration, we send them a code. The code is generated and saved in another table name called code. I develop a form (http://cash2money2020.com/form.html) So all i want is if someone inputs the generated code we sent to them, and filled it in the form, it makes a database checks to see if the code exists in the other table, if yes, submit form..if not, error message that the code is invalid and the form will not be submitted: This is the code i have so far which saves the data into the database: $why = $sql->real_escape_string($_POST['why']); $interesting = $sql->real_escape_string($_POST['interesting']); $impressive = $sql->real_escape_string($_POST['impressive']); $code = $sql->real_escape_string($_POST['code']); $query = " INSERT INTO registration (id, why, interesting, impressive, generated_code, submitted_date) VALUES ('', '$why', '$interesting', '$impressive', '$code', now()) "; $sql->query($query) or die($query.' '.$sql->error); if($_SERVER['REQUEST_METHOD'] == 'POST') This is where am stucked and i dont know what to do next. Also, this is the code the generates and saves data into the database: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $sqli = @mysqli_connect ( 'localhost', 'root', 'wisdom', 'cash2money' ) OR die ( mysqli_connect_error() ) ; mysqli_set_charset( $sqli, 'utf8' ) ; //Checking if the user has already validated the form we show the string if(isset($_POST["submit"])) { $length = 10; $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX‌​YZ"), 0, $length); echo "$randomString"; } else //If he hadn't show the form { ?> <form method="post" action=""> <input type="submit" name="submit" value="Generate Code" /> <input type="hidden" name="code" value="" /> </form> <?php } $code = $sqli->real_escape_string($_POST['submit']); $query = "INSERT INTO code (id, generated) VALUES ('','$randomString')"; $sqli->query($query) or die($query.' '.$sql->error); //From here, there is error... but the above code saves the generated code into the database. $result = mysqli_query("SELECT generated FROM code ", $sqli); //guess a COUNT statement should work $row = mysqli_fetch_array($result); $table1 = $result("generated_code `registration`", $sqli); $table2 = $result("generated `code`", $sqli ); if( json_encode($table1) == json_encode($table2) ){ echo "Code does not match"; }else{ echo "It matched"; } ?> </body> </html> Please who will help me out with the comparison of values between two tables
  16. Ok, so in a database table i have: name contact code type price quantity Name 1 xxxxxxxxx GHT3 Food £10.50 2 Name 1 xxxxxxxxx GHTd Food £10.30 2 Name 1 xxxxxxxxx GHTs Food £10.90 2 Name 2 xxxxxxxxx GHT3 Food £10.50 2 Name 3 xxxxxxxxx GHTs Food £10.50 2 Name 3 xxxxxxxxx GHTd Food £10.50 2 I want them to read on another page like this: Name Contact Code Type Quantity Name 1 xxxxxxxxxx GHT3 Food 2 GHTd Food 2 GHTs Food 2 Total Price: £xx.xx Name 2 xxxxxxxxxx GHT3 Food 2 Total Price: £xx.xx Name 3 xxxxxxxxxx GHTs Food 2 GHTd Food 2 Total Price: £xx.xx So it only reads the name and number once but puts in the whole of what they are after. Hope someone understands this and can lend some help. Don't need the table doing just need to know the sql i would need to use.
  17. Hi. I have made a application form for a job, I want the results the user enters into the boxes to come out into my database (evxhotel and the table apps). I get no errors and the website works perfectly fine but when I fill the form and submit the page just reloads and when I go to check my database I see that my results of the form are not in the database. I believe that maybe I put the mysql_connect and the mysql_select_db on the wrong lines. BTW, this is only the php script embedded into a html document. The file format and name is form.php. All the tags are correct. <?php $connect = mysql_connect("****", "****", "****") or die(mysql_error()); if(isset($_POST['submit'])){ $username = mysql_real_escape_string($_POST['Username']); $email = mysql_real_escape_string($_POST['Email']); $firstname = mysql_real_escape_string($_POST['First']); $lastname = mysql_real_escape_string($_POST['Last']); $day = mysql_real_escape_string($_POST['Day']); $month = mysql_real_escape_string($_POST['Month']); $year = mysql_real_escape_string($_POST['Year']); $time = mysql_real_escape_string($_POST['Time']); $position = mysql_real_escape_string($_POST['Position']); $why = mysql_real_escape_string($_POST['Why']); $what = mysql_real_escape_string($_POST['What']); $exp = mysql_real_escape_string($_POST['Exp']); $hours = mysql_real_escape_string($_POST['Hours']); $comments = mysql_real_escape_string($_POST['Comments']); mysql_select_db($connect, "evxhotel") or die(mysql_error()); $sql = mysql_query ("INSERT INTO apps (username, email, realname, dob, time, position, why, what, exp, hours, comments) VALUES ('".$username."', '".$email."', '".$firstname/$lastname."', '".$day/$month/$year."', '".$time."', '".$position."', '".$why."', '".$what."', '".$exp."', '".$hours.", '".$comments."')", $connect); if($sql) { echo "Your applicaton has been added to the database."; } else { die(mysql_error()); } } ?> Whats wrong? Thanks in advance.
  18. Hello. In my business logic, I have a user, a company (users can be part of the company) and products. A product can be owned by a user or by a company, the company can assign it to a user later, but it would still be owned by the company (in case the company fires the user). My thought is to have the user table, the company table and the product table. I'm thinking about having a product_owner table, where I would have product_id, user_id, company_id, agent_assigned. If the product is owned by a user then only product_id and user_id will be filled. If it's owned by a company, then product_id, company_id and agent_assigned would be filled. Is this the best way to do it? It doesn't seem good to me.
  19. Hello everyone, I am trying to create a database login but i am not having any luck. I am not sure what is wrong. I feel everything is in order but I am new and don't really know what to look for. If someone could help me get this up and running, i'd greatly appreciate it. I've spent over 20 hours. I know it isn't exteremely diffuclt but I am fustrated and about to give up . Some help would me great! 1st page: Login.html ( I left out the formatting, heres just the form) file:///C:/Users/Stahlsta/Desktop/PHP/Login.html <form name="form 1" method="post" action="KitchenDatabase.php"> <Center><table width="20%" border="0" cellspacing="0" bgcolor="blue" frame="box" > <tr> <td><h3>Username:</h3></td> <td><input name="username" type="text" id="username" ></td></tr> <tr> <td><h3>Password:</h3></td> <td><input name="password" type="text" id="password" ></td></tr> <tr> <td colspan="2" align="center"> <input type="submit" name="Submit" value="Login"/> <input type="submit" value="Guest Log in"/></td></tr> </table> </Center> </form> When I click login: I want to access KitchenDatabase.php 2nd page:KitchenDatabase.php - This page should link to loginsuccess.php <?php $host="localhost:3306"; // Host name $Owner_fName="username"; // Mysql username $Owner_password="password"; // Mysql password $db_name="2013-wstahl"; // Database name $tbl_name="Owner"; // Table name // Connect to server and select databse. mysql_connect("$host", "$Owner_fName", "$Owner_password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $Owner_fName=$_POST['username']; $Owner_password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $Owner_fName = stripslashes($Owner_fName); $Owner_password = stripslashes($Owner_password); $Owner_fName = mysql_real_escape_string($Owner_fName); $Owner_password = mysql_real_escape_string($Owner_password); $sql="SELECT * FROM $tbl_name WHERE username='$Owner_fName' and password='$Owner_password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $Owner_fName, $Owner_password and redirect to file "loginsuccess.php" session_register("username"); session_register("password"); header("location:loginsuccess.php"); } else { echo "Wrong Username or Password"; } ?> Page 3:loginsuccess.php - This page should link to KitchenDatabase.html <?php session_start(); if(!session_is_registered(username)){ header("KitchenDatabase.html"); } ?> Page 4:I wont bore you witht he code, i dont think it's important for the login work. (file:///C:/Users/Stahlsta/Desktop/PHP/KitchenDatabase.html) Everything is based off this database. KitchenDatabase.sql # # DUMP FILE # # Database is ported from MS Access #------------------------------------------------------------------ # Created using "MS Access to MySQL" form http://www.bullzip.com # Program Version 5.1.242 # # OPTIONS: # sourcefilename=C:\Users\wstahl\Desktop\KBdatabase1.accdb # sourceusername= # sourcepassword= # sourcesystemdatabase= # destinationdatabase=2013-wstahl # storageengine=MyISAM # dropdatabase=0 # createtables=1 # unicode=1 # autocommit=1 # transferdefaultvalues=1 # transferindexes=1 # transferautonumbers=1 # transferrecords=1 # columnlist=0 # tableprefix= # negativeboolean=0 # ignorelargeblobs=0 # memotype=LONGTEXT # CREATE DATABASE IF NOT EXISTS `2013-wstahl`; USE `2013-wstahl`; # # Table structure for table 'Fridge' # DROP TABLE IF EXISTS `Fridge`; CREATE TABLE `Fridge` ( `Fridge_ID` INTEGER NOT NULL, `Owner_ID` INTEGER NOT NULL, `Room_Loc` VARCHAR(255), INDEX (`Owner_ID`), PRIMARY KEY (`Fridge_ID`), FOREIGN KEY (`Owner_ID`) REFERENCES `Owner` ) ENGINE=myisam DEFAULT CHARSET=utf8; SET autocommit=1; # # Dumping data for table 'Fridge' # INSERT INTO `Fridge` VALUES (100, 100, 'Kitchen'); INSERT INTO `Fridge` VALUES (101, 101, 'Wills'); INSERT INTO `Fridge` VALUES (102, 102, 'Taylors'); INSERT INTO `Fridge` VALUES (103, 103, 'Matts'); INSERT INTO `Fridge` VALUES (104, 104, 'Felixs'); INSERT INTO `Fridge` VALUES (105, 105, 'Anthonys'); INSERT INTO `Fridge` VALUES (106, 106, 'Sams'); # 7 records # # Table structure for table 'Guest' # DROP TABLE IF EXISTS `Guest`; CREATE TABLE `Guest` ( `Guest_ID` INTEGER NOT NULL AUTO_INCREMENT, `Guest_fName` VARCHAR(50), `Guest_lName` VARCHAR(50), `Over21` TINYINT(1) DEFAULT 0, `Owner_ID` INTEGER NOT NULL, INDEX (`Over21`), PRIMARY KEY (`Guest_ID`), FOREIGN KEY (`Owner_ID`) REFERENCES `Owner` ) ENGINE=myisam DEFAULT CHARSET=utf8; SET autocommit=1; # # Dumping data for table 'Guest' # INSERT INTO `Guest` VALUES (1, 'Harry', 'Potter', 1, 101); INSERT INTO `Guest` VALUES (2, 'Jamie', 'Kurtis', 1, 102); INSERT INTO `Guest` VALUES (3, 'Bucky', 'Smith', 0, 103); INSERT INTO `Guest` VALUES (4, 'Nick', 'Crawl', 1, 101); INSERT INTO `Guest` VALUES (5, 'Matt', 'Taylor', 0, 104); INSERT INTO `Guest` VALUES (6, 'Martha', 'Stewart', 1,105); INSERT INTO `Guest` VALUES (7, 'Kris', 'Durdon', 0, 105); INSERT INTO `Guest` VALUES (8, 'Mike', 'Micheals', 1, 102); # 8 records # # Table structure for table 'Item' # DROP TABLE IF EXISTS `Item`; CREATE TABLE `Item` ( `Item_ID` INTEGER NOT NULL AUTO_INCREMENT, `Item_Name` VARCHAR(255), `Item_Cost` DECIMAL(19,4), `Exp_Date` DATETIME, `Item_Qty` INTEGER, `Owner_ID` INTEGER, `Fridge_ID` INTEGER, `Store_ID` INTEGER, PRIMARY KEY (`Item_ID`), FOREIGN KEY (`Owner_ID`) REFERENCES `Owner`, FOREIGN KEY (`Fridge_ID`) REFERENCES `Fridge`, FOREIGN KEY (`Store_ID`) REFERENCES `Store`, INDEX (`Fridge_ID`), INDEX (`Owner_ID`), INDEX (`Store_ID`) ) ENGINE=myisam DEFAULT CHARSET=utf8; SET autocommit=1; # # Dumping data for table 'Item' # INSERT INTO `Item` VALUES (1, 'eggs', 2.09, '2013-11-11 00:00:00', 2, 100, 100, 200); INSERT INTO `Item` VALUES (2, 'milk', 3.49, '2013-11-07 00:00:00', 2, 100, 100, 201); INSERT INTO `Item` VALUES (3, 'Bread', 3.09, '2013-11-08 00:00:00', 1, 101, 101, 201); INSERT INTO `Item` VALUES (4, 'cheese', 4.01, '2013-12-30 00:00:00', 2, 101, 100, 200); INSERT INTO `Item` VALUES (5, 'hot dogs', .97, '2014-01-16 00:00:00', 3, 102, 102, 200); INSERT INTO `Item` VALUES (6, 'rolls', 3.09, '2013-11-25 00:00:00', 6, 102, 102, 200); INSERT INTO `Item` VALUES (7, 'noodles', .99, NULL, 4, 103, 103, 202); INSERT INTO `Item` VALUES (8, 'sauce', 4.09, '2013-11-20 00:00:00', 2, 103, 103, 202); INSERT INTO `Item` VALUES (9, 'rice', .98, NULL, 12, 104, 104, 200); INSERT INTO `Item` VALUES (10, 'beans', 1.49, '2013-12-18 00:00:00', 2, 104, 100, 202); INSERT INTO `Item` VALUES (11, 'hamburgers', 6.99, '2013-12-25 00:00:00', 8, 105, 100, 200); INSERT INTO `Item` VALUES (12, 'buns', 3.09, '2013-12-19 00:00:00', 8, 105, 105, 200); INSERT INTO `Item` VALUES (13, 'onions', .99, NULL, 3, 106, 106, 202); INSERT INTO `Item` VALUES (14, 'soup', 1.99, '2014-04-16 00:00:00', 5, 106, 106, 200); INSERT INTO `Item` VALUES (15, 'icream', 3.09, NULL, NULL, NULL, 101, NULL); INSERT INTO `Item` VALUES (16, 'Bacon', 5.15, '2013-10-16 00:00:00', 1, 101, 101, 202); INSERT INTO `Item` VALUES (17, 'Hot sauce', 2.79, '2013-11-22 00:00:00', 3, 101, 101, 200); INSERT INTO `Item` VALUES (18, 'ketchup', 3.5, NULL, 1, 101, 101, 201); INSERT INTO `Item` VALUES (19, 'crunch cereal', 3.49, '2014-01-22 00:00:00', 2, 101, 101, 201); # 19 records # # Table structure for table 'Owner' # DROP TABLE IF EXISTS `Owner`; CREATE TABLE `Owner` ( `Owner_ID` INTEGER NOT NULL, `Owner_fName` VARCHAR(255) NOT NULL, `Owner_lname` VARCHAR(255), `Owner_password` VARCHAR(50), PRIMARY KEY (`Owner_ID`) ) ENGINE=myisam DEFAULT CHARSET=utf8; SET autocommit=1; # # Dumping data for table 'Owner' # INSERT INTO `Owner` VALUES (100, 'All', 'NULL', 'NULL'); INSERT INTO `Owner` VALUES (101, 'Will', 'Stahl', password); INSERT INTO `Owner` VALUES (102, 'Taylor', 'Ryzuk', NULL); INSERT INTO `Owner` VALUES (103, 'Matt', 'Sheehan', NULL); INSERT INTO `Owner` VALUES (104, 'Felix', 'Burgos', NULL); INSERT INTO `Owner` VALUES (105, 'Anthony', 'Lombardi', NULL); INSERT INTO `Owner` VALUES (106, 'Sam', 'Gutzmer', NULL); # 7 records # # Table structure for table 'Store' # DROP TABLE IF EXISTS `Store`; CREATE TABLE `Store` ( `Store_ID` INTEGER NOT NULL, `Store_Name` VARCHAR(255) NOT NULL, `Store_City` VARCHAR(255), PRIMARY KEY (`Store_ID`) ) ENGINE=myisam DEFAULT CHARSET=utf8; SET autocommit=1; # # Dumping data for table 'Store' # INSERT INTO `Store` VALUES (200, 'Walmart', 'Oswego'); INSERT INTO `Store` VALUES (201, 'Bryne', 'Oswego'); INSERT INTO `Store` VALUES (202, 'Kinneys', 'Oswego'); INSERT INTO `Store` VALUES (203, 'Price Chopper', 'Oswego'); # 4 records Am I even close? I've come to far to quit. Please help me get this working Kudos, Fridge.html Fridge.php KitchenDatabase.html KitchenDatabase.php Login.html loginsuccess.php
  20. Hi, I have a set of radio buttons with some integer as its value. I use them to make seat selections in an application. If a Radio button is once selected its value will be entered to the DataBase. My question, can I mask or make invisible, the radio button whose value is found in database? isa that possible? Any help will be appreciable. Thanks in advance.. Regards...
  21. Hi, I am having a bit of a problem with a simple task and I was wondering if someone would be able to help. I have a php system which allows members to sign up, stores their information in a mysql database, then they can sign in and do all sorts of things. The area I have a problem with is I'm trying to make an update page so that they can edit their details stored in the mysql database. My code is as follows. <?php session_start(); include_once "base.php"; //connects to database $username = mysql_real_escape_string($_SESSION['Username']); // get users username from session $forename = mysqL_real_escape_string($_SESSION['Forename']; //gets already stored forename $newforename = mysql_real_escape_string($_POST['newforename']);//post for new forename $registerquery = mysql_query("INSERT INTO users WHERE Username = '".$username."'(Forename) VALUES('".$newforename."')"); //finds row for the user and updates the forename column with new record ?> <form method="post" action="index.php" name="registerform" id="registerform"> <fieldset> <label for="newforename">Forename:</label><input type="text" name="newforename" id="newforename" /><br /> <input type="submit" name="register" id="register" value="Register" /> </fieldset> </form> Unfortunately this code does not update the database at all, however it does not crash or produce any errors! I would really appreciate any help you can give with this.
  22. I'm trying to view the posts stored in the database but for some weird reason I am only seeing the messahe thats says the post cannot be accessed. Can someone look at the code below and see if you can point out where i have gone wrong please. <?php include 'connect.php'; include 'header.php'; echo "<div class='inside'>"; echo '<h3>Category View</h3><br />'; //retrieve the category from the database based on $_GET['cat_id'] $sql = "SELECT cat_name, cat_description FROM category WHERE cat_id = " . $_GET['id']; $result = mysql_query($sql) or die("<p>Could not execute query. Sorry for the inconvenience, please try again later.</p>"); if($result) { if(mysql_num_rows($result) == 0) { echo '<p>There are no topics in this category yet.</p>'; } else { $row = mysql_fetch_assoc($result); echo '<table width="100%" class="category"> <tbody> <tr> <th colspan="2" class="tableheader">' . $row['cat_name'] . '</th> </tr> <tr> <th class="leftpanel">Topic</th> <th class="rightpanel" align="center">Last Post</th> </tr>'; $sql = "SELECT topic_id, topic_subject, topic_date, topic_cat FROM topic WHERE topic_cat = " . mysql_real_escape_string($_GET['id']) ." ORDER BY topic_date DESC"; $result = mysql_query($sql,$connect) or die('The topics could not be displayed, please try again later.<br /><br />'); if(mysql_num_rows($result) == 0) { echo 'There are no topics in this category yet.'; } else { //prepare the table while($row = mysql_fetch_assoc($result)) { $sql = "SELECT post_id, post_date, post_by FROM post WHERE post_topic = " . $row['topic_id'] ." ORDER BY post_date DESC LIMIT 1"; $result2 = mysql_query($sql,$connect) or die('The post could not be accessed, please try again later.<br /><br />'); $row2 = mysql_fetch_assoc($result2); echo '<tr>'; echo '<td class="leftpart">' .'<h4><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br /><h4>' .'</td>' .'<td class="rightpart">' .'<span class="byline"><span class="created">' .istoday($row2['post_date']) .'</span><br/><span class="floatright">by ' . $row2['post_by'] .'</span></span></td>'; echo '</tr>'; } } echo '</tbody> </table>'; } } echo "</div>"; include 'footer.php'; ?>
  23. Hi The following php code is to update values and pass it to the database . The problem is it's not updating the $lastlogin value and I can't see anything wrong with it, can anybody tell me what I'm doing wrong. Any help would be appreciated. public function login($postArray) { $jsonArr = array("status" => "unknown"); $username = $postArray['username']; $pass = sha1($postArray['password']); $ip = $_SERVER['REMOTE_ADDR']; $date = gmdate("Y-m-d H:i:s"); //login time $rowsNum = self::$dbConnection->rows_num("SELECT * FROM `users` WHERE `username`='$username' AND `password`='$pass'"); //successfully logged in if($rowsNum == 1) { //update the record self::$dbConnection->exec_query("UPDATE `users` SET `cur_ip`='$ip', `last_login`='$date' WHERE `username`='$username', `password`='$pass'"); //pull the information from the database $f = self::$dbConnection->query("SELECT * FROM `users` WHERE `username`='$username' AND `password`='$pass'"); $userid = $f['id']; $lastlogin = $f['last_login']; //set the login session $dataArray = array("userid" => $userid, "username" => $username, "lastlogin" => $lastlogin); //set status $jsonArr['status'] = "login_success"; $jsonArr['userdata'] = $dataArray; } else { //set status $jsonArr['status'] = "login_fail"; } return $jsonArr; }
  24. Hello, I was making a login page with PHP and Mysql and have managed to debug all the errors, but the page says 'Wrong Username or Password' even though i have typed in the right password from the table. I was wondering if anyone could help me. Thanks I have 4 php files: main_login.php check_login.php login_success.php logout.php Here is all the code: main_login.php: <table> <tr> <form name="form1" method="post" action="check_login.php"> <td> <table> <tr> <td><strong>Login form: </strong></td> </tr> <tr> <td>UserName</td> <td>:</td> <td><input name="myusername" type="text" id="myusername"/></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="mypassword" type="text" id="mypassword"/> </td> </tr> <tr> <td> </td> <td> </td> <td><input type="Submit" name="Submit" value="Login"/></td> </tr> </table> </td> </form> </tr> </table> <?php ?> check_login.php: <?php $host = "localhost"; $Username = "christopher"; $Password = "password"; $db_name = "test_db"; $tbl_name = "test"; //CONNECT TO SERVER mysql_connect("$host", "$Username", "$Password") or die("CANNOT CONNECT"); mysql_select_db("$db_name") or die("CANNOT SELECT DB"); //USERNAME AND PASSWORD FROM FORM $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; //SECURITY PROTECTION $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); $count = mysql_num_rows($result); $count = 1; if($count == 1){ session_register("myusername"); session_register("mypassword"); header("Location: http://localhost/login/2/login_success.php/"); } else { echo "Wrong Username Or Password"; } ?> login_success.php <?php session_start(); echo "login successful.."; if(!session_is_registered(myusername)){ header("location:main_login.php"); } ?> <html> <body> LOGIN SUCCESSFUL </body> </html> logout.php: <?php session_start(); session_destroy(); ?> check_login.php login_success.php logout.php main_login.php
  25. I keep getting this error how can I fix this?? Warning: Invalid argument supplied for foreach() in /hermes/waloraweb071/b2172/moo.mangowebdesignsnet/shopping/includes/functions.inc.php on line 1082 MySQL Error OccurredError Message: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 SQL: SELECT I.productId, I.image, I.price, I.name, I.sale_price FROM mangostoreCubeCart_inventory AS I, mangostoreCubeCart_category AS C WHERE C.cat_id = I.cat_id AND I.disabled != '1' AND I.showFeatured = '1' AND I.cat_id > 0 AND C.hide != '1' ORDER BY I.productId DESC LIMIT If anyone can help me with this I would be deeply grateful. If you need anything or more details please respond to this topic please. I need this fixed ASAP. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.