[HELP]Adding Code From Website To Database

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

[HELP]Adding Code From Website To Database

Postby rave on Wed Dec 12, 2012 11:12 pm

Hi,

I Hope Someone Can Help Me Please?
I Would Like To Know If How Can I Code This Option

Website>Page That Put Values Like

Username:
Code:
Check box ( are you sure with your code? )
Submit

After Submit The Code I Put Will Be On My Navicat

Website>Page....>Code Added To Database

Anyone Can Help? I Tried The add_dpts.php But It Doesnt Work
rave
Clown
Clown
 
Posts: 459
Joined: Thu Dec 10, 2009 1:07 pm

Re: [HELP]Adding Code From Website To Database

Postby Ultra on Thu Dec 13, 2012 12:58 am

Ahmm maybe you mean
want to update rose database from the website right ?
or you`re asking that cause your add_dtps script dont work?

1)

I dont know exactly what you need ...
I will create something like tutorial ..
For example i will use level_change script and create my own exp_change script :)
<?php
/*
Dynasty CMS EXP_change script by Ultra
*/
if(!session_is_registered(Admin)) {
die('Access Denied');
}
?>
Here we will allow only administrators to change the HP of the players .

The Level_Change Script Form:

  1. <form id="form1" name="form1" method="post" action="?op=level_change">
  2. <table width="275" border="0" align="center">
  3.   <tr>
  4.     <td width="98">Character Name: </td>
  5.     <td width="167"><label>
  6.       <input type="text" name="textfield1">
  7.     </label></td>
  8.   </tr>
  9.   <tr>
  10.     <td width="98">Desired Level: </td>
  11.     <td width="167"><label>
  12.       <input type="text" name="textfield2">
  13.     </label></td>
  14.   </tr>
  15.   <tr>
  16.     <td>Are you sure? </td>
  17.     <td><label>
  18.       <input name="sure" type="checkbox" id="sure" value="checkbox">
  19.     </label></td>
  20.   </tr>
  21. </table>
  22.  
  23. <p align="center">
  24.   <input name="submit" type="submit" id="submit" />
  25.   <br />
  26.   <br />
  27. <?php


Here is the EXP Changing Script :

  1. ?>
  2. <form id="form1" name="form1" method="post" action="?op=exp_change">
  3. <table width="275" border="0" align="center">
  4.   <tr>
  5.     <td width="98">Character Name: </td>
  6.     <td width="167"><label>
  7.       <input type="text" name="textfield1">
  8.     </label></td>
  9.   </tr>
  10.   <tr>
  11.     <td width="98">Desired EXP: </td>
  12.     <td width="167"><label>
  13.       <input type="text" name="textfield2">
  14.     </label></td>
  15.   </tr>
  16.   <tr>
  17.     <td>Are you sure? </td>
  18.     <td><label>
  19.       <input name="sure" type="checkbox" id="sure" value="checkbox">
  20.     </label></td>
  21.   </tr>
  22. </table>
  23.  
  24. <p align="center">
  25.   <input name="submit" type="submit" id="submit" />
  26.   <br />
  27.   <br />
  28. <?php


[Also thats not important at all cause here you edit only the form..]

Level Change :
  1. <?php
  2. if(isset($_POST['sure'])) {
  3. mysql_query("UPDATE characters SET level = '".$_POST['textfield2']."' WHERE char_name = '".$_POST['textfield1']."'");
  4. echo 'Level changed successfully.';
  5. } else {
  6. echo 'If you want to change the level, then click the box!';
  7. }
  8. ?></p>


EXP Change :
  1. <?php
  2. if(isset($_POST['sure'])) {
  3. mysql_query("UPDATE characters SET exp = '".$_POST['textfield2']."' WHERE [color=#FF0000]char_name[/color] = '".$_POST['textfield1']."'");
  4. echo 'EXP changed successfully.';
  5. } else {
  6. echo 'If you want to change the level, then click the box!';
  7. }
  8. ?></p>

--------------


2) Are you sure that you have configure the mysql connection?
Cause for me works allright... or maybe its a bug from the new rev ( I dont know cause im not using it.... )

Hope it helps....
Ultra
Rackie
Rackie
 
Posts: 226
Joined: Thu Jul 22, 2010 6:31 pm
Location: Usa

Re: [HELP]Adding Code From Website To Database

Postby Mark on Fri Dec 14, 2012 12:14 pm

You forgot the most basic thing the MySql DB connection, tut tuts lol...

Although, he might not need one if he's using DynCMS.. oh btw I've finished the Storage script I just need to find a way to echo non-existant data from an sql table ( i.e if there isn't a line 18 then echo this image ) cuz atm, data is only showed for items that are in the storage table ( obviously ) but I want it to show a blank box for data that doesn't exist ( yet ).

I'll give you a sneek peek below:
  1.  
  2. // Storage Script, Bought to you by TeamFox //
  3. <?php
  4. if(!session_is_registered(User_Name)) {
  5. die('You must log in to access your storage!');
  6. }
  7.  
  8. if(!session_is_registered(User_Pass)) {
  9. die('You must log in to access your storage!');
  10. }
  11. ?>
  12. <div style="width:75%" align="left">
  13. <?php // Database connection
  14. $rs = mysql_connect($dbhost, $dbuser, $dbpasswd) or die('Could not establish database connection.');
  15. mysql_select_db($dbname,$rs) or die(mysql_error());
  16. if (!$rs)
  17.   {
  18.   die('Could not connect: ' . mysql_error());
  19.   }
  20.   print "Welcome:";
  21.   echo  $_SESSION['account'];
  22.   echo "<br>";
  23.   print "Storage is still in <font color='red'><b>BETA!</b></font>";
  24.   echo "<br>";
  25.  
  26.   $result = mysql_query("SELECT
  27.  s.itemtype,
  28.  s.itemnum,
  29.  s.slotnum,
  30.  r.icon,
  31.  s.count
  32.  FROM storage s
  33.  LEFT JOIN itemref r ON s.itemtype=r.itemtype
  34.  AND s.itemnum=r.itemnum
  35.  WHERE owner='".$_SESSION['account_id']."' AND slotnum <'41' ORDER BY slotnum"); // Selecting from storage via account_id
  36.   $thisImage = '' ;
  37.   $imagePath = 'images/storage2/' ; //Location can be changed.
  38.  
  39.   while($row = mysql_fetch_array($result))
  40.  {
  41.   if ($row['slotnum']=="0") // Still thinking of using the alternative method instead of echoing 160 slots ( see section 1.0a for alt method )
  42.   {
  43.   echo '<img src="'.$imagePath.$row['icon'].'.bmp"/> '.$row['count'].'';
  44.   }
  45. if ($row['slotnum']>"40")
  46.   {
  47.   echo "<div align=center><br><b>Next Page</b></br></div>"; // To be converted to <a href>
  48.   }
  49. ?>
  50. </div>
  51.  

Section 1.0a ( alt image code ) as mentioned in above coding:
  1.  
  2. if (@file_exists($imagePath.$row['icon'].".bmp")) //Checking if an image exists
  3.   {
  4.   echo '<img src="'.$imagePath.$row['icon'].'.bmp"/> '.$row['count'].''; //Displaying the image
  5.   }
  6.   else
  7.   {
  8.   echo "No Image"; // Displaying No Image text for now
  9.   }
  10. ?>
  11.  
Administrator / Coder for EutopiaRose Online
Image
http://www.eutopiarose.co.uk
User avatar
Mark
Rackie
Rackie
 
Posts: 176
Joined: Tue Dec 13, 2011 8:15 am
Location: Sunny England

Re: [HELP]Adding Code From Website To Database

Postby xadet3 on Fri Dec 14, 2012 12:56 pm

Ultra wrote:...

This has a tonne of exploits. You should also be using the mysqli/PDO classes, not the mysql_ functions. Any code using the mysql_ functions will be broken in PHP 5.5.
xadet3
Pero pero
Pero pero
 
Posts: 727
Joined: Tue Jan 08, 2008 11:51 pm
Location: Norwich, England.

Re: [HELP]Adding Code From Website To Database

Postby hoegarden31 on Sun Dec 16, 2012 1:38 pm

Mark is going to have a hard time too if you have more than 1000 items in your itemmall....
Guess you don't know that much about sql querys to make all that way much simpler.
I'm the one and only. In heaven and on earth.
Image
hoegarden31
Rackie
Rackie
 
Posts: 150
Joined: Sun Nov 13, 2011 7:13 pm

Re: [HELP]Adding Code From Website To Database

Postby Mark on Sun Dec 16, 2012 11:20 pm

hoegarden31 wrote:Mark is going to have a hard time too if you have more than 1000 items in your itemmall....
Guess you don't know that much about sql querys to make all that way much simpler.


It's ok I decided to go with the alternative way of displaying items ( the simpler way ), I have a seperate sql table for all items in the client which are linked to another sql table for pulling the correct data/icons/item names etc, No data is lost or muddled up at all, so far no problems.

And I'm still learning new ways of querying databases so cut me some slack, as for the new php 5.5, whats that all about? I've ran a few tests using my_sql functions and they work fine for me :shock:
Administrator / Coder for EutopiaRose Online
Image
http://www.eutopiarose.co.uk
User avatar
Mark
Rackie
Rackie
 
Posts: 176
Joined: Tue Dec 13, 2011 8:15 am
Location: Sunny England

Re: [HELP]Adding Code From Website To Database

Postby xadet3 on Sun Dec 16, 2012 11:32 pm

The mysql_ functions are being deprecated as they encourage bad security and bad practises. They're still widely used simply due to the number of terrible tutorials for PHP still out there.

If you didn't want to use an ORM (like Paris/Idiorm, which I highly recommend using), then you have a choice between the mysqli class or the PDO class. Both use parametrised queries, which means you no longer need to escape data, as you're making the distinction between what's the static query and what's the data, but PDO has the advantage that you can connect to many more databases than just MySQL.

Here's a comparison between the two http://net.tutsplus.com/tutorials/php/p ... d-you-use/ and here's a good tutorial on using PDO http://net.tutsplus.com/tutorials/php/w ... se-access/.
xadet3
Pero pero
Pero pero
 
Posts: 727
Joined: Tue Jan 08, 2008 11:51 pm
Location: Norwich, England.

Re: [HELP]Adding Code From Website To Database

Postby Mark on Sun Dec 16, 2012 11:44 pm

Nice 1 thx xadet, tbh I'd prob go with the PDO variant as I host multiple databases and sometimes data needs to be sought from one for the other to function i.e WoW playtime = EutopiaRose Donation points and visa versa :D Just saw that Idiorm is built on top of PDO anyway so I might just use that.. ahh the choices :lol:
Administrator / Coder for EutopiaRose Online
Image
http://www.eutopiarose.co.uk
User avatar
Mark
Rackie
Rackie
 
Posts: 176
Joined: Tue Dec 13, 2011 8:15 am
Location: Sunny England

Re: [HELP]Adding Code From Website To Database

Postby hoegarden31 on Mon Dec 17, 2012 6:32 pm

I can only agree with xadet. PDO classes are very good. It is a lot faster than mysql with very large databases. Maybe i will remake that dynasty package. But it's a lot of work... Don't expect some results at the end of the week.
I'm the one and only. In heaven and on earth.
Image
hoegarden31
Rackie
Rackie
 
Posts: 150
Joined: Sun Nov 13, 2011 7:13 pm

Re: [HELP]Adding Code From Website To Database

Postby Calder on Mon Dec 31, 2012 8:21 am

Just for the record. PDO an MySQLi are both slower than native MySQL, not to the point where I'd recommend not using them, but the statement that it's faster is just plain wrong.
Calder
Clown
Clown
 
Posts: 503
Joined: Fri May 09, 2008 12:28 am

Next

Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 3 guests