PHP - How To Modify/edit Loop Values From Mysql Database
Hi friends. I want to php code on how i can modify my retrieved database values from a particular table before echoing out. Please could you help me correct the code. Or if there is any better way of editing loop datas before printing out, please kindly drop the code for me. Thanks
<?php please if there is any better way of editing loop values from mysql database before printing out, please kindly drop the code for me. Thanks Similar TutorialsIs it possible to use for loop to insert values into database using for loop? Or what would be the another way to insert these values into the database if the number of values being entered differs from one time to another? Here is basically what I am trying to do: mysql_query("INSERT INTO MaxMillionsNum SET Day='$weekday', DrawDate='$CompleteDate', DateTime='$timestamp', for($i=1; $i<=$SetNumber; $i+=1){ for($j=0; $j<7; j+=1){ $NumberName="Number".$i.$v[$j];//Generating name of database field $$NumberName=$Match[0][$j];//Here I would store the $Match value into the fieldname name created above } } Tries='$RunCounter'"); I have posted one set of values into my database and it worked fine but when i input another set they wont go inside unless i changes the value of the primary index colum. I want to be able to insert a new values regardless of the primary index value. Any idears...? Hi, I have this form which will create a checkbox list using data from my database and also determin if a checkbox had been checked before and check if it had. <form style="text-align:center" name="PrefRestaurant" id="PrefRestaurant" action="preferances_check.php" method="post"><table align="center"> <?php checkbox(id, name, restaurants, id); ?></table> <input type="submit" name="Prefer" id="Prefer" value="Επιλογή"/></form> function checkbox($intIdField, $strNameField, $strTableName, $strOrderField, $strMethod="asc") { $strQuery = "select $intIdField, $strNameField from $strTableName order by $strOrderField $strMethod"; $rsrcResult = mysql_query($strQuery); while ($arrayRow = mysql_fetch_assoc($rsrcResult)) { $testqry = "SELECT * FROM user_restaurant WHERE user_id = $_SESSION[UserId] AND restaurant_id = $arrayRow[id]"; $rsltestqry = mysql_query($testqry); $numrows = mysql_num_rows($rsltestqry); if ($numrows == 1) { echo "<tr align=\"left\"><td><input type=\"checkbox\" name=\"restaurant[]\" value=\"$arrayRow[id]\" checked/>$arrayRow[name]</td></tr>"; } else{ echo "<tr align=\"left\"><td><input type=\"checkbox\" name=\"restaurant[]\" value=\"$arrayRow[id]\" />$arrayRow[name]</td></tr>"; } } } Now the part which I can't get to work is when I'm trying to store the new values in my database. When I click the submit button I clear my database of any row that is related to the currently loggedin user and I want to store his new preferences (checked cheboxes). I've read that only the cheked checkboxes' values are POSTed so I did this (preferances_check.php) foreach($_POST['restaurant'] as $value) { $query="INSERT INTO user_restaurant VALUES ('$_SESSION[UserId]','$value')"; } But it is not working, nothing gets written in my table Could someone please enlighten me on this? Thnks! Hello there,
I'm really new at PHP and I've been reading several beginner tutorials so please accept my apologies for any stupid questions I may ask along the way.
I've gotten as far as installing XAMPP, set up a database plus PHP form and I'm struggling to figure out how to insert values from an array into my database.
I've learnt the code in one particular way (see beginner tutorials) so I was wondering if you could help me keeping this in mind. I know there'll be a million better ways to do what I'm doing but I fear I will be bamboozled with different code or differently structured code.
Anyway the tutuorials I'm reading don't see to cover how I can insert an array of values into my database, just singular values.
In the attached file, I have 10 rows of 2x text inputs (20 text inputs total). Each row allows the user to enter a CarID and CarTitle. I've commented out the jQuery which validates the inputs so I can build a rudimentary version of this validation with PHP.
I thought that because the line $sql="INSERT INTO carids_cartitles (CarID, CarTitle) VALUES ($id, $title)"; is inside the foreach, means that for each pair of values from the form it'd insert to the database.
It doesn't do this. If I enter two or more CarIDs and CarTitles, only one pair of values gets saved to the database.
I'm sorry if I haven't explained this well enough, any questions please let me know.
Many thanks for your help in advance.
Attached Files
form.php 4.43KB
5 downloads Here we go, I need to use a query where it uses a posted time value to compare if there are the same times on the posted date value. I want it so the user cant book the same time on the same day as someone before bascially. My input so far is this Code: [Select] <?php ob_start();?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Conforming XHTML 1.0 Strict Template</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link type="text/css" href="ui-lightness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" /> <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script> </head> <body> <form name="input" action="input.php" method="post"> Subject: <input type="text" name="subject" /> First Name: <input type="text" name="firstname" /> Surname: <input type="text" name="surname" /> Trainer: <input type="text" name="trainer" /> Email: <input type="text" name="email" /> Date: <input type="text" name="event_date" id="date" /> Time: <input type="text" name="event_time" id="time" /> <input type="submit" value="Submit" name="submit" /> </form> <script type="text/javascript"> $('#date').datepicker(); $('#time').timepicker({}); </script> <?php include_once("functions/database.php"); include_once("functions/number.php"); if (isset($_POST["submit"])) { echo $_POST['event_date']; echo mdy2mysql($_POST['event_date']); echo $_POST['event_time']; echo time2mysql($_POST['event_time']); $queryselect = "SELECT * FROM events LIKE '".$_POST['event_time']."'"; if ($queryselect == true) { echo "sorry this time is already booked"; } else { $query = "INSERT INTO events (subject, firstname, surname, trainer, email, event_date, event_time, status) VALUES('".$_POST["subject"]."', '".$_POST["firstname"]."', '".$_POST["surname"]."','".$_POST["trainer"]."','".$_POST["email"]."' ,'".mdy2mysql($_POST['event_date'])."','".time2mysql($_POST['event_time'])."', 'pending' ) "; $result = mysql_query($query, $db_link) or die(mysql_error().'cannot get results!'); header("Location: input.php"); } ?> can anyone help me ? very much appreciated. Hey there... I'm so stuck on this problem I was hoping someone could help... I need to query a MySQL Database using array values... Here is my array ... $query_keywords = Array ( [7] => business [10] => home [11] => depo ) Here is my php ...$query = "SELECT * FROM product WHERE product_name, product_comment IN ($query_keywords)"; $result=mysql_query($query); if(mysql_num_rows($result) > 0) { echo "results"; } else { echo "no results"; } Unfortunately, I get this ... Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in blah\blah\results.php on line 99 Please help me All comments greatly appreciated... i have a dictionary - THIS IS obviously a python dictionary an this has approx 8 000 lines with records [/CODE] $ python printer.py {'url': 'http://www.site1_com' 'cname': 'butcher', 'name': 'cheng', 'email': 'mail1@hotmail.com'} {'url': 'http://www.site2_com' 'cname': 'dilbert', 'name': 'James', 'email': 'mail2@hotmail.com'} [code=auto:0]i have a mysql-db up and runing in my opensuse there i have created a db with the fields url cname name i use the import MySQLdb i studied this documentation he http://stackoverflow...abase-in-python but i think this goes a bit over my head. - well how can i get the data ( in other words the dictionary) into the database? love to hear from you greetings helllo dear php-commmunity new to Ruby - i need some advices - i plan to do some requests in osm-files. (openstreetmap) Question - how can i store the results on a Database - eg mysql or - (if you prefer postgresql) - note: my favorite db - at least at the moment is mysql here the code require 'open-uri' require "net/http" require 'rexml/document' def query_overpass(object_type, left,bottom,right,top, key, value) base_url = "http://www.overpass-api.de/api/xapi?" query_string = "#{object_type}[bbox=#{left},#{bottom},#{right},#{top}][#{key}=#{value}]" url = "#{base_url}#{URI.encode(query_string)}" resp = Net::HTTP.get_response(URI.parse(url)) data = resp.body return data end overpass_result = REXML::Document.new(query_overpass("node", 7.1,51.2,7.2,51.3,"amenity","restaurant|pub|ice_cream|food_court|fast_food|cafe|biergarten|bar|bakery|steak|pasta|pizza|sushi|asia|nightclub")) overpass_result.elements.each('osm/node') {|x| if !x.elements["tag[@k='name']"].nil? print x.elements["tag[@k='name']"].attributes["v"] end print " | " if !x.elements["tag[@k='addr:postcode']"].nil? print x.elements["tag[@k='addr:postcode']"].attributes["v"] print ", " end if !x.elements["tag[@k='addr:city']"].nil? print x.elements["tag[@k='addr:city']"].attributes["v"] print ", " end if !x.elements["tag[@k='addr:street']"].nil? print x.elements["tag[@k='addr:street']"].attributes["v"] print ", " end if !x.elements["tag[@k='addr:housenumber']"].nil? print x.elements["tag[@k='addr:housenumber']"].attributes["v"] end print " | " print x.attributes["lat"] print " | " print x.attributes["lon"] print " | " if !x.elements["tag[@k='website']"].nil? print x.elements["tag[@k='website']"].attributes["v"] end print " | " if !x.elements["tag[@k='amenity']"].nil? print x.elements["tag[@k='amenity']"].attributes["v"] print " | " end puts } look forward to hear from you again - i would love to store it on a mysql - database - if possible. If you would prefer postgresql - then i would takte this one.... ;-) look forward to hear from you again - i would love to store it on a mysql - database - if possible. If you would prefer postgresql - then i would takte this one.... ;-) well - i guess that the answer to this will be the same no matter what language we are using. If the db is a sql database we need to design the database schema and create the tables in the database. The first step in accessing a db in our code is to get a connection to it. If ruby is our choice of language, a search for "ruby sql connector" will give us lots of options to read about. Well - we also can do it in PHP. What do you think!? Next, based on the schema we have designed, we need to create queries suitable for storing the data. We will likely need to consider our transactional model. Again, searching "ruby sql transactional model" will give us plenty of food for thought. Finally, we may want or need to close the connection to the database. Hello everyone I need code for this question
would you help me please..?
Am a newbie in php. Since I can't insert values to the database with respect to a user Id or with any other token using WHERE clause. I.e "INSERT INTO receipts(date) VALUES(example) where id="**....." If I need to fetch several values of column for a particular user, how do I go about it? Thank you!!! I made a loop in order to display a html table where a user can choose various items. In this table there are several Items, each item has it's own checkbox. each checkbox value is unique and stored in the Users_and_items mysql table (UserID, Item_ID, Item_Fullname, Item_Picture are the columns) If a user chooses an item, then it's UserID and the Item_ID get stored in a preferences mysql table (User_ID, Item_ID are the 2 columns) Everything runs fine but I would like to repopulate the checkboxes now. I thought about a solution which I need to integrate in the loop to make this happen: Code: [Select] <?php include 'connector.php'; echo "<form action='processor.php' method='post'>"; echo "<table>"; //loop to create AvailableItems html Table , each Item gets listed with it's unique Item_ID $query1 = "SELECT UserID, Item_ID, Item_Fullname, Item_Picture FROM Users_and_items"; $result1 = @mysql_query($query1); $num=mysql_numrows($result1); $i=0; while ($i < $num) { //creates a new table row after 3 items displayed if($i>0 && ($i%3==0)) { echo "<tr>"; } //gets all the table data for the loop sequentially from mysql row by row $UserID=mysql_result ($result1,$i,"UserID"); $Item_ID=mysql_result ($result1,$i,"Item_ID"); $Item_Fullname=mysql_result ($result1,$i,"Item_Fullname"); $Item_Picture=mysql_result ($result1,$i,"Item_Picture"); // ### NEW CODE INSERTION POINT - SEE OTHER CODEBOX IN THIS FORUM POST ### echo " <td> <input type='checkbox' name='selecteditems[]' value='$Item_ID' id='$Item_ID' /> <img src='$Item_Picture'><br> $Item_Fullname </td> "; $i++; //creates a new table row after 3 items displayed if($i>0 && ($i%3==0)) { echo "</tr>"; } } echo "</table>"; echo " <input type='hidden' name='PRIMARYID' value='$UserID' /> <input type='submit' name='formSubmit' value='OK' /> </form> "; ?> Code: [Select] // POSSIBLE SOLUTION, I think that it would run fine but I am a mysql beginner and don't know how to code it completely! // ### THIS CODE MUST BE INSERTED IN THE LOOP (the insertion point is specified in the other codebox): $query_repopulate_chkboxes = "SELECT Item_ID FROM preferences WHERE UserID=$UserID"; // we get all the past user preferences $result_repopulate_chkboxes = @mysql_query($query_repopulate_chkboxes); // we store the preferences in a variable if $Item_ID of the html table that is being created by the php loop is contained in $result_repopulate_chkboxes (which is the list of all the past user's chosen items) then echo the function with the checkbox input checked='checked' ELSE output the normal echo (which leaves the checkbox unchecked). While I think that this is a feasible solution, I am having difficulties to code this section and implement it in the loop since I am a beginner with php. Any help is appreciated! Hello, I've been stuck on this code for nearly 3 days and i still am not able to understand this too well. The PHP manual says "Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it." Right , so from what i understand from that,if i want to modify an array inside a foreach , i need to reference the array. This example was given in the PHP manual to demonstrate this reference requirement <?php $arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; } // $arr is now array(2, 4, 6, 8) unset($value); // break the reference with the last element ?> But, when i try this code : <?php $array = array('Ibanez'); foreach ($array as $guitar) { $array['guitar'] = $array[0]; unset($array[0]); $array['guitar'] = 'Gibson'; } print_r($array); ?> The output of the array outside the foreach shows the changed array and not the original anymore. So doesn't this mean that the foreach CAN indeed operate on the array itself without the array being referenced? The reason i'm stuck with this code is that i'm trying to use another slightly bigger array which needs to have its keys modified within the foreach statement, but the changes refuse to leave the foreach loop. But when i tested this small piece of code above, changes are indeed getting reflected without any reference. I'm really confused now about how this works. Help is greatly appreciated Hi all, I'm brand new to php / mysql and I'm trying to modify this script which currently runs a search on two fields "product_number" and "product_name". I also want the search to consider a third field "product_type". When I remove either product_name or product number from the following part of the code, it removes that field from being considered in the search: Code: [Select] $search_map = array($orderby, 'product_number','product_name',); So shouldn't I be able to just add the third field's name to this array and have it be considered too? I'm a complete beginner so I'm hoping this is a simple fix and I just dont get it. Here's the rest of what I think is the relevant code: Code: [Select] function load_all_products() { global $AppUI; global $sorted_item_list; global $additional_pfilter; load_type_list(); $orderby = 'product_id'; $search_map = array($orderby, 'product_number','product_name',); $where = $AppUI->getState( 'QuoteIdxWhere' ) ? $AppUI->getState( 'QuoteIdxWhere' ) : '*'; $not =" "; $op = " OR"; $check = substr(trim($where),0,4); if(stristr($check,"NOT")){ $op ="AND"; $not = " NOT "; $where = substr(trim($where),4); $where = trim($where); } // assemble the sql statement $q = new DBQuery; $q->addTable('products'); $q->addJoin('companies', 'com', 'products.product_company_id = com.company_id'); $q->addJoin('users', 'u', 'products.product_owner = u.user_id'); $q->addQuery('products.*, com.company_name, u.user_username'); $where_filter = " "; foreach($search_map as $search_name) $where_filter .=" $op $search_name $not REGEXP '$where'"; $where_filter = substr($where_filter, 5); // echo $where_filter; if($where != "*") $q->addWhere("($where_filter)"); $q->addOrder('product_id'); $sql = $q->prepare(); $q->clear(); $sql_list = db_exec( $sql ); if ($sql_list) $rn = db_num_rows( $sql_list ); else { echo db_error(); $rn = 0; } $product_list = array(); foreach ($sql_list as $item) { $product_list[ $item[ 'product_id' ] ] = $item; } // sort the list global $sort_state; if ( !isset( $sort_state ) ) $sort_state = getProductSortState(); if ( isset( $sort_state[ 'sort_item1' ] ) ) { if ( isset( $sort_state[ 'sort_item2' ] ) ) { $sorted_item_list = array_csort2( $product_list, $sort_state['sort_item1'], intval( $sort_state['sort_order1'] ) , $sort_state[ 'sort_item2' ], intval( $sort_state['sort_order2'] ) ); } else { $sorted_item_list = array_csort2( $product_list, $sort_state['sort_item1'], intval($sort_state['sort_order1']) ); } } else $sorted_item_list = array_csort2( $product_list, 'product_id' ); } Thanks! i'm creating a ticketing system and i need some assistance. The code directly below displays the database records and the delete works fine. The edit however isn't picking the values in the various fields.
<?Php require "config.php"; $page_name="currentout.php"; $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 10; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; $nume = $dbo->query("select count(id) from receipt")->fetchColumn(); echo "<TABLE class='t1'>"; echo "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>"; $query=" SELECT * FROM receipt limit $eu, $limit "; foreach ($dbo->query($query) as $row) { @$m=$i%2; @$i=$i+1; echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$row[id]'>delete</a></td><td><a href='edit.php?id=$row[id]'>Edit</a></td></tr>"; } echo "</table>"; if($nume > $limit ){ echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; if($back >=0) { print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} $l=$l+1; } echo "</td><td align='right' width='30%'>"; if($this1 < $nume) { print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; } ?>The code below is edit.php. It's supposed to display the various fields when clicked to allow for editing but it isn't picking any field, PLEASE assist. <?Php require "config.php"; $sql = "SELECT FROM receipt WHERE ID= :ID"; $stmt = $dbo->prepare($sql); $stmt->bindParam(':ID', $_GET['id'], PDO::PARAM_INT); $stmt->execute(); ?> <form action="update.php" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td> <label><strong>Full Names</strong></label></td> <td> <input type='text' name='name' value=" <?php echo $row['name']; ?>" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td> </tr> <tr> <td><label><strong>ID/Passport No. </strong></label></td> <td> <input type="text" name="pass" value="<?php echo $row['id_passno']; ?> " /><br /></td> </tr> <tr> <td> <label><strong>Phone No. </strong></label></td> <td><input type="text" name="phone" value="<?php echo $row['phone_num']; ?>" /> <br /></td> </tr> <tr> <td> <label><strong>Amount (KShs.) </strong></label></td> <td><input type="text" name="amount" value="<?php echo $row['Amount']; ?> "/> <br /></td> </tr> <tr> <td> <input type="reset" name="Reset" value="CANCEL" onClick="return confirm('Discard changes?');" /> <br></td> <td> <input type="submit" name="Submit2" value="SUBMIT" /> </td> </tr> </table> </form> i'm creating a ticketing system and i need some assistance. The code directly below displays the database records and the delete works fine. The edit however isn't picking the values in the various fields.
<?Php require "config.php"; $page_name="currentout.php"; $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 10; $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; $nume = $dbo->query("select count(id) from receipt")->fetchColumn(); echo "<TABLE class='t1'>"; echo "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>"; $query=" SELECT * FROM receipt limit $eu, $limit "; foreach ($dbo->query($query) as $row) { @$m=$i%2; @$i=$i+1; echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$row[id]'>delete</a></td><td><a href='edit.php?id=$row[id]'>Edit</a></td></tr>"; } echo "</table>"; if($nume > $limit ){ echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; if($back >=0) { print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} $l=$l+1; } echo "</td><td align='right' width='30%'>"; if($this1 < $nume) { print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>"; } ?>The code below is edit.php. It's supposed to display the various fields when clicked to allow for editing but it isn't picking any field, PLEASE assist. <?Php require "config.php"; $sql = "SELECT FROM receipt WHERE ID= :ID"; $stmt = $dbo->prepare($sql); $stmt->bindParam(':ID', $_GET['id'], PDO::PARAM_INT); $stmt->execute(); ?> <form action="update.php" method="post" enctype="multipart/form-data"> <table align="center"> <tr> <td> <label><strong>Full Names</strong></label></td> <td> <input type='text' name='name' value=" <?php echo $row['name']; ?>" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <br /></td> </tr> <tr> <td><label><strong>ID/Passport No. </strong></label></td> <td> <input type="text" name="pass" value="<?php echo $row['id_passno']; ?> " /><br /></td> </tr> <tr> <td> <label><strong>Phone No. </strong></label></td> <td><input type="text" name="phone" value="<?php echo $row['phone_num']; ?>" /> <br /></td> </tr> <tr> <td> <label><strong>Amount (KShs.) </strong></label></td> <td><input type="text" name="amount" value="<?php echo $row['Amount']; ?> "/> <br /></td> </tr> <tr> <td> <input type="reset" name="Reset" value="CANCEL" onClick="return confirm('Discard changes?');" /> <br></td> <td> <input type="submit" name="Submit2" value="SUBMIT" /> </td> </tr> </table> </form> The Script:
<?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/header.php"); ?> <?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/connect.php"); ?> <?php if(isset($_GET['thread_id'])) { $tqs = "SELECT * FROM `thread` WHERE `id` = '" . $_GET['thread_id'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $row = mysqli_fetch_assoc($tqr); ?> <div class="div"> <h1>Admin Modify</h1> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="title" value="<?php echo $row['title']; ?>"/><br/> <textarea type="text" name="caption"><?php echo $row['caption']; ?></textarea> <input type="submit" name="admin_update" value="Update" /> </form> </div> <?php // This prints e.g.: // 47 echo "The Thread ID: "; echo $_GET['thread_id']; if(isset($_POST['admin_update'])){ $tqs = "UPDATE `thread` SET `title` = '" . $_POST['title'] . "', `caption` = '" . $_POST['caption'] . "' WHERE `id` = '" . $_GET['thread_id'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } } ?> <?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/footer.php"); ?>I do not see why this is not working. The "UPDATE" SQL statement has worked without the "WHERE" part and modified all of the posts. (With this the database connection works too.) Though, this statement does work in PhpMyAdmin: UPDATE `thread` SET `title` = 'testing', `caption` = 'testing' WHERE `id` = '47';I added the "WHERE" part to the script and now it is not modifying the text in the table anymore, basically the "updates" do not happen. What could be the issue here? Any suggestions are much appreciated. Also, I have used this way of "syntax style" in PHP, perhaps somebody could be modifying the "UPDATE" SQL statement into a different syntax style so I can try it out, I would much appreciate it. I would also like to ask how the "syntax style" I have used is and if it can be better than this? Edited by glassfish, 20 October 2014 - 05:52 AM. Hi am in processes of making a bespoke CMS for a project in uni am having a problem with my scrip basically i have three php files i have content which echos out the database tables i wish to edit with a link to an update_content page when u click on that it bring u too update_content.php which allows the user to modifier the content in the tables but when i hit update am getting a Parse error: syntax error, unexpected T_IF in line 4 of my update_ac file any help would be great cheers richie <?php require("includes/connection.php") // If form button has been pressed then do the following if(isset($_POST['update'])){ // Get id of post $id = $_GET['id']; $header = $_POST['header']; $content = $_POST['content']; // Update database table $query = "UPDATE pages SET header = '$header', content = '$content' WHERE id = '$id'"; $result = mysql_query($query); if ($result){ echo "Successfully edited entry"; } else { echo "There was error editing entry"; } } ?> Hi, I have a webpage that the super administrator log's into. Once the super administrator is logged in he/she can view his/her clients. The super admins clients also have their own clients, once the super admins clients login they can view their own clients details who register with them. What i am trying to do is have a link on that clients name (for the super admins clients) that will bring me to a new page where i can edit his/her details that is stored in the mysql database. I have used INPUT buttons for each clients row in a FORM which works......but i know this is not the right way to do it. This is the code i have used to display the clients with the input button: <?php $query = "SELECT ID FROM clients WHERE username = '$username'"; $result = mysql_query($query); if(mysql_num_rows($result)) { while($row = mysql_fetch_assoc($result)){ $userID = $row['ID']; $query = "SELECT * FROM users WHERE userID = '$userID'"; $result = mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="3" cellpadding="3" width="100%"> <tr> <th width="30%"><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Username</font></th> <th><font face="Arial, Helvetica, sans-serif">Email Address</font></th> <th> </th> </tr> <?php $i=0; while ($i < $num) { $userID=mysql_result($result,$i,"userID"); $name=mysql_result($result,$i,"name"); $username=mysql_result($result,$i,"username"); $email=mysql_result($result,$i,"email"); ?> <tr> <td width="30%"><?php echo $name; ?></td> <td><?php echo $username; ?></td> <td><?php echo $email; ?></td> <td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;"> <input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="View Info" class="button" /></form></td> </tr> <?php $i++; }}} ?> </table> From the above code when i use the following code: ?userID=<?php echo $userID; ?>&name=<?php echo $name; ?> It doesn't make a difference .... it just displays the correct userID and name in the link. Once the INPUT button is clicked it will bring you to this page: <?php $query = "SELECT * FROM users WHERE userID = '".$_POST['selectuser']."' AND username = '".$_POST['username1']."'"; $result = mysql_query($query); if(mysql_num_rows($result)) { $userID = $_POST['selectuser']; while($row = mysql_fetch_assoc($result)){ $name = $row['name']; $userID = $row['userID']; $email = $row['email']; $username = $row['username']; $registered = $row['registered']; $last = $row['last']; ?> <?php echo $brokerID; ?> <table border="0" cellspacing="3" cellpadding="3" width="100%" summary="Client table"> <tr> <td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;"> <input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="Income" class="button" /></form></td> <td><form action="http://localhost/single-client.php?userID=<?php echo $userID; ?>&name=<?php echo $name; ?>" method="post" style="margin:0px;"> <input type="hidden" name="selectuser" id="selectuser" value="<?php echo $userID; ?>" /><input type="hidden" name="username1" id="username1" value="<?php echo $username; ?>" /><input type="hidden" name="name1" id="name1" value="<?php echo $name; ?>" /><input type="submit" name="submit" value="Bills" class="button" /></form></td> </tr> </table> <h2>Client Profile - <?php echo $_POST['name1']; ?></h2> <table border="0" cellspacing="3" cellpadding="3" width="100%"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Username</font></th> <th><font face="Arial, Helvetica, sans-serif">Email Address</font></th> <th><font face="Arial, Helvetica, sans-serif">Registered</font></th> <th><font face="Arial, Helvetica, sans-serif">Last</font></th> </tr> <tr> <td><?php echo $name; ?></td> <td><?php echo $username; ?></td> <td><?php echo $email; ?></td> <td><?php echo $registered; ?></td> <td><?php echo $last; ?></td> </tr> </table> <?php } } else { echo "<p>Error</p>"; } ?> This page displays the correct user info. Is there a way to do it differently instead of using FORMS and INPUT buttons? and rather using links? Any help would be greatly appreciated. Sir/ma'am,
With the script I'm using to run my website, I've been trying to add an additional feature for the users to add/edit. I'll try to provide as much info as I can, hopefully it'll help.
Here is the code I'm using to display the user's unique info from the db.
<a class="wallet-edit"><?php echo $_SESSION['simple_auth']['INFO']?></a>That displays the user's info from the column 'INFO' perfectly. It's also a js popup to a menu to where I'm hoping to add a single textbox to edit the INFO. The script uses a similar function to edit the password with a popup. I've tried modifying the code to edit the INFO column but it doesn't work. Here is the default code it has to edit the password. I'm not sure if it can be changed to edit another column or needs a new piece of code for that. // user edit $('body').on('click', '.username-edit', function() { $('#modal').html(' '); var output = '<div class="modal-content"><h5><?php echo lang::get("Change password")?></h5><hr />'; output += '<h5><?php echo lang::get("New password:")?></h5><input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />'; output += '<h5><?php echo lang::get("Confirm password:")?></h5><input type="password" name="password2" id="password2" value="" class="text ui-widget-content ui-corner-all" />'; output += '</div>'; output += '<div class="modal-buttons right">'; output += '<button id="confirm-button" type="button" class="nice radius button"><?php echo lang::get("Change")?></button>'; output += '</div>'; output += '<a class="close-reveal-modal"></a>'; $('#modal').append(output); $('#second_modal').hide(); $('#modal').reveal(); $('#confirm-button').click(function(){ $('#password').css('border-color', '#CCCCCC'); $('#password2').css('border-color', '#CCCCCC'); var password = $('#password').val(); var password2 = $('#password2').val(); if(typeof(password) === 'undefined' || password == ''){ $('#password').css('border-color', 'red'); return false; } if(password != password2){ $('#password2').css('border-color', 'red'); return false; } password_data = encodeURIComponent(password); $.post("<?php echo gatorconf::get('base_url')?>", { changepassword: password_data} ).done(function(data) { // flush window.location.href = '<?php echo gatorconf::get('base_url')?>'; }); }); });If the code above can be edited to work with what I'm trying to do, it of course only needs one textbox and doesn't have to be confirmed by a second input. Please help! Thanks! Hey everyone. I'm making a php/mysql game and I don't understand how do to this. please read the whole thing and dont just say use paypal. thanks in advanced. The game is free to play but if you want some extra perks like gold and what not I want to you be able to pay with real money to get them. I dont have ANY idea how to do this.... Say there are three parts 100gold 1,000gold 10,000gold $5 $10 $20 Is this possible: use paypal set up three different buttons/links for that then I know paypal asks if you wants to point them to a thankyou page so I would make the thankyou page have the PHP in it to update they database with the new gold values. the problem I see is how will paypal save their member id or user id number so my script in the thankyou page will update the right account and also what is stopping people from just going straight to the thankyou page without paying? Thanks for the info |