PHP - Integrating Datas To One Database Using Php Script
Hello everybody, I have found a lot of amazing advises and codes to improve on my existing codes. It seems to be an awesome site. I actually came from a background of Application programming, however I have just recently pick up a project in php. The project is about database integration, where I have to integrate 5 supplier's existing data who have different attributes into one. (each suppliers have about 30k data) I really need help and advises on how should I do the script.
Here's the details, All the suppliers uses different data file, such as CSV and .xls. I am finding a way to integrate all the 5 files into one database(mysql/phpmyadmin) so it could be listed out in a shopping cart or catalog in future. However, I am unfamiliar with php, so please advice on how can i go about fixing this problem. The first problem is that each individual suppliers uses a different attributes name, for example Supplier 1 uses : SupplierName, SupplierID, SupplierAddress, Status Inside the status, the supplier uses data such as, Good, Excellent, Great while Supplier 2 uses : SName, SID, SAddress, Status and inside this supplier, the status data that are being uses is G, Ex, Gr. How can I set a consistancy on the data and converting all the properties into one so I can import this data into a proper database such as mysql/phpmyadmin. Please help, thanks in advance Similar Tutorialsi am a newbie.. From my tables, what code should i put to put into my site? in text.. Dear All, I have login script already. i have two database one is users and another one is reference in both user_name is common. In this if a user login and search the refid means that user datas onle possible to retrieve. for others datas they cant access. i wrote the below code but it display all user datas. kindly help me <?php session_start(); if (!$_SESSION["user_name"]) { // User not logged in, redirect to login page Header("Location: login.php"); / } // Member only content // ... $con = mysql_connect('localhost','root',''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $user_name = $_POST['user_name']; $query = "select * from reference,users where reference.user_name=users.user_name and reference.refid='$refid'"; $result = mysql_query($query) or trigger_error('MySQL encountered a problem<br />Error: ' . mysql_error() . '<br />Query: ' . $query); while($row = mysql_fetch_array($result)) { echo $row['refid']; echo $row['origin']; echo $row['dest']; echo $row['date']; echo $row['exdate']; echo $row['user_name']; } echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> <html> <form method="post" action="final.php"> Ref Id:<input type="text" name="refid"> <input type="submit" value="submit" name="submit"> </html> guys please help, i have an array(52,51,52) here i want to insert first & last elements into DB, not second one does not follows the series another array (52,52,53) in this case insert first 2 elements into DB since last element does not follow the series. how is this possible? I'm very beginner with arrays.... i KNOW, databases exist, it's more easy.. I can't use a database.. I have to use, this.. or similar.. that doesn't requiring a database engine... So... that array...
array ( ); I search by the element [#][0].. in the +250 some will contain the same infos and I would like to make them point to the element containing the info instead of repeating it and have to update at 3-4 places when it's time. Like what it's in "10" also good for "ten", "dix" and "diez"... anyway to make that simple? by reference or...??? I'm crying.. last time I used arrays... Turbo Pascal.. at school... or was it Turbo C++ 3.0?? Maybe it was with cobol... well it was the good ol' time of the 90s!
Thanks!
-TRP-
guys, please help i have table with datas like speed of vehicle, position e.t.c from morning 8 a.m. to 8 p.m. I need to get these details, but after every 15 minutes i.e. after selecting datas at 8 a.m. it shd select datas @ 8.15 a.m. then 8.30 a.m. hw can i write a mysql query for this ? or a PHP approach is appreciated I hav a php page which takes data from the db.But the problem i am facing is for a particular fild in database ,i have long data,which i need to b displayed in a wordwrap way eg my data is " Description need a site for school gave order on 12-10-2010 work started on 12-10-2010 " this shuld be displayed as "Description need a site for school gave order on 12-10-2010 work started on 12-10-2010" Description is the field in the database and rest of them are the datas in it Hi, I am planning to integrate Facebook login into my site, I found this useful guide: Code: [Select] http://www.1stwebdesigner.com/tutorials/facebook-integrate/ Has anyone tried it before, if so how difficult would you say it is to do this? My site is operated by matching id numbers with username. How would I get a username from a Facebook login? Hi, hope I have posted this in the right place, I have the following code which contains PHP and javascript, where both work on there own but when I try putting them together I keep getting errors: Code: [Select] <?php include 'config.php'; include 'opendb.php'; $var = 'Smith'; $query = "SELECT * FROM search_directory WHERE merchant LIKE \"%$var%\""; $result = mysql_query($query); $id = $row{"id"}; while($row = mysql_fetch_assoc($result)) { echo "Name: {$row['name']} <br>"; echo "Subject: {$row['title']} <br><br>"; } include 'closedb.php'; ?> <a href="javascript:;" onclick="document.getElementById('.....').style.display='block';window.open('http://www.google.co.uk');"><img src="../../graphics/Click here.png" border="0" /></a> <div id="....." style="display:none;"> ...your text here </div> What I have been trying to do is get $id variable from the php code to replace the '.....' in the javascript and div id. I have tried putting it into an echo statement which seemed to work with the div id but the brought up errors when i tried with the javascript. If anyone knows how to solve this it would be very much appreciated. Thanks in advance. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=358814.0 I am taking a form that has been created and now trying to incorporate it into WP. The form is filled out multiple times per session. The form when filled out will generate an ID that is used to track the form submissions until completed. The problem that I'm running into is that the code is using a URL structure that breaks on the install.
I'm not sure what to tell the code to look for as the URL.
I hope I'm making sense. This is my first dive into WP dev. Thanks for the help.
<?php /* Template Name: Form */ ?> <?php /** * The template for displaying all pages * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages and that * other 'pages' on your WordPress site will use a different template. * * @package WordPress * @subpackage Twenty_Thirteen * @since Twenty Thirteen 1.0 */ get_header(); ?> <div id="main-content" class="main-content"> <div id="headertitle"> <h1>Steam Trap Form Input</h1> </div> <div id="formtable"> <form class="form-horizontal" role="form" action="/test/FormHandler.php" method="post"> <fieldset> <div class="form-group"> <label for="dateSurvey" class="col-sm-2 control-label">Survey Date</label> <div class="col-sm-6"> <input type="text"<? echo (isset($sd['date']) ? ' value="'.format_date($sd['date']).'"' : '') ?> class="form-control col-sm-6 input-append date" id="dp1" name="dateSurvey" data-date="02-12-2014" data-date-format="mm-dd-yyyy"> </div> </div> <div class="form-group"> <label for="plantName" class="col-sm-2 control-label">Plant Name</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="plantName"<? echo (isset($sd['plant_name']) ? ' value="'.$sd['plant_name'].'"' : '') ?>> </div> </div> <div class="form-group"> <label for="plantLoc" class="col-sm-2 control-label">Plant Location</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="plantLoc"<? echo (isset($sd['plant_location']) ? ' value="'.$sd['plant_location'].'"' : '') ?>> </div> </div> <div class="form-group"> <label for="plantContact" class="col-sm-2 control-label">Plant Contact Name</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="plantContact"<? echo (isset($sd['plant_contact_name']) ? ' value="'.$sd['plant_contact_name'].'"' : '') ?>> </div> </div> <div class="form-group"> <label for="pph" class="col-sm-2 control-label">Pound Per Hour</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="pph" placeholder="XX.XX"<? echo (isset($sd['pph']) ? ' value="'.$sd['pph'].'"' : '') ?>> </div> </div> <div class="form-group"> <label for="area" class="col-sm-2 control-label">Area</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="area" placeholder="Boiler Room"<? echo (isset($sd['area']) ? ' value="'.$sd['area'].'"' : '') ?>> </div> </div> <hr> <div class="form-group"> <label for="testDate" class="col-sm-2 control-label">Tested Date</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6 input-append date" id="dp2" name="testDate" data-date="02-12-2014" data-date-format="mm-dd-yyyy"> </div> </div> <!-- <div class="form-group"> <label for="direction" class="col-sm-2 control-label">Direction</label> <div class="col-sm-6"> <select class="form-control col-sm-6" name="direction"> <option value="N">N</option> <option value="NE">NE</option> <option value="NW">NW</option> <option value="S">S</option> <option value="SE">SE</option> <option value="SW">SW</option> <option value="E">E</option> <option value="W">W</option> </select> </div> </div> --> <div class="form-group"> <label for="location" class="col-sm-2 control-label">Location</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="location" placeholder=" 'Detailed as possible'"> </div> </div> <div class="form-group"> <label for="flrLevel" class="col-sm-2 control-label">Floor Level</label> <div class="col-sm-6"> <select class="form-control col-sm-6" name="flrLevel"> <option value="GROUND">Ground</option> <option value="1st">1st</option> <option value="2nd">2nd</option> <option value="3rd">3rd</option> <option value="4th">4th</option> <option value="5th">5th</option> <option value="6th">6th</option> <option value="7th">7th</option> <option value="8th">8th</option> <option value="9th">9th</option> <option value="10th">10th</option> <option value="11th">11th</option> <option value="12th">12th</option> <option value="13th">13th</option> <option value="14th">14th</option> <option value="15th">15th</option> </select> </div> </div> <div class="form-group"> <label for="elevation" class="col-sm-2 control-label">Elevation</label> <div class="col-sm-6"> <input type="number" class="form-control col-sm-6" name="elevation" placeholder="in feet"> </div> </div> <div class="form-group"> <label for="tagNum" class="col-sm-2 control-label">Tag Number</label> <div class="col-sm-6"> <input type="text" class="form-control col-sm-6" name="tagNum"> </div> </div> <div class="form-group"> <label for="manufacturer" class="col-sm-2 control-label">Manufacturer</label> <? /* <input type="text" name="mmn" size="30"> */ ?> <div class="col-sm-6"> <select name="manufacturer" class="depend col-sm-6 form-control" id="manufacturer"> <option value="" selected="selected" disabled="disabled">Select Manufacturer</option> </select> </div> <div id="status"></div> </div> <div class="form-group"> <label for="model" class="col-sm-2 control-label">Model Number</label> <div class="col-sm-6"> <select name="model" class="depend col-sm-6 form-control" id="model"> <option value="" selected="selected">Select value</option> </select> </div> </div> <div class="form-group"> <label for="size" class="col-sm-2 control-label">Size</label> <div class="col-sm-6"> <select name="size" class="depend col-sm-6 form-control" id="size"> <option value="" selected="selected">Select value</option> </select> </div> </div> <div class="form-group"> <label for="pressure" class="col-sm-2 control-label">Pressure</label> <div class="col-sm-6"> <select name="pressure" id="pressure" class="col-sm-6 form-control"> <option value="" selected="selected">Select value</option> </select> </div> </div> <div class="form-group"> <label for="service" class="col-sm-2 control-label">Service</label> <div class="col-sm-6"> <select class="form-control col-sm-6" name="service" name="service"> <option value="TRACER">TRACER</option> <option value="HEATER">HEATER</option> <option value="PROCESS">PROCESS</option> <option value="DRIP">DRIP</option> </select> </div> </div> <div class="form-group"> <label for="trapCond" class="col-sm-2 control-label">Trap Conditions</label> <div class="col-sm-6"> <select class="form-control col-sm-6" name="trapCond"> <option value="OK">OK</option> <option value="BT">BT</option> <option value="CP">CP</option> <option value="VO">VO</option> <option value="RCL">RCL</option> </select> </div> </div> <p></p> <div class="form-group"> <div class="col-sm-offset-2 col-sm-6"> <? if(isset($surveyID)) { echo '<input type="hidden" name="surveyID" value="'.intval($_GET['survey']).'">'; } ?> <!-- <? if(isset($areaID)) { echo '<input type="hidden" name="areaID" value="'.intval($_GET['area']).'">'; } ?> --> <button class="btn btn-default btn-lg" type="submit" name="submit" value="add">Add Trap</button> <button class="btn btn-primary btn-lg" type="submit" name="submit" value="add_area">Submit Area</button> <button class="btn btn-danger btn-lg" type="submit" name="submit" value="submit">Submit Survey</button> </div> </div> </fieldset> </form> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <!-- <script src="../script/js/script.js"></script> --> <script src="../script/js/live.js"></script> <script src="../script/js/bootstrap-datepicker.js"></script> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#dp1').datepicker({ dateFormat : 'dd-mm-yy' }); }); jQuery(document).ready(function() { jQuery('#dp2').datepicker({ dateFormat : 'dd-mm-yy' }); }); </script> </body> </html> <!-- #content --> </div><!-- #primary --> <?php get_sidebar( 'content' ); ?> </div><!-- #main-content --> <?php get_sidebar(); get_footer(); ?> <?php require("../test/base.php"); if(isset($_POST['submit'])) { $url = '../test/form'; // path to form.php if(!isset($_POST['manufacturer'])) { $_POST['manufacturer'] = NULL; } if(!isset($_POST['model_number'])) { $_POST['model_number'] = NULL; } if(!isset($_POST['size'])) { $_POST['size'] = NULL; } if(!isset($_POST['pressure'])) { $_POST['pressure'] = NULL; } $data = prep($_POST); if($data['submit'] == 'add') { if(!isset($data['surveyID'])) { $surveyID = save_survey($data); } else { $surveyID = $data['surveyID']; } save_survey_details($surveyID, $data); if($surveyID) { header('Location: '.$url.'?survey='.$surveyID); } } if($data['submit'] == 'add_area') { if(!isset($data['areaID'])) { $areaID = save_survey($data); } else { $areaID = $data['areaID']; } save_survey_details($areaID, $data); if($areaID) { header('Location: '.$url.'?survey='.$areaID); } } elseif($data['submit'] == 'submit') { if(isset($data['surveyID'])) { save_survey_details($data['surveyID'], $data); } else { $surveyID = save_survey($data); save_survey_details($surveyID, $data); } header('Location: '.$url); } } function prep($input) { $data = array(); if(is_array($input)) { foreach ($input as $key => $val) { $data[$key] = mysql_real_escape_string($val); } } return $data; } function format_date($date = '') { if(isset($date) && $date) { $tmp = explode('-', $date); $d = $tmp[2].'-'.$tmp[0].'-'.$tmp[1]; } else { $d = NULL; } return $d; } function save_survey($data) { $result = mysql_query("INSERT INTO surveys (date, plant_name, plant_location, plant_contact_name, pph, area) VALUES('".format_date($data['dateSurvey'])."','".$data['plantName']."','".$data['plantLoc']."','".$data['plantContact']."','".$data['pph']."','".$data['area']."')") or die('Error: ' . mysql_error()); $result = mysql_query("INSERT INTO area (date, plant_name, plant_location, plant_contact_name, pph, area) VALUES('".format_date($data['dateSurvey'])."','".$data['plantName']."','".$data['plantLoc']."','".$data['plantContact']."','".$data['pph']."','".$data['area']."')") or die('Error: ' . mysql_error()); return mysql_insert_id(); } function save_survey_details($surveyID, $data) { $result = mysql_query("INSERT INTO survey_details (survey_id, tested_date, direction, location, floor_level, elevation, tag_number, manufacturer, model_number, size, pressure, service, trap_conditions) VALUES($surveyID, '".format_date($data['testDate'])."','".$data['direction']."','".$data['location']."','".$data['flrLevel']."','".$data['elevation']."','".$data['tagNum']."','".$data['manufacturer']."','".$data['model']."','".$data['size']."','".$data['pressure']."','".$data['service']."','".$data['trapCond']."')"); $result = mysql_query("INSERT INTO area_details (survey_id, tested_date, direction, location, floor_level, elevation, tag_number, manufacturer, model_number, size, pressure, service, trap_conditions) VALUES($surveyID, '".format_date($data['testDate'])."','".$data['direction']."','".$data['location']."','".$data['flrLevel']."','".$data['elevation']."','".$data['tagNum']."','".$data['manufacturer']."','".$data['model']."','".$data['size']."','".$data['pressure']."','".$data['service']."','".$data['trapCond']."')"); //or die('Error: ' . mysql_error()); } ?> Hi all, I have quite a big issue regarding an e-commerce site I'm in the process of redeveloping.
The company whom I work for sell hundreds of event tickets to clients worldwide. I've been tasked with rebuilding the entire shop as its very basic at the moment, and only accepts PP express. The shop itself only has a few categories so the design / layout isn't a problem for me. The main issue is with the dev site of things. They want me to integrate a so-called 'white label' or 'affiliate' type system so that other 'agencies' can register with ourselves. From there they would have access to our product list and be able to add them on their own shop. In turn they would receive a commission for every sale.
I was thinking about going with Prestashop or Drupal but this kind ingratiation has me thinking if its even possible. I'm not even sure if there are any off-the-self solutions that would do exactly what we need, without hiring a developer.. anyone here have any experience building a similar system?
Any guidance of any of this would be greatly appreciated.
Thanks 4T7
Edited by 4T7, 05 November 2014 - 09:05 AM. I have two sets of codes that work perfectly. One is for the table and the other is for the rating system. I can't seem to figure out how to combine the two codes so that the rating system is displayed INSIDE the table instead of after it. I'm not sure if it's possible, but I've seen it used on sites like Netflix. If you can tell me how to fix it or give me a different suggestion I would be eternally thankful. What I am trying to do ultimately is have a table that has a star rating associated with each entry without linking to a full page. Code: [Select] <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src="/jquery_star.js"></script> <script type="text/javascript" src="/script.js"></script> <?php $con = mysql_connect("localhost","myhowd5_undrdg","indie500"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myhowd5_jo151", $con); $result = mysql_query("SELECT * FROM jos_easytables_table_data_1"); echo "<table border='1'> <tr> <th>Artist</th> <th>Genre</th> <th>Your Rating</th> <th>Average Rating</th> <th>Total Votes</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['column0'] . "</td>"; echo "<td>" . $row['column1'] . "</td>"; echo "<td>" . $row['rating'] . "</td>"; echo "<td>" . $row['total_rating'] . "</td>"; echo "<td>" . $row['total_ratings'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> <?php mysql_connect("localhost", "myhowd5_undrdg", "indie500") or die(mysql_error()); mysql_select_db("myhowd5_jo151") or die(mysql_error()); $query = mysql_query("SELECT * FROM jos_easytables_table_data_1"); while($row = mysql_fetch_array($query)) { $rating = (int)$row[rating]; ?> <div class="floatleft"> <div id="rating_<?php echo $row[id]; ?>"> <span class="star_1"><img src="/star_blank.png" alt="" <?php if($rating > 0) { echo"class='hover'"; } ?> /></span> <span class="star_2"><img src="/star_blank.png" alt="" <?php if($rating > 1.5) { echo"class='hover'"; } ?> /></span> <span class="star_3"><img src="/star_blank.png" alt="" <?php if($rating > 2.5) { echo"class='hover'"; } ?> /></span> <span class="star_4"><img src="/star_blank.png" alt="" <?php if($rating > 3.5) { echo"class='hover'"; } ?> /></span> <span class="star_5"><img src="/star_blank.png" alt="" <?php if($rating > 4.5) { echo"class='hover'"; } ?> /></span> </div> </div> <div class="star_rating"> (Rated <strong><?php echo $rating; ?></strong> Stars) </div> <div class="clearleft"> </div> <?php } ?> Hi I am trying to modify my database and am using the following part of code which isn't working. $bad is various values seperated by a newline. The strange thing about the code is that it works when their is only one $value but won't work if their are two or more values even though it is too easy to be wrong. Please help $badarray=explode(array("\r\n", "\r", "\n"),$bad); foreach($badarray as $value){ $value= str_replace(array("\r\n", "\r", "\n"),NULL,trim($value)); echo $value; $query="Update googlevacancies_junk SET exist='$no' WHERE email='$value' "; mysql_query($query); } This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=354184.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=355955.0 My first real attempt to mess with MySql. Keep getting a syntax error and I am quite confused. Error: Code: [Select] Parse error: syntax error, unexpected '}' in /home/a8152576/public_html/MemberSystem/install1.php on line 68 Here is my php code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <h2><center>Fill in the following info properly to install required databases.</center></h2> <p> <label>Host: <input type="text" name="host" id="host" /> </label> </p> <p> <label>Database User: <input type="text" name="dbUser" id="dbUser" /> </label> </p> <p> <label>Database Password: <input type="text" name="dbPass" id="dbPass" /> </label> </p> <p> <label>Desired Admin Username: <input type="text" name="adminName" id="adminName" /> </label> </p> <p> <label>Desired Admin Password: <input type="text" name="adminPass" id="adminPass" /> </label> </p> <p> <label>Email: <input type="text" name="adminEmail" id="adminEmail" /> </label> </p> <p> <input type="submit" name="submitBtn" id="submitBtn" value="Submit" /> </p> </form> <?php if(isset($_POST['submit'])){ $hostName = $_POST['host']; $dbUserName = $_POST['dbUser']; $dbPassword = $_POST['dbPass']; $adminUserName = $_POST['adminName']; $adminPassword = $_POST['adminPass']; $email = $_POST['adminEmail']; $sqlLink = mysql_connect('$hostName','$dbUserName','$dbPassword'); if(!$sqlLink){ die('Could not connect: ' .mysql_error()); mysql_close(); } else { $queryCreate = 'CREATE DATABASE member_db'; echo 'Connected successfully!'; if(mysql_query($queryCreate,$link)){ echo 'Created database!'; mysql_select_db('member_db'); $createAdminTable = "CREATE TABLE " .$adminUserName. " (`secLvl` tinyint(1) default NOT NULL,`rank` tinyint(2) default NOT NULL,`username` varChar(32) NOT NULL UNIQUE,`password` varChar(32) NOT NULL,`email` varChar(32) NOT NULL UNIQUE"; $insertAdminInfoQuery = "UPDATE " .$adminUserName. " SET `secLvl` = '5', `rank` = '10', `username` = '$adminUserName', `password` = '$adminPassword', `email` = '$email' WHERE '$adminUserName' LIMIT 1"; mysql_query($createAdminTable) or die("ERROR: " .mysql_error()); mysql_query($insertAdminInfoQuery) or die("ERROR: " .mysql_error()) } else { echo 'Error: '.mysql_error(); } } } ?> </body> </html> You can even see the error on this web page directly: http://www.ptcptc.info/MemberSystem/install1.php Thanks, Brandon i'm just having a little bit of a play around making a browser-based text RPG with PHP and mySQL. But when it comes to creating a system where a player can view their inventory, and for that matter -have- items. i just don't know where to begin. Would i make a seperate database for inventories and have each column in the database be a different inventory slot and then have the value in that field be in reference to an item? like 1 = potion, 2= ether, etc? with a large amount of items and inventory space for each player i don't want to get started down a long road on the wrong path. To reiterate, I'm not asking for the code specifically i'm just asking what way I would go about it. What would be the simplest, least headachey method of such a system? Hey, sorry I'm a newb so prepare for me to do everything wrong even though I read the FAQ.
I'm trying to use a simple php script to input data to register but I get this error:
"Failed to run query: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined" once I fill out the form.
I've seen other people get this error but I seem to have different problems to them and can't figure it out.
My PHP script is just
<?php require("config.inc.php"); //if posted data is not empty if (!empty($_POST)) { if (empty($_POST['username']) || empty($_POST['password'])) { $response["success"] = 0; $response["message"] = "Please Enter Both a Username and Password."; die(json_encode($response)); } $query = " SELECT 1 FROM users WHERE username = :user"; $query_params = array( ':user' => $_POST['username'] ); try { $stmt = $db->prepare($query); $result = $stmt->execute($query_params); } catch (PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); $response["success"] = 0; $response["message"] = "Database Error. Please Try Again!"; die(json_encode($response)); } $row = $stmt->fetch(); if ($row) { die("This username is already in use"); $response["success"] = 0; $response["message"] = "I'm sorry, this username is already in use"; die(json_encode($response)); } $query = "INSERT INTO users ( username, password ) VALUES ( :user, :pass ) "; $query_params = array( ':username' => $_POST['username'], ':password' => $_POST['password'] ); try { $stmt = $db->prepare($query); $result = $stmt->execute($query_params); } catch (PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); $response["success"] = 0; $response["message"] = "Database Error. Please Try Again!"; die(json_encode($response)); } $response["success"] = 1; $response["message"] = "Username Successfully Added!"; echo json_encode($response); } else { ?> <h1>Register</h1> <form action="index.php" method="post"> Username:<br /> <input type="text" name="username" value="" /> <br /><br /> Password:<br /> <input type="password" name="password" value="" /> <br /><br /> <input type="submit" value="Register New User" /> </form> <?php } ?>and the config: <?php $username = "root"; $password = ""; $host = "localhost"; $dbname = "drinkdealz"; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); try { $db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); } catch(PDOException $ex) { die("Failed to connect to the database: " . $ex->getMessage()); } $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { function undo_magic_quotes_gpc(&$array) { foreach($array as &$value) { if(is_array($value)) { undo_magic_quotes_gpc($value); } else { $value = stripslashes($value); } } } undo_magic_quotes_gpc($_POST); undo_magic_quotes_gpc($_GET); undo_magic_quotes_gpc($_COOKIE); } header('Content-Type: text/html; charset=utf-8'); session_start(); ?>Sorry if I uploaded anything wrong and it's only a localhost so I don't really care about passwords etc (none will be the same when I upload it) So if any of you can even point me in the direction of what to look for that would be brilliant. Cheers, Kieran Hi, i'm basically having problems with this code, its for a newsletter script which added the email address into a file, i'm trying to convert it to work with mysql but having a few problems; I've edited the last bit, the code just basically doesn't add it to the database even though i thought i had done it right... any help is very much appreciated! If email is not valid the script is letting me know; if email is valid it says "already added to the list" no matter what. old script <?php /** BY WebResourcesDepot - http://www.webresourcesdepot.com*/ /** YOU CAN EDIT HERE*/ $newsletterFileName = "file.txt"; /** IMPORTANT: EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING*/ function GetField($input) { $input=strip_tags($input); $input=str_replace("<","<",$input); $input=str_replace(">",">",$input); $input=str_replace("#","%23",$input); $input=str_replace("'","`",$input); $input=str_replace(";","%3B",$input); $input=str_replace("script","",$input); $input=str_replace("%3c","",$input); $input=str_replace("%3e","",$input); $input=trim($input); return $input; } /**Validate an email address. Provide email address (raw input) Returns true if the email address has the email address format and the domain exists. */ function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } } return $isValid; } $email = GetField($_GET['email']); $pass = validEmail($email); if ($pass) { $f = fopen($newsletterFileName, 'a+'); $read = fread($f,filesize($newsletterFileName)); If (strstr($read,"@")) { $delimiter = ";"; } if (strstr($read,$email)) { echo 3; } else { fwrite($f, $delimiter . $email); echo 1; } fclose($f); } else { echo 2; } ?> edited script <?php /** BY WebResourcesDepot - http://www.webresourcesdepot.com*/ /** YOU CAN EDIT HERE*/ $newsletterFileName = "file.txt"; /** IMPORTANT: EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING*/ function GetField($input) { $input=strip_tags($input); $input=str_replace("<","<",$input); $input=str_replace(">",">",$input); $input=str_replace("#","%23",$input); $input=str_replace("'","`",$input); $input=str_replace(";","%3B",$input); $input=str_replace("script","",$input); $input=str_replace("%3c","",$input); $input=str_replace("%3e","",$input); $input=trim($input); return $input; } /**Validate an email address. Provide email address (raw input) Returns true if the email address has the email address format and the domain exists. */ function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } } return $isValid; } $email = GetField($_GET['email']); $pass = validEmail($email); if ($pass) { $user_name = "_db"; $password = ""; $database = "_db"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL2 = "SELECT * FROM newsletter WHERE email = '$_GET[email]'"; $result = mysql_query($SQL2); mysql_close($db_handle); } if (strstr($SQL2,$email)) { echo 3; } else { $user_name = "_db"; $password = ""; $database = "_db"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO newsletter (email,subscribed) VALUES ('$_GET[email]',1)"; $result = mysql_query($SQL); mysql_close($db_handle);} echo 1; } } else { echo 2; } ?> Hi, Im just in the middle of creating an update script for my mysql database but don't know why it's not working. p.s. I'm a little new to PHP, but know quite a bit, it's probably something really small.. *facepalm* Here's the script: the form (update.php) <? // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $id = $_GET['id']; // Ask the database for the information from the links table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"Name"); $location=mysql_result($result,$i,"Location"); $fault=mysql_result($result,$i,"Fault"); ?> <form action="updated.php" method="post"> <input type="hidden" name="ud_id" value="<? echo "$id";?>"> Name: <input type="text" name="ud_name" value="<? echo "$name"?>"><br> Location: <input type="text" name="ud_location" value="<? echo "$location"?>"><br> Fault: <input type="text" name="ud_fault" value="<? echo "$fault"?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> ------------------------------------------------------ (processor) updated.php <?php // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $query="UPDATE orders SET Name='" . $_POST['ud_name'] . "', Location='" . $_POST['ud_location'] . "', Fault='" . $_POST['ud_fault'] . "' WHERE $id='" . $_POST['ud_id'] . "'"; echo $query; $checkresult = mysql_query($query); if ($checkresult) echo '<p>update query succeeded'; else echo '<p>update query failed'; mysql_close(); ?> ------------------------------------------------------ Every time I want to update, it comes up with: UPDATE orders SET Name='TEST', Location='TEST', fault='jbjh' WHERE ='' update query failed Any help would be appreciated. |