Jump to content

DuaneCawaling

Members
  • Posts

    15
  • Joined

  • Last visited

DuaneCawaling's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. now i get it, thanks for that info it helped my others codes alot!
  2. <?php $username = "root"; $password = "vince"; $hostname = "localhost"; $con = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("dummy") or die ("No existing database".mysql_error()); $query = mysql_query("SELECT * from prepurchase"); $row = mysql_fetch_array($query); echo $nrow = mysql_num_rows($query); //=4 while ($row = mysql_fetch_array($query)){ //why does this loop only 3times?? echo $bool = $row['Reply']; echo $id = $row['ID']; $getinfo = mysql_query("SELECT * from profile where studentid = '$id'"); $bal = $getinfo['credit']; $num = $getinfo['contact']; if ($bool == "1") echo "Your order is ready for pickup.<br>"; else if ($bool == "2") echo "Sorry, your order cound not be processed.<br> Your credit is refunded. Remaining credit: $bal.<br>"; } ?> i counted the array, it has 4 items in it..why does it loop only 3 times?? awaw1.bmp
  3. i did not think of that..sorry for that..anyways thank you for the advice it works perfectly fine now
  4. the $str is a string. in_array() needs an array as a parameter. to make the string an array.str_split is used. a problem occurs because the string's parameters 'register|bal|menu|snacks|drinks|buy|pass' are not equal in length.str_split arrays with equal length
  5. $str= "WAL bal"; $message = explode(" ",$word); if(preg_match('/(register|bal|menu|snacks|drinks|buy|pass)/', $str)){ if($message[1]){ echo "KEYWORD--OK <br>"; return $str; }else echo "Invalid keyword, try again."; this works okay, the only problem is that if $str = WAL balance, it is still strue coz it has "bal" and i dont want that to happen.. what can i do to limit the $message[1] as such register|bal|menu|snacks|drinks|buy|pass ONLY??
  6. im sorry for the wrong use of section. i would post the working codes after. thank you and i apologize for the inconvenience
  7. <?php echo ('Type <strong>ADZU</strong>[space]<strong>UEW</strong>[space]<em>keyword</em>*')."<br />"; echo "<em>KEYWORDS</em>:"."<br />". "<strong>register</strong>[space]<em>password</em>"."<br>" ."<strong>bal</strong>"."<br />"."<strong>menu</strong>"."<br />"."<strong>drinks</strong>"."<br />" ."<strong>snacks</strong>"."<br />"."<strong>buy</strong>[space]<em>qty-item_keyword</em> ex: ADZU UEW buy 1-M1"."<br />" ."<strong>pass</strong>[space]<em>password</em>"."<br />"; ?> <form action="keyword.php" method="post"> Message: <input type="text" name="message"> Contact no.: <input type="text" name="number"> <input type="submit"> </form> this is the code for asking message and mumber <?php $str_full = "$_POST[message]"; //full message $number = "$_POST[number]"; //contact number $message = explode(" ",$str_full); $str_keyword = strtolower($message[2]); //----->message [2] echo iskeyword($str_full,$str_keyword); function iskeyword($word,$dummy){ if($dummy == "register"){ $msg = substr($word,17); $msg1 = str_replace(' ','',$msg); return $msg1; }else if($dummy == "bal"){ $msg = substr($word,12); $msg1 = str_replace(' ','',$msg); return $msg1; } if($dummy == "buy"){ $msg = substr($word,12); $msg1 = str_replace(' ','',$msg); return $msg1; } } ?> this is the part im checking for errors in some keywords, im still in the process of finishing the codes
  8. Type SMART[space]WALLET[space]keyword* KEYWORDS: register[space]password bal menu drinks snacks buy[space]qty-item_keyword ex: ADZU WALLETbuy 1-M1,1-M2,3-S1 pass[space]password ex: ADZU WALLET pass 12345 i want to check all the errors that may occur in the scenario of inputing the different keywords. for example: ADZU WALLET pass in this string, the error would be that there is no password ..a message should be shown to the user that it is an error please help me check every possible error and scenario
  9. i wanna compute their total. the items' information is in a database. and by parsing them as such i can now get each of their prices and add them. but i dont know on what should i code first.
  10. thank you for the advice, i've followed the tips above. the next concern now is accesing 3 different database. lets say A,B,D are present in three different databases. and i want to retrieve their corresponding prices and total them. what would be the fates and efficient way?am i going to code 3 different mysql_query's?
  11. hi, my group is developing an sms feture. in this feature a certain sms message should be messaged by the user/subscriber. one of the sub-feature is ordering. a certain text patter should be followed: SMART<space>WAL<space>BUY<space>"order" example: SMART WAL BUY 2-A,1-B,3-D in 2-A, whew 2 is the quantity and A is the item tag what would be the best solution to use the explode(); function? first is, there are other keywords used like "BAL" or "MENU" other than "BUY". second after the "BUY" keyword, i would like to use the "-" as a delimiter to separate the quantity and item tag. please share your knowledge on the topic comments and suggestions are ALWAYS welcome
  12. thanks for the replies. i was thinking so hard what was my problem..it was just the wrong use of or sign..thank you again, really now!a function for making strings to lower case..that will make things more easy
  13. $username = "root"; $password = "duane"; $hostname = "localhost"; $con = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; $selected = mysql_select_db("dummy") or die ("No existing database".mysql_error()); $number = "$_POST[number]"; $keyword = $message[2]; if($keyword == "balance"||"BALANCE"){ $reply = mysql_query("SELECT * from profile where contact = '$number'"); $info = mysql_fetch_array($reply); echo "Your remaining balance is: ".$info['credit']."<br />"; }else if ($keyword == "menu"||"MENU") { $data = mysql_query("SELECT * from food") or die (mysql_error()); while ($row = mysql_fetch_array($data)) { echo "<strong>Item(</strong>".$row{'menu_tag'}."<strong>):</strong> ".$row{'item'} ." --<em>price</em>:".$row{'price'}."<br>";//display the results } }else if ($keyword == "snacks"||"SNACKS") { $data = mysql_query("SELECT * from inventory") or die (mysql_error()); while ($row = mysql_fetch_array($data)) { echo "<strong>Item(</strong>".$row{'tag'}."<strong>):</strong> ".$row{'item'} ." --<em>price</em>:".$row{'price'}."<br>";//display the results } } there are no syntax errors. my problem is that it keeps on entering the FIRST if statement even if the $keyword is not "balance" @@
  14. $con=mysql_connect("localhost","root","duane"); // Check connection if(!$con){ echo ("Could not connect." .mysql_error()); } echo ("Connected successfully"); $selected = mysql_select_db("dummy") or die ("No existing database".mysql_error()); $result = mysql_query("INSERT INTO prepurchase(ID, Sum, Reply, items, time) VALUES('080390',20,1,'2m3','9:46')") or die(mysql_error()); $data = mysql_query("SELECT * from prepurchase") or die (mysql_error()); while ($row = mysql_fetch_array($data)) { echo "ID: ".$row['ID']." Sum: ".$row['Sum']." Items: ".$row['items']." ";//display the results } mysql_close($con); i'm sorry about the way i posted the codes, i was in a rush it works!changed the mysql_query parameters.. THANK YOU for the kind reply hoping to hear from you more coz i know his will not be the first time i'll ask questions about php
  15. i'm a newbie at PHP prodramming and i want to add data to an existing data base, but unfortunately, the " Warning: mysql_query() expects parameter 2 to be resource, "always pops up @@ here are my codes <?php $con=mysql_connect("localhost","root","duane"); // Check connection if(!$con){ echo ("Could not connect." .mysql_error()); } echo ("Connected successfully"); $selected = mysql_select_db("dummy") or die ("No existing database".mysql_error()); mysql_query($selected,"INSERT INTO prepurchase (ID, Sum, Reply, items, time) VALUES ('080392',15,1,'2m2','5:46'')") or die(mysql_error()); mysql_query($selected,"INSERT INTO prepurchase (ID, Sum, Reply, items, time) VALUES ('080390',20,1,'2m3','9:46'')") or die(mysql_error()); $data = mysql_query($selected, "SELECT * from prepurchase") or die (mysql_error()); while ($row = mysql_fetch_array($data)) { echo "FN: ".$row{'Firstname'}." LN: ".$row{'Lastname'}." Age: ".$row{'Age'}."<br>";//display the results } mysql_close($con); ?> the italic and bold codes are the error..please enlighten me with your knowledge. attached is the database i'm planning to modify using ph
×
×
  • Create New...

Important Information

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