PHP - Jeditable - Send Data Back To Database
Hi All,
I have a table (with an ID of example) that can be seen he http://tinyurl.com/cfla7wp The following script calls jeditable.js and makes the Telephone & Mobile columns editable. Once edited, the table shows the new value plus a * symbol. Code: [Select] <script type="text/javascript"> $(document).ready(function() { /* Init DataTables */ var oTable = $('#example').dataTable(); /* Apply the jEditable handlers to the table */ $('td:eq(4), td:eq(5)', oTable.fnGetNodes()).editable( 'update_table_tenants.php', { "callback": function( sValue, y ) { var aPos = oTable.fnGetPosition( this ); oTable.fnUpdate( sValue, aPos[0], aPos[1] ); }, "submitdata": function ( value, settings ) { return { "row_id": this.parentNode.getAttribute("1"), "column": oTable.fnGetPosition( this )[2] }; }, "height": "14px" } ); } ); </script> What I need to do however is add the value entered into my database, but I do not know how to do this. I believe I need to do something like: UPDATE my_table VALUE whatever column has been edited in the table WHERE tenID is the same as the row selected in the table i.e. if I update the MOBILE NUMBER of the person called BILL GATES it would find his tenID, update numMobile in the table called my_table All help appreciated Dave Similar TutorialsI have a profile page where the user answers a list of about 20 questions. These questions are then put into a mysql table with username, questionid, and answer. I can store the answers to the table, but I cannot figure out how to get them back to view and edit. My form is built from basic HTML. I know how to pull answers from a db table with only 1 row of results, where each field is a different question, but this one is different, as it will pull 20 rows, and each row is for a different question. Here is how I populate the questions and then fill in the answers. Code: [Select] // If this user has never set their profile, insert empty questions into the database $query1 = "SELECT * FROM u_profile WHERE username = '" . $_SESSION['username'] . "'"; $data = mysqli_query($dbc, $query1); if (mysqli_num_rows($data) == 0) { // First grab the list of questionids $query2 = "SELECT questionid FROM questions ORDER BY q_order"; $data = mysqli_query($dbc, $query2); $questionids = array(); while ($row = mysqli_fetch_array($data)) { array_push($questionids, $row['questionid']); } // Insert empty question rows into the u_profile table, one per question foreach ($questionids as $questionid) { $query3 = "INSERT INTO u_profile (username, questionid) VALUES ('" . $_SESSION['username']. "', '$questionid')"; mysqli_query($dbc, $query3); } } // If the questionnaire form has been submitted, write the responses to the database if (isset($_POST['submit'])) { // Write the questionnaire response rows to the response table foreach ($_POST as $answer_id => $answer) { $query4 = "UPDATE u_profile SET answer = '$answer' WHERE username = '" . $_SESSION['username'] . "' AND questionid = '$answer_id'"; $uprofile_set = "CALL uprofile_set('" . $_SESSION['username'] . "')"; mysqli_query($dbc, $query4) or die( "Connection Error1" . mysqli_error($dbc) ) ; mysqli_query($dbc, $uprofile_set) or die( "Connection Error2" . mysqli_error($dbc) ) ; } $races = "SELECT * FROM u_raceschedule WHERE username = '" . $_SESSION['username'] . "'"; $data = mysqli_query($dbc, $races); if (mysqli_num_rows($data) > 0) { set_time_limit(30); $buildplan = "CALL tplan('" . $_SESSION['username'] . "')"; mysqli_query($dbc,$buildplan) or die("Connection Error2" . mysqli_error($dbc) ) ; Would LOVE any help. I am really new to this whole coding thing. Hi, I'm trying to setup a quick PHP script that will grab the email from the url (see below) and after inserting into MySQL db - which is working fine - the script will complete two additional tasks: 1. send that same captured email out to a external db as in shown via http://domain1.com/insert.php?email=$lead (example), but then send to a DIFFERENT source - the originator of the lead - a portback acknowledgement using Header (sending the status and email to http://domain2.com/check.php?e=$lead&s=$status for their records). See the code below: ------------------------- Code: [Select] $lead = $_REQUEST['e_mail']; // will grab email from posted url string and assign to local variable $result = mysql_query($command); // this is just to execute the MySQL insert which works just fine but included here to explain validation below // Create API Call string to insert lead into iContact folder $requestURL = "http://domain1.com/insert.php?email=$lead"; // Execute API Call to CAKE $xml = simplexml_load_file($requestURL) or die("feed not loading"); if ($result) { $status = 1; // mark lead as sucess // send postback on lead status header("Location: http://domain2.com/check.php?e=$lead&s=$status"); } -------- Problem: I'm getting all sorts of errors with the simplexml_load_file() function and can't figure out why it won't work. Any input appreciated as this the only way I know how to pass the lead onward and then inform/update the other party of receipt of information. thanks! the second database found on the cloud
i try to get JSON data but how to insert and update them to another online database with the same table my php script to return json data <?php include_once('db.php'); $users = array(); $users_data = $db -> prepare('SELECT id, username FROM users'); $users_data -> execute(); while($fetched = $users_data->fetch()) { $users[$fetchedt['id']] = array ( 'id' => $fetched['id'], 'username' => $fetched['name'] ); } echo json_encode($leaders);
i get
{"1":{"id":1,"username":"jeremia"},"2":{"id":2,"username":"Ernest"}} Edited March 24 by mahenda OK, I think this should belong on this board. I am trying to write something that does the following (simplified for ease of understanding): User has signed into my website and has a session variable with their user id in it. There is a table in the mySQL databse that contains details about the user. (this part is already working) User wants to pay for a trip, so clicks a customised Paypal button that takes him to the Paypal site. The item has an trip id associated with it. Once the transaction has been completed, I want to feed information back to my website, and insert the 'item id' and 'user id' into a field in a table in the database. Any idea how I might do this!? Whilst I have a basic script that will insert a row into my table, it relies on variables being sent from the page it is on, thus will not work when the user is redirected to Paypal, as I cannot find a way to send variables to paypal about the item, and then have them send it back to me once the transaction is complete. My PHP is self-taught so sorry if this way of doing things seems a bit scrappy. Hi, I would like to send a value in a link and request it back in ajax and set it as a variable in php in the same page, can anyone help me here? thanks Here's the code that deals with the client side:
<?php session_start(); if(!isset($_SESSION['Logged_in'])){ header("Location: /page.php?page=login"); } ?> <!DOCTYPE Html> <html> <head> <!--Connections made and head included--> <?php require_once("../INC/head.php"); ?> <?php require_once("../Scripts/DB/connect.php"); ?> <!--Asynchronously Return User Names--> <script> $(document).ready(function(){ function search(){ var textboxvalue = $('input[name=search]').val(); $.ajax( { type: "GET", url: 'search.php', data: {Search: textboxvalue}, success: function(result) { $("#results").html(result); } }); }; </script> </head> <body> <div id="header-wrapper"> <?php include_once("../INC/nav2.php"); ?> </div> <div id="content"> <h1 style="color: red; text-align: center;">Member Directory</h1> <form onsubmit="search()"> <label for="search">Search for User:</label> <input type="text" size="70px" id="search" name="search"> </form> <a href="index.php?do=">Show All Users</a>|<a href="index.php?do=ONLINE">Show All Online Users</a> <div id="results"> <!--Results will be returned HERE!--> </div>search.php <?php //testing if data is sent ok echo "<h1>Hello</h1><br>" . $_GET['search']; ?>This is the link I get after sending foo. http://www.family-li...php?&search=foo Is that mean it was sent, but I'm not processing it correctly? I'm new to the whole AJAX thing. Hello everyone! I am a new user and I have a simple question. How to download the database and create a backup. Hi everyone, first time here! I am trying to use Jeditable. Not sure if anyone knows about it. http://www.appelsiini.net/projects/jeditable Basically its a Edit-in-place plugin for JQuery. However it requires a PHP script and Im pretty sure a mySQL db to work properly. I believe the PHP does something along the lines of taking the new inputted data, sending it to a db then echoing it back to where ever it came from, I think it achieves this using the $_POST function. This is exactly what I want! However this is the first time I have dealt with PHP. Im not too bad at Javascript but PHP is new to me. I have googled my brains out looking for an example php file for this but they don't seem to be around. I understand it cant just be written for me because it would be a different script for every one, and that's not what i want either. But some examples would be great ! The javascript i have so far is Code: [Select] <html> <head> <style type="text/css"> a.test { font-weight: bold; } </style> <script type="text/javascript" src="jquery-1.4.3.min.js"></script> <script src="jquery.jeditable.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('.edit').editable('http://Example.com/save.php', { indicator : 'Saving...', tooltip : 'Click to edit...' }); $('.edit_area').editable('http://Example.com/save.php', { type : 'textarea', cancel : 'Cancel', submit : 'OK', indicator : '<img src="img/indicator.gif">', tooltip : 'Click to edit...' }); }); </script> </head> <body> <div class="edit" id="div_1">Dolor</div> <div class="edit_area" id="div_2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div> <a href="http://jquery.com/">jQuery</a> </body> </html> Any help would be great! I think its at least mostly right so far but perhaps I'm missing something important which is why I cant get it all to come together. Ok so I have this site where I'm posting a message to my Database. But when I go to pull the message from the MYSQL DB it's one long sentence. Any suggestions? Hi.. I've seen code for back up database but when I run the code the database was backup outside the folder. I want to put the back up database inside the folder here is the code: Code: [Select] <?php include 'config.php'; backup_tables('localhost','root','','payroll'); /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*') { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $myfoldername = "backup_DBPayroll";//your folders name $handle = fopen(getcwd().$myfoldername.'db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); // $handle = fopen('db-backup-'.date('m-d-Y').'-'.(md5(implode(',',$tables))).'.sql','w+'); fwrite($handle,$return); fclose($handle); } $smarty->display('header_cat.tpl'); $smarty->display('backup.tpl'); $smarty->display('footer.tpl'); ?> Thank you in advance I have a table that has a cell that I've made editable:
echo "<td contenteditable='true'>" . $row['Comments'] . "</td>";Which is cool I guess, but it doesn't go anywhere from there. I'd like to make it so that upon changing, it links back to an SQL UPDATE query that I define. Is this possible through some sort of onChange function? I have these two tables...
schedule (gameid, homeid, awayid, weekno, seasonno)
teams (teamid, location, nickname)
This mysql query below gets me schedule info for ALL 32 teams in an array...
$sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2014"; $schedule= mysqli_query($connection, $sql); if (!$schedule) { die("Database query failed: " . mysqli_error($connection)); } else { // Placeholder for data $data = array(); while($row = mysqli_fetch_assoc($schedule)) { if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; } }However, I only want to get info for one specific team, which is stored in the $teamid variable. This should be very easy, right? I have tried multiple things, including this one below (where I added an AND statement of "AND (h.teamid=$teamid OR a.teamid=$teamid)"), but this one still outputs too much... $sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2014 AND (h.teamid=$teamid OR a.teamid=$teamid)"; $schedule= mysqli_query($connection, $sql); if (!$schedule) { die("Database query failed: " . mysqli_error($connection)); } else { // Placeholder for data $data = array(); while($row = mysqli_fetch_assoc($schedule)) { if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; } }Below is the array that the above outputs. In a nutshell, all I want is that 1st array ([1]) which has, in this example, the Eagles full schedule. It's not giving me too much else and I guess I could live with it and just ignore the other stuff, but I'd rather be as efficient as possible and only get what I need... Array ( [1] => Array ( [1] => Jaguars [2] => @ Colts [3] => Redskins [4] => @ 49ers [5] => Rams [6] => Giants [7] => BYE [8] => @ Cardinals [9] => @ Texans [10] => Panthers [11] => @ Packers [12] => Titans [13] => @ Cowboys [14] => Seahawks [15] => Cowboys [16] => @ Redskins [17] => @ Giants ) [27] => Array ( [1] => @ Eagles ) [28] => Array ( [2] => Eagles ) [4] => Array ( [3] => @ Eagles [16] => Eagles ) [14] => Array ( [4] => Eagles ) [15] => Array ( [5] => @ Eagles ) [3] => Array ( [6] => @ Eagles [17] => Eagles ) [] => Array ( [7] => @ Eagles ) [16] => Array ( [8] => Eagles ) [25] => Array ( [9] => Eagles ) [11] => Array ( [10] => @ Eagles ) [7] => Array ( [11] => Eagles ) [26] => Array ( [12] => @ Eagles ) [2] => Array ( [13] => Eagles [15] => @ Eagles ) [13] => Array ( [14] => @ Eagles ) ) When i $_POST[] the form it doesn't send anything to database after the & sign. How can i allow it to send without breaking the php code or whatever. right now I have : mysql_real_escape_string(ucwords($_POST['title'])); Thanks. hello dear php-experts,
https://europa.eu/youth/volunteering/organisations_en#open
<?php // Report all PHP errors (see changelog) error_reporting(E_ALL); include('inc/simple_html_dom.php'); //base url $base = 'https://europa.eu/youth/volunteering/organisations_en#open'; //home page HTML $html_base = file_get_html( $base ); //get all category links foreach($html_base->find('a') as $element) { echo "<pre>"; print_r( $element->href ); echo "</pre>"; } $html_base->clear(); unset($html_base); ?>
I have the above code and I'm trying to get certain elements of the page but it isn't returning anything.
Is it possible that certain PHP functions might be disabled on the server to stop that? The above code works perfectly on other sites.
Is there any workaround?
btw: i have created a small snipped as a proof of concept to run this with Python and BeautifulSoup -
import requests from bs4 import BeautifulSoup url = 'https://europa.eu/youth/volunteering/organisations_en#open' response = requests.get(url) soup = BeautifulSoup(response.content, 'lxml') print(soup.find('title').text) block = soup.find('div', class_="eyp-card block-is-flex")
and this....
European Youth Portal >>> block.a <a href="/youth/volunteering/organisation/48592_en" target="_blank">"Academy for Peace and Development" Union</a> >>> block.a.text '"Academy for Peace and Development" Union' >>> block.select_one('div > div > p:nth-child(9)') <p><strong>PIC:</strong> 948417016</p> >>> block.select_one('div > div > p:nth-child(9)').text 'PIC: 948417016'
what is aimed in the end - i want to gather the first 20 results of the page - and put them in to a sql-db or alternatively show the information in a little widget Hello i have some problems i hope some one can help me, first i want add new field data for like (data number) but if i add $name=$_POST['NR']; and make new <td><div align="left">Your number</div></td> <td><input name="NR" type="text" size="40"></td> and $query=( "INSERT INTO user (uname, pw,email,NR,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')"); i get no result to database what could be the problem (database table exsist) Code: [Select] <?php if(isset($_POST['Submit'])){ //NEED TO CHECK IF FIELDS ARE FILLED IN if( empty($_POST['name']) && (empty($_POST['email']))){ header("Location:Messages.php?msg=3"); exit(); } if( empty($_POST['pw1']) && (empty($_POST['pw2']))){ header( "Location:Messages.php?msg=4" ); exit(); } $name=$_POST['name']; $email=$_POST['email']; $pw1=$_POST['pw1']; $pw2=$_POST['pw2']; if("$pw1" !== "$pw2" ){ header( "Location:Messages.php?msg=5" ); exit(); } $ip = $_SERVER['REMOTE_ADDR']; //connect to the db server , check if uname exist include('config.php'); $query=("Select * from user where uname='$name'"); $result= mysql_query($query); $num=mysql_num_rows($result); if ($num > 0) {//Username already exist header( "Location:Messages.php?msg=6" ); exit(); }else{ //if username does not exist insert user details $query=( "INSERT INTO user (uname, pw,email,date_joined,ip,level) VALUES ('$name',password('$pw1'),'$email',NOW(),'$ip','Normal')"); if (@mysql_query ($query)) { header("location:login.php?reg=1"); exit; } } mysql_close(); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><!-- InstanceBegin template="/Templates/Auth.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <!-- InstanceBeginEditable name="doctitle" --> <title>Registration</title> <!-- InstanceEndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <!-- InstanceBeginEditable name="head" --> <!-- InstanceEndEditable --> <link href="styleLog.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" cellspacing="7" cellpadding="0"> <tr class="temptitle"> <td><!-- InstanceBeginEditable name="EditRegion4" -->New User Registration <!-- InstanceEndEditable --></td> </tr> <tr> <td><!-- InstanceBeginEditable name="EditRegion3" --> <form name="form1" action="register.php" method="post"> <table width="657" border="0"> <tr> <td width="122"><div align="left">Name</div></td> <td width="525"><input name="name" type="text" size="40"></td> </tr> <tr> <td><div align="left">Email</div></td> <td><input name="email" type="text" size="40"></td> </tr> <tr> <td><div align="left">Password</div></td> <td><input name="pw1" type="password" size="40"></td> </tr> <tr> <td ><div align="left">Confirm Password </div></td> <td><input name="pw2" type="password" size="40"></td> </tr> <tr> <td></td> <td> <input name="Submit" type="submit"></td> </tr> </table> </form> <!-- InstanceEndEditable --></td> </tr> <tr> <td><div align="center">Copyright 2005 </div></td> </tr> </table> </body> <!-- InstanceEnd --></html> hello and good day
first of all:; i hope youre all right and everything goes well at your site;: Worpress-Plugin API - giving back the meta-data according the usage of different filters
I'm currently working on a parser to make a small preview on the newest plugins in wordpress. at the moment i think i work from a URL given out of the range of these: https://de.wordpress.org/plugins/browse/popular/ - let us say the first 30 to 40 URL-pages.
What i subsequently want to filter out after the fetch is - those plugins that have the newest timestamp Version: 1.9.5.12 installations: 10,000+ WordPress Version: 5.0 or higher Tested up to: 5.4 PHP Version: 5.6 or higher Tags 3 Tags: database member sign-up form volunteer Last updated: 19 hours ago plugin-ratings
Supported arguments per action +--------------------+---------------+--------------------+----------+----------------+ | | | | | | +--------------------+---------------+--------------------+----------+----------------+ | Argument Name | query_plugins | plugin_information | hot_tags | hot_categories | | $slug | No | Yes | No | No | | $per_page | Yes | No | No | No | | $page | Yes | No | No | No | | $number | No | No | Yes | Yes | | $search | Yes | No | No | No | | $tag | Yes | No | No | No | | $author | Yes | No | No | No | | $user | Yes | No | No | No | | $browse | Yes | No | No | No | | $locale | Yes | Yes | No | No | | $installed_plugins | Yes | No | No | No | | $is_ssl | Yes | Yes | No | No | | $fields | Yes | Yes | No | No | +--------------------+---------------+--------------------+----------+----------------+
regards dil_Bert
cf: https://developer.wordpress.org/reference/functions/plugins_api/ $fields = array( 'active_installs' => true, // rounded int 'added' => true, // date 'author' => true, // a href html 'author_block_count' => true, // int 'author_block_rating' => true, // int 'author_profile' => true, // url 'banners' => true, // array( [low], [high] ) 'compatibility' => false, // empty array? 'contributors' => true, // array( array( [profile], [avatar], [display_name] ) 'description' => false, // string 'donate_link' => true, // url 'download_link' => true, // url 'downloaded' => false, // int // 'group' => false, // n/a 'homepage' => true, // url 'icons' => false, // array( [1x] url, [2x] url ) 'last_updated' => true, // datetime 'name' => true, // string 'num_ratings' => true, // int 'rating' => true, // int 'ratings' => true, // array( [5..0] ) 'requires' => true, // version string 'requires_php' => true, // version string // 'reviews' => false, // n/a, part of 'sections' 'screenshots' => true, // array( array( [src], ) ) 'sections' => true, // array( [description], [installation], [changelog], [reviews], ...) 'short_description' => false, // string 'slug' => true, // string 'support_threads' => true, // int 'support_threads_resolved' => true, // int 'tags' => true, // array( ) 'tested' => true, // version string 'version' => true, // version string 'versions' => true, // array( [version] url ) );
what do you say-!? Hello everyone , I am new to php .. I am trying to make website that other people can order my books.So I saw video tutorial about making shopping cart and everything works , until part when other person need to send me information what ordered. With paypal it works , but in my country paypal is not available to use , so I want them to send me their details , and I will send them books . I made database , it works to get their details , but can't get hidden parts , product_id , product_id_array and cartTotal so I can know what they ordered , and how much they need to pay me .. How to "grab" what they ordered , they shopping cart when have products .. Thanks in advance for help )) cart.php codes Quote <?php session_start(); // Start session first thing in script // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 1 (if user attempts to add something to the cart from the product page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['pid'])) { $pid = $_POST['pid']; $wasFound = false; $i = 0; // If the cart session variable is not set or cart array is empty if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { // RUN IF THE CART IS EMPTY OR NOT SET $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1)); } else { // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $pid) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); $wasFound = true; } // close if condition } // close while loop } // close foreach loop if ($wasFound == false) { array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1)); } } header("location: cart.php"); exit(); } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 2 (if user chooses to empty their shopping cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { unset($_SESSION["cart_array"]); } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 3 (if user chooses to adjust item quantity) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") { // execute some code $item_to_adjust = $_POST['item_to_adjust']; $quantity = $_POST['quantity']; $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers if ($quantity >= 100) { $quantity = 99; } if ($quantity < 1) { $quantity = 1; } if ($quantity == "") { $quantity = 1; } $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $item_to_adjust) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity))); } // close if condition } // close while loop } // close foreach loop } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 4 (if user wants to remove an item from cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") { // Access the array and run code to remove that array index $key_to_remove = $_POST['index_to_remove']; if (count($_SESSION["cart_array"]) <= 1) { unset($_SESSION["cart_array"]); } else { unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>"; } else { // Start PayPal Checkout Button $pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="">'; // Start the For Each loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $pricetotal = number_format ($pricetotal , $decimals = 0); // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>'; $cartOutput .= '<td>' . $details . '</td>'; $cartOutput .= '<td>$' . $price . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustBtn' . $item_id . '" type="submit" value="change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .= '</tr>'; $i++; } setlocale(LC_MONETARY, "en_US"); $cartTotal = number_format ($cartTotal , $decimals = 0); $cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : ".$cartTotal." USD</div>"; // Finish the Paypal Checkout Btn $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="http://mywebsite.com"> <input type="hidden" name="return" value="http://mywebsite.com"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="Return to The Store"> <input type="hidden" name="cancel_return" value="http://mywebsite.com"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!"> </form>'; } ?> <!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>Your Cart</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <div id="pageContent"> <div style="margin:24px; text-align:left;"> <br /> <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr> <td width="18%" bgcolor="#C5DFFA"><strong>Product</strong></td> <td width="45%" bgcolor="#C5DFFA"><strong>Product Description</strong></td> <td width="10%" bgcolor="#C5DFFA"><strong>Unit Price</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Quantity</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Total</strong></td> <td width="9%" bgcolor="#C5DFFA"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> <?php echo $cartTotal; ?> <br /> <br /> <form action="create.php" method="post"> <input type="hidden" name="inputid" value="<?php echo $id; ?>"> <br/> <input type="hidden" name="product_id" value="' . $product_id . '"> <br/> <input type="text" name="inputPayer_email" value="" /> <br/> <input type="text" name="inputFirst_name" value="" /> <br/> <input type="text" name="inputLast_name" value="" /> <br/> <input type="text" name="inputAddress_street" value="" /> <br/> <input type="text" name="inputAddress_city" value="" /> <br/> <input type="text" name="inputAddress_state" value="" /> <br/> <input type="hidden" name="custom" value="' . $product_id_array . '"> <br/> <input type="hidden" name="inputcartTotal" value="" /> <input type="submit" name="submit" /> </form> <?php echo $pp_checkout_btn; ?> <br /> <br /> <a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a> </div> <br /> <a href="http://mywebsite.com">Home</a> <br/> <a href="http://mywebsite.com">Order</a> </div> <?php include_once("template_footer.php");?> </div> </body> </html> create.php codes Quote <?php $id = $_POST['inputid']; $product_id = $_POST['inputproduct_id']; $Payer_email = $_POST['inputPayer_email']; $First_name = $_POST['inputFirst_name']; $Last_name = $_POST['inputLast_name']; $Address_street = $_POST['inputAddress_street']; $Address_city = $_POST['inputAddress_city']; $Address_state = $_POST['inputAddress_state']; $product_id_array = $_POST['inputproduct_id_array']; $cartTotal = $_POST['inputcartTotal']; if(!$_POST['submit']) { echo "please fill out this form"; header('Location: index.php'); } else { mysql_query("INSERT INTO `transactions` ( `id` , `product_id` , `payer_email` , `first_name` , `last_name` , `address_street` , `address_city` , `address_state` , `product_id_array` , `cartTotal` ) VALUES (NULL , '$product_id', '$Payer_email', '$First_name', '$Last_name', '$Address_street', '$Address_city', '$Address_state', '$product_id_array', '$cartTotal')") or die(mysql_error()); echo "Added already"; header('Location: index.php'); } ?> order form codes Quote <form action="create.php" method="post"> <input type="hidden" name="inputid" value="<?php echo $id; ?>"> <br/> <input type="hidden" name="product_id" value="' . $product_id . '"> <br/> <input type="text" name="inputPayer_email" value="" /> <br/> <input type="text" name="inputFirst_name" value="" /> <br/> <input type="text" name="inputLast_name" value="" /> <br/> <input type="text" name="inputAddress_street" value="" /> <br/> <input type="text" name="inputAddress_city" value="" /> <br/> <input type="text" name="inputAddress_state" value="" /> <br/> <input type="hidden" name="custom" value="' . $product_id_array . '"> <br/> <input type="hidden" name="inputcartTotal" value="" /> <input type="submit" name="submit" /> </form> So completely new here.
I've created a database that has 4 fields full_name, company, email and serial_no with 2 sample records.
I would like to create a form with those fields, so the data I enter into the form when I press submit it goes into the database. Config File: <?php $mysqli = new mysqli('localhost', 'username', 'pass', 'database_name'); if($mysqli->connect_error) { echo $mysqli->connect_error; } ?>
Index.php <html lang="en"> <head> <meta charset="UTF-8"> <title>Add Record Form</title> </head> <body> <form action="insert.php" method="post"> <p> <label for="Fullname">Fullname:</label> <input type="text" name="full_name" id="Fullname"> </p> <p> <label for="Company">Company:</label> <input type="text" name="Company" id="Company"> </p> <p> <label for="emailAddress">Email Address:</label> <input type="text" name="email" id="emailAddress"> </p> <p> <label for="Serial">Serial:</label> <input type="text" name="Serial" id="Serial"> </p> <input type="submit" value="Submit"> </form> </body> </html>
Insert.php <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "username", "pass", "database_name"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $full_name = mysqli_real_escape_string($link, $_REQUEST['full_name']); $company = mysqli_real_escape_string($link, $_REQUEST['company']); $email = mysqli_real_escape_string($link, $_REQUEST['email']); $serial_no = mysqli_real_escape_string($link, $_REQUEST['serial_no']); // Attempt insert query execution $sql = "INSERT INTO licjwe(full_name, company, email, serial_no) VALUES ('$full_name', '$company', '$email', '$serial_no')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); ?>
This is the error I am getting: ERROR: Could not able to execute INSERT INTO database_name(full_name, company, email, serial_no) VALUES ('test', '', 'email@home.com', ''). Table 'table_name' doesn't exist Not sure what I am doing.
Basically I want to have the form so I can enter the data, once its been entered, it lets me know its been successfully updated, then loads the page again.
Please help. Where have I gone wrong?
This will only send 1 goggles information into the database but I have a "adding" page that can actually add more than 1 goggles at once. I have no idea how to go about saving multiple goggle's information using array or loop. $name= $_POST['goggles_name']; $price = $_POST['goggles_price']; $des = $_POST['goggles_description']; $file = $_FILES['goggles_image']['name']; $chkbox = $_POST['upload']; $id = $_POST['goggles_id']; $query = "UPDATE goggles SET goggles_name = '$name' , goggles_price = '$price' ,goggles_description = '$des' WHERE goggles_id ='".$id."' "; $result = mysqli_query($link, $query) or die(mysqli_error($link)); |