PHP - This Little Piece Of Code Is Givin' Me Fits!
I am past a beginner in php but no where near an expert and I need some help. This piece of code he
$query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); is part of my search results page with paged indexes (next, previous 10, etc.). However with this code i get the die message but if i take the first line off ($query), the page executes but then the page doesn't operate correctly i.e. shows 15 results when the $limit(limit for rows) =10. Is it not written correctly or am I missing somethingwith the top line? if the entire script is needed let me know and i will paste it? Thanks in advance for any help! Similar TutorialsI have the below code: Code: [Select] $buttons = "button+='<table height=\"40\" border=\"0\"id=\"table1\"cellspacing=\"0\"cellpadding=\"2\"><tr><td>---PLACE CODE HERE---</td><td valign=\"bottom\">';\n"; between the to cell tags (<td>---PLACE CODE HERE---</td>) I need to add this code: Code: [Select] document.getElementById('com').innerHTML=<?php echo $gSurfMultiLoadedText; ?>+button2; My problem is the '; " and \" stuff Anyone care to show how I can merge these pieces? Helo dear people, I need some help with piece of code that generates XML This all works as is: Code: [Select] include(dirname(__FILE__).'/config/config.inc.php'); require_once(dirname(__FILE__).'/init.php'); error_reporting(0); $p=Product::getProducts(7, 0, 0, 'id_product', 'desc', false); $products=Product::getProductsProperties(7, $p); header("Content-Type: text/xml\n\n"); //print "Content-type: text/html\n\n"; echo '<?xml version="1.0" encoding="utf-8"?> <Catalog>'; foreach ($products as $row) { if ($row['active']){ $img=Product::getCover($row['id_product']); echo ' <products> <code>'.str_replace("&", "&", $row['id_product']).'</code> <name>'.str_replace("&", "&", $row['name']).'</name> <descr>'.str_replace("&", "and", strip_tags($row['description_short'])).'</descr> <price>'.($row['price']*1).'</price> <quantity>'.str_replace("&", "&", $row['quantity']).'</quantity> <categ>'.str_replace("&", "&", $row['category']).'</categ> <link>http://www.xxxxx.hr'.$row['link'].'</link> <img>http://www.xxxxx.hr/xxxxx/'.$shopUrl.'img/p/'.$row['id_product'].'-'.$img['id_image'].'.jpg</img> </products>'; } } echo '</Catalog>'; ?>code] :shrug: But now i need to hide quantity if its larger that 5 pieces. So that all quantity that is >= equal or larger of 5 si shown in XML as 5. Can anyone help me out with this!? :'( BR Vixus
Hi there, i have an code <?php $a = [ 0 => 10, ]; $i = 0; $a[$i++] = $i;
and question "Explain what the problem is and what you could do to fix it"
Please help! I have this little code that I cannot get to work Code: [Select] $sql_buildings = ("SELECT castle, treasury, huts, [b]leader_id[/b] FROM teams WHERE team_id=[b]".$_GET['t']." [/b]"); $rsbuildings = mysql_query($sql_buildings); if($rsbuildings[".$_GET['t']."] == 'leader_id' ){ The problem is this part: Code: [Select] if($rsbuildings[[b]".$_GET['t']."[/b]] == '[b]leader_id[/b]' ){ How can I write it to have these to values work? Code: Code: [Select] <table border='0' style="height:100%;width:570px;border:solid 1px #BBB"> Error: Code: [Select] Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\sources\admin\manage-user.php on line 26 Sorry, im a noob when it comes to coding. please help! My Error Output is this: Warning: Cannot modify header information - headers already sent by (output started at city-search.php:1) in city-search.php on line 65 What I'm I missing in the code, I can't seem to get these. It works excellent in Localhost, but in production. Error above. Code: [Select] <?php // MG CREATED THIS SIMPLE REGISTRATION PHP FOR THAT GOES TO ONE SPECIFIC USER. // WILL TEST FORM REGSITRATION NG 07-2011 //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the name field is not empty if(trim($_POST['name']) == '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure that the subject field is not empty if(trim($_POST['subject']) == '') { $hasError = true; } else { $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) == '') { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } //Check to make sure comments were entered if(trim($_POST['message']) == '') { //$hasError = true; $comments == 'Have No Friends'; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { //$emailTo = 'regina@shushmedeals.com'; //$emailTo = 'reginabyrd32@yahoo.com'; $emailTo = 'mp3@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //$emailBcc = 'info@danjaproduction.com'; //$emailBcc = 'ganja99@netzero.net'; //Put your own email address here $body = "Location: $name \n\nEmail: $email \n\nShushMeDeals Sign-up Info:\n $comments"; // To send HTML mail, the Content-type header must be set $headers = 'From: ShushMeDeals.com City Location sign-up - '.$name.'' . "\r\n" . 'Reply-To: ' . $email . "\r\n" .'Bcc: print@extremeatlanta.com'; //$headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; //$headers .= 'Bcc: info@danjaproduction.com' . "\r\n"; mail($emailTo, $subject, $body, $headers); $emailSent = true; if($emailSent = true) { setcookie("location", $name); //echo '<script type="text/javascript"> // window.location = "index.php?option=com_enmasse&controller=deal&task=today&locationName='.$name.'" // </script>'; } } } ?> Hi, I'm just trying out some basic code and playing around with passing variables by reference and i was reading this on the php manual at this page http://php.net/manual/en/language.references.pass.php : No other expressions should be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid: <?php function foo(&$var) { $var++; } function bar() // Note the missing & { $a = 5; return $a; } foo(bar()); // Produces fatal error since PHP 5.0.5 foo($a = 5); // Expression, not variable foo(5); // Produces fatal error ?> So, i decided to try it out myself like i always do, and i noticed that i'm not getting an error when i do foo(bar()); i.e calling bar() without the & in the function declaration. Infact it works perfectly fine and returns an incremented $a after its passed to foo(). Likewise foo($a = 5); also works great and returns an incremented $a after being passed to foo(). Is this a mistake in the manual or am i missing something? Running PHP 5.3.2-1ubuntu4.5 Hello,
I'm working on a project that requires me to have stock / fake demo files that will be replaced with real files provided by users... I need something to take space and then when people actually start using the site and inputting data, then I can replace each file with new, unique files.
I have some idea of how this would work.
I would need incremented or non-matching identifiers and then a script that probably works on an if statement
like
If new data, take first list of data, delete, replace with new data. Something like that.
Code: [Select] $Rep = htmlspecialchars($_GET["Rep"]); echo $Rep; The above will print "John Doe & Assoc." (without the quotes) Code: [Select] $result = mysql_query("SELECT RepName FROM Reps WHERE Repname = '".$Rep."'"); $repcount = mysql_num_rows($result); echo $repcount; The above code prints "0" If I delete the first block of code and replace it with Code: [Select] $Rep = "John Doe & Assoc." The second block of code will then return a "1" as it should. Why is one returning a 0 and one returning a 1 when the text in $Rep appears to be identical in both cases? This problem only appears to be occurring when the $Rep value contains an &. Hi there, Sorry if this is the wrong forum to post this in, If it is please feel free to move it to the correct one. I have a php page and I am trying to get a couple of lines to only be run if Javascript is disabled on the visitors browsers. Code: [Select] $returnpage = 'myphppage.php'; include('anotherphppage.php'); It is something probably simple but I can't see it... I have tried: Code: [Select] <noscript> <?php $returnpage = 'myphppage.php'; include('anotherphppage.php'); ?> </noscript> but that does not seem to work and I was hoping someone here would have an idea... Many thanks in advance Ross Hi Im sure am missing something very easy on this one can someone help me find it please.. INDEX.HTML Code: [Select] <html> <head> <title>Example form</title> </head> <body> <form name="analysis" id="analysis" action="index3.php" method="POST"> <table width="70%"> <h5><strong>A=agree B=somewhat agree C=neutral D=disagree</strong></h5> <tr> <th align="left">SECTION 1</th> <td align="right">A B  C D </td> </tr> <tr class="question"> <td class="section">Love makes the world go round. <td align="right"> <input type="radio" name="love1" id="sec11" value="0"> <input type="radio" name="love1" id="sec11" value="2"> <input type="radio" name="love1" id="sec11" value="5"> <input type="radio" name="love1" id="sec11" value="10"> </tr> <tr class="question"> <td class="section">What goes around comes around <td align="right"> <input type="radio" name="love2" id="sec12" value="0"> <input type="radio" name="love2" id="sec12" value="2"> <input type="radio" name="love2" id="sec12" value="5"> <input type="radio" name="love2" id="sec12" value="10"> <tr class="question"> <td class="section">Love thy neighbor but dont get caught <td align="right"> <input type="radio" name="love3" id="sec13" value="0"> <input type="radio" name="love3" id="sec13" value="2"> <input type="radio" name="love3" id="sec13" value="5"> <input type="radio" name="love3" id="sec13" value="10"> <tr class="question"> <td class="section">youre a volcano and he/shes a tornado <td align="right"> <input type="radio" name="love4" id="sec14" value="0"> <input type="radio" name="love4" id="sec14" value="2"> <input type="radio" name="love4" id="sec14" value="5"> <input type="radio" name="love4" id="sec14" value="10"> </table> <p> <b> About you: </b> </p> <p> <textarea rows="5" name="addtext" cols="65"></textarea> </p> <div> <input type="submit" id="createcsv" name="createcsv"> </div> </form> </body> </html> INDEX3.PHP <?php // Receiving variables @$pfw_ip= $_SERVER['REMOTE_ADDR']; @$love1 = addslashes($_POST['love1']); @$love2 = addslashes($_POST['love2']); @$love3 = addslashes($_POST['love3']); @$love4 = addslashes($_POST['love4']); @$addtext = addslashes($_POST['addtext']); // Validation //saving record in a text file if ($_POST) { foreach ($_POST as $key => $value) { $_POST[$key] = addslashes($value); } $pfw_file_name = "info.csv"; // Let's store this as an array so we can loop through it $pfw_first_row = array("love1","love2","love3","love4","addtext"); if(!file_exists($pfw_file_name)) { $pfw_is_first_row = true; // If the file doesn't exist, let's create it if (!$fh = fopen($pfw_file_name, "w+")) { die("Cannot create file {$pfw_file_name}"); } else { fclose($fh); } } else { if (!$pfw_handle = fopen($pfw_file_name, 'r')) { die("Cannot open file ($pfw_file_name)"); } // If the file exists, we want to read in its contents else { // Until we reach the end of the file while (!feof($pfw_handle)) { // We'll read in one line at a time and store it in an array $existing_file[] = fgets($pfw_handle, 1024); } if (count($existing_file) == 1) { $pfw_is_first_row = true; } } // We only opened it for reading fclose($pfw_handle); } // Now we're going to open the file for writing if (!$pfw_handle = fopen($pfw_file_name, 'w+')) { die("Cannot open file {$pfw_file_name} for writing"); } else { // We need to write in the labels if ($pfw_is_first_row == true) { // Write the file one line at a time for ($i = 0; $i < count($pfw_first_row); $i++) { // We need to combine the first label and the first row of data $string = $pfw_first_row[$i] . "," . $_POST[$pfw_first_row[$i]] . "\r\n"; fwrite($pfw_handle, $string); } } else { // Same as above, except $existing_file contains labels plus whatever // was already in the file for ($i = 0; $i < count($existing_file); $i++) { $string = rtrim($existing_file[$i], "\r\n") . "," . $_POST[$pfw_first_row[$i]] . "\r\n"; fwrite($pfw_handle, $string); } } fclose($pfw_handle); } } echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>thanx</font></p>"); ?> WHENEVER I WRITE SOMETHING IN THE about you BOX AND CLICK ENTER AND WRITE ONTO A NEW LINE.. THE DATA THAT GETS SAVED IN THE CSV GETS JUMBLED UP have uploaded the files at http://www.bazazu.com/form/ for your reference.. the link to the csv file once generated would be http://www.bazazu.com/form/info.csv please advice Hi guys, I apologize for the number of posts regarding this particular class that I am writing (really, at this point, you've probably done more in it), but I have another issue. I've decided to re-write the pieces that were giving me trouble, and instead of using a for loop, I went to a foreach loop. Here's what it in the database for the particular query: Here's what I get when I dump the array with print_r(): Array ( => Array ( [0] => 4 [id] => 4 [1] => Test [label] => Test [2] => ?r=test [link] => ?r=test [3] => [relation] => [4] => 0 [parent] => 0 [5] => 5 [sort] => 5 [6] => 1 [active] => 1 ) [1] => Array ( => 2 [id] => 2 [1] => About Us [label] => About Us [2] => ?r=about [link] => ?r=about [3] => [relation] => [4] => 0 [parent] => 0 [5] => 10 [sort] => 10 [6] => 0 [active] => 0 ) [2] => Array ( => 3 [id] => 3 [1] => Fleet [label] => Fleet [2] => ?r=about/fleet [link] => ?r=about/fleet [3] => [relation] => [4] => 2 [parent] => 2 [5] => 0 [sort] => 0 [6] => 0 [active] => 0 ) ) And the SQL statement: SELECT * FROM `menu` ORDER BY `parent` ASC, `sort` ASC With the corresponding PHP code (The issue starts in formatMenuItems()): Code: [Select] <?php /** * Menu Class * * This file is used to create a dynamic menu based on the user's permissions and status * @author Max Udaskin <max.udaskin@gmail.com> * @version 1.0 * @package navigation */ /** * @ignore */ if(!defined('ALLOW_ACCESS')) { // Do not allow the file to be accessed by itself die('Restricted File.'); } require_once("Database.php"); class Menu { protected $login; protected $all_rows; protected $menu_items; protected $html = NULL; /** * The constructor * @param Login $login */ function _construct() { } /** * Get All Items * Retrieves all database menu items */ private function getAllItems() { $sql = 'SELECT * FROM `menu` ORDER BY `parent` ASC, `sort` ASC'; $database = new Database('default'); $database->connect(); $database->fetchArray($sql); $query = $database->getLastQuery(); $i = 0; while($row = mysql_fetch_array($query)) { $this->all_rows[$i] = $row; $i++; } print_r($this->all_rows); } /* * Selects the menu items that are appropriate for the user */ private function chooseMenuItems() { $this->menu_items = $this->all_rows; } /** * Formats the menu items for the HTML output */ private function formatMenuItems() { $menu = array(); $menu_imploded = ''; foreach($this->menu_items as $item) { if($item['parent'] == 0) { $menu[] = $this->parseItem($item); } } $menu_imploded = $this->combineMultiArray('', $menu); echo '<div id="menu">'; echo $menu_imploded; echo '</div>'; } /** * Searches an array and it's sub arrays for a defined value ($for) * @param array $array * @param mixed $for */ private function search(array $array, $for) { foreach ($array as $key => $value) { if ($value === $for) { return ($key); } else if (is_array($value)) { $found = $this->search($value, $for); if (is_array($found)) { array_unshift($found, $key); return $found; } } } return false; } /** * Gets the array item and returns it * @param array $arr * @param string $string */ function variableArray($arr, $string) { preg_match_all('/\[([^\]]*)\]/', $string, $arr_matches, PREG_PATTERN_ORDER); $return = $arr; foreach($arr_matches[1] as $dimension) { $return = $return[$dimension]; } return $return; } /** * Parses HTML for the item, as an array * @param array $item */ private function parseItem($item) { if($item['parent'] == 0) { $h2_s = '<h2>'; $h2_e = '</h2>'; } else { $h2_s = ''; $h2_e = ''; } $return[0] = '<ul><li>' . $h2_s . '<a href="'; $return[0] .= $item['link'] . '">'; $return[0] .= $item['label'] . '</a>' . $h2_e; $return[1] = false; // Children $return[2] = '</li></ul>'; $return['parent'] = $item['parent']; return $return; } /** * Puts all of the HTML in the array together */ private function produceHtml() { $this->getAllItems(); $this->chooseMenuItems(); $this->formatMenuItems(); } /** * Get HTML * @return string The HTML menu */ public function getHtml() { $this->produceHtml(); return $this->html; } /** * Combine Multi Array * Takes any array of any dimension and combines it into a single string * @param unknown_type $array */ private function combineMultiArray($glue, $array) { $return = ''; foreach($array as $piece) { if(is_array($piece)) { $return .= $glue . $this->combineMultiArray($glue, $piece); } $return .= $glue . $piece; } return $return; } } Hello, I have a variable that holds a piece of text that looks something like this: "world,blue,big". Is there anyway to split the text into the separate words as an array, and remove the commas? Code: [Select] $text_to_split = "world,blue,big"; $splitArray = array(); //Do some kind of php function that splits text\\ echo splitArray[0]; // world echo splitArray[1]; //blue echo splitArray[2]; //big Would appreciate it, thanks Hi, I am trying to translate a page in PHP using Google API. There is 5000 chars limit on data that you can send to Google at a time. So I am trying to break the page into pieces of 5000 chars. But as you know while doing this we have to keep in mind the HTML formatting that it should not be disturbed otherwise you will not get desired results. For example you have to send this: <a href="#" class="myclass">Link</a> Instead of this: <a href="#" class="myclas I am able to solve it somehow (although not perfectly I guess) by checking if "<" sign is coming after ">" sign or not. If "<" sign is coming after ">" then I go back to the point where I found ">" and cut string from there. Anyway the point is I am still having some problems regarding HTML formatting and want to know how to do it efficiently. Is there any parser available that will solve this problem!? Thanks I’m trying to construct a button that simply writes an "aleph" character into a text area, see below.
My code does not work, can anyone tell me why ? How should I fix it ?
<!DOCTYPE html> <html> <meta charset="UTF-8"> <head> <title>Example</title> <script type="text/javascript"> //JavaScript code goes here function insertAtEnd(text) { var theArea = document.getElementById("thisArea"); theArea.value += '' + text + '';; } </script> </head> <body> <input type="button" id="aleph" name="aleph" value="Write an aleph" onClick="javascript:insertAtEnd(\'<span>א</span>\');return(false)" /> <textarea id="thisArea"> </textarea> </body> </html> Hi, I have some code which displays my blog post in a foreach loop, and I want to add some social sharing code(FB like button, share on Twitter etc.), but the problem is the way I have my code now, creates 3 instances of the sharing buttons, but if you like one post, all three are liked and any thing you do affects all of the blog post. How can I fix this? <?php include ("includes/includes.php"); $blogPosts = GetBlogPosts(); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; echo "<p class='postnote'>" . $post->post . "</p"; echo "<span class='footer'>Posted By: " . $post->author . "</span>"; echo "<span class='footer'>Posted On: " . $post->datePosted . "</span>"; echo "<span class='footer'>Tags: " . $post->tags . "</span>"; echo ' <div class="addthis_toolbox addthis_default_style "> <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a> <a class="addthis_button_tweet"></a> <a class="addthis_counter addthis_pill_style"></a> </div> <script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script> <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=webguync"></script>'; echo "</div>"; } ?> I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. Hi, I need to insert some code into my current form code which will check to see if a username exist and if so will display an echo message. If it does not exist will post the form (assuming everything else is filled in correctly). I have tried some code in a few places but it doesn't work correctly as I get the username message exist no matter what. I think I am inserting the code into the wrong area, so need assistance as to how to incorporate the username check code. $sql="select * from Profile where username = '$username'; $result = mysql_query( $sql, $conn ) or die( "ERR: SQL 1" ); if(mysql_num_rows($result)!=0) { process form } else { echo "That username already exist!"; } the current code of the form <?PHP //session_start(); require_once "formvalidator.php"; $show_form=true; if (!isset($_POST['Submit'])) { $human_number1 = rand(1, 12); $human_number2 = rand(1, 38); $human_answer = $human_number1 + $human_number2; $_SESSION['check_answer'] = $human_answer; } if(isset($_POST['Submit'])) { if (!isset($_SESSION['check_answer'])) { echo "<p>Error: Answer session not set</p>"; } if($_POST['math'] != $_SESSION['check_answer']) { echo "<p>You did not pass the human check.</p>"; exit(); } $validator = new FormValidator(); $validator->addValidation("FirstName","req","Please fill in FirstName"); $validator->addValidation("LastName","req","Please fill in LastName"); $validator->addValidation("UserName","req","Please fill in UserName"); $validator->addValidation("Password","req","Please fill in a Password"); $validator->addValidation("Password2","req","Please re-enter your password"); $validator->addValidation("Password2","eqelmnt=Password","Your passwords do not match!"); $validator->addValidation("email","email","The input for Email should be a valid email value"); $validator->addValidation("email","req","Please fill in Email"); $validator->addValidation("Zip","req","Please fill in your Zip Code"); $validator->addValidation("Security","req","Please fill in your Security Question"); $validator->addValidation("Security2","req","Please fill in your Security Answer"); if($validator->ValidateForm()) { $con = mysql_connect("localhost","uname","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("beatthis_beatthis") or die(mysql_error()); $FirstName=mysql_real_escape_string($_POST['FirstName']); //This value has to be the same as in the HTML form file $LastName=mysql_real_escape_string($_POST['LastName']); //This value has to be the same as in the HTML form file $UserName=mysql_real_escape_string($_POST['UserName']); //This value has to be the same as in the HTML form file $Password= md5($_POST['Password']); //This value has to be the same as in the HTML form file $Password2= md5($_POST['Password2']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $Zip=mysql_real_escape_string($_POST['Zip']); //This value has to be the same as in the HTML form file $Birthday=mysql_real_escape_string($_POST['Birthday']); //This value has to be the same as in the HTML form file $Security=mysql_real_escape_string($_POST['Security']); //This value has to be the same as in the HTML form file $Security2=mysql_real_escape_string($_POST['Security2']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Profile (`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ mail('email@gmail.com','A profile has been submitted!',$FirstName.' has submitted their profile',$body); echo "<h3>Your profile information has been submitted successfully.</h3>"; } mysql_close($con); $show_form=false; } else { echo "<h3 class='ErrorTitle'>Validation Errors:</h3>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p class='errors'>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> hey gurus, i am a newbie php coder.. i am learning by example. what i am trying to do is write a piece of code which will alter 3 tables (user, bonus_credit, bonus_credit_usage) ---------------------------------------------------------------- the table structure that will be used is as follows: user.bonus_credit user.ID bonus_credit.bonusCode bonus_credit.qty bonus_credit.value bonus_credit_usage.bonusCode bonus_credit_usage.usedBy ---------------------------------------------------------------- so lets say, in bonus_credit i have the following bonusCode = 'facebook' (this is the code they have to type to redeem the bonus qty = '10' ( number of times the bonusCode can be redeemed, but same person can't redeem it more than once) value = '5' (this is the amount of bonus_credit for each qty) Now, I need to write a code that check to see if the code has been redeemed in the bonus_credit_usage table and if the user.ID exists in this table as bonus_code_usage.usedBy, then give an error that its already been used and if it hasn't been used, then subtract 1 from qty, add ID to usedBy and then add the value to the bonus_credit ----------------------- i have started the steps just to create a simple textbox and entering a numeric value to bonus_credit, and that works.. but now i have to use JOIN and IF and ELSE.. which is a little too advanced for me.. so i'd appreciate a guide as i write the code. if(isset($_REQUEST['btnBonus'])) { $bonus_credit = addslashes($_REQUEST['bonusCode']); $query = "update user set bonus_credit=bonus_credit+'".$bonus_credit."' where id='".$_SESSION['SESS_USERID']."'"; echo "<script>window.location='myreferrals.php?msgs=2';</script>"; mysql_query($query) or die(mysql_error()); } Advance thank you. Can you help please. The error..... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test_dabase.php on line 24 code. Code: [Select] <?php //database connection. $DB = mysql_connect("localhost","root") or die(mysql_error()); if($DB){ //database name. $DB_NAME="mysql"; //select database and name. $CON=mysql_select_db($DB_NAME,$DB)or die(mysql_error()."\nPlease change database name"); // if connection. }if($CON){ //show tables. $mysql_show="SHOW TABLES"; //select show and show. $mysql_select2="mysql_query(".$mysql_show.") or die(mysql_error())"; } //if allowed to show. if($mysql_select2){ //while it and while($data=mysql_fetch_assoc($mysql_select2)){ //show it. echo $data; } } ?> |