Hello,
I need someone to code something quick, easy and simple in PHP which allowed people to post there Runescape item to the homepage or what runescape item they are buying.
Hello! Need a bit of basic php coding..
Started by SuperSponge, Sep 25 2010 05:44 AM
10 replies to this topic
#1
Posted 25 September 2010 - 05:44 AM
|
|
|
#2
Posted 25 September 2010 - 05:55 AM
You just basically need a form to parse the input and insert it into a database (or a flatfile, whatever you feel is more appropriate).
If you use this code, please edit the connect & select_db parameters, and create a table entitled 'orders' (with the following fields: personsName and personsItem (varchars for the field type I suppose))
<?php
mysql_connect(....); // Your info belongs here. Replace the periods with your MySQL connection info
mysql_select_db(...); // And here!
if(!$_POST['submit']) {
echo "<form method=\"post\">Name: <br /><input type=\"text\" name=\"personsName\" /><br /><br />Item: <br /><input type=\"text\" name=\"personsItem\" /></form>"; // The HTML
}
else {
// They've used the submit button, now let's clarify all fields were entered correctly.
if(!$_POST['personsItem'] || !$_POST['personsName']) {
echo "You missed a field!"; // They missed a field here. You could paste the form echo back here, if you wish to.
}
else {
// The returned fields appear to be okay to process
mysql_query("INSERT INTO orders (personsName, personsItem) VALUES('" . mysql_real_escape_string($_POST['personsName']) . "', '" . mysql_real_escape_string($_POST['personsItem']) . "')"); // Insert their order into the database.
echo "Thank you, " . $_POST['personsName'] . ". You are ordering item " . $_POST['personsItem']; // Echo the success message.
}
}
?>
If you use this code, please edit the connect & select_db parameters, and create a table entitled 'orders' (with the following fields: personsName and personsItem (varchars for the field type I suppose))
#3
Posted 25 September 2010 - 05:56 AM
The thing is I'm not experienced with coding so I don't have a clue what you are talking about :(
#4
Posted 25 September 2010 - 05:58 AM
Right, fair enough.
Do you understand the code above and do you understand what to change?
mysql_connect("localhost", "mysqluser", "mysqlpass");
mysql_select_db("database_name");
Do you understand the code above and do you understand what to change?
#5
Posted 25 September 2010 - 05:59 AM
Yes I understand that, but I don't know where to put it.
#6
Posted 25 September 2010 - 06:00 AM
Would it be easier if I use HTML because I can understand HTML a hell of a lot better than php. My friend recommended PHP me to me, I don't know why.
#7
Posted 25 September 2010 - 06:03 AM
Sorry for not explaining this too well.
Create a page (say 'form.php') and paste the code above, change the two lines (just under the '<?php' part) to your MySQL information, once done, create another page:
In this new page, call it something random, as long as you can access it, change the MySQL information (line 2 & line 3) to your current database information, save the page, access it then delete it (that will configure your database table for you, so your form will be functional).
PHP is a server-sided language, HTML is merely a markup. The form has to be written in a language like PHP.
<?php
mysql_connect("localhost", "mysqluser", "mysqlpass"); // And this part too (whoops, wrote in descending order).
mysql_select_db("database_name"); // Here are the parts you need to change.
if(!$_POST['submit']) {
echo "<form method=\"post\">Name: <br /><input type=\"text\" name=\"personsName\" /><br /><br />Item: <br /><input type=\"text\" name=\"personsItem\" /></form>"; // The HTML
}
else {
// They've used the submit button, now let's clarify all fields were entered correctly.
if(!$_POST['personsItem'] || !$_POST['personsName']) {
echo "You missed a field!"; // They missed a field here. You could paste the form echo back here, if you wish to.
}
else {
// The returned fields appear to be okay to process
mysql_query("INSERT INTO orders (personsName, personsItem) VALUES('" . mysql_real_escape_string($_POST['personsName']) . "', '" . mysql_real_escape_string($_POST['personsItem']) . "')"); // Insert their order into the database.
echo "Thank you, " . $_POST['personsName'] . ". You are ordering item " . $_POST['personsItem']; // Echo the success message.
}
}
?>
Create a page (say 'form.php') and paste the code above, change the two lines (just under the '<?php' part) to your MySQL information, once done, create another page:
<?php
mysql_connect("localhost", "mysqluser", "mysqlpass"); // And this part too (whoops, wrote in descending order).
mysql_select_db("database_name"); // Here are the parts you need to change.
mysql_query("CREATE TABLE `orders` (`personsName` VARCHAR( 254 ) NOT NULL ,`personsItem` VARCHAR( 254 ) NOT NULL) ENGINE = MYISAM ;");
?>
In this new page, call it something random, as long as you can access it, change the MySQL information (line 2 & line 3) to your current database information, save the page, access it then delete it (that will configure your database table for you, so your form will be functional).
SuperSponge said:
Would it be easier if I use HTML because I can understand HTML a hell of a lot better than php. My friend recommended PHP me to me, I don't know why.
PHP is a server-sided language, HTML is merely a markup. The form has to be written in a language like PHP.
#8
Posted 25 September 2010 - 06:07 AM
That makes much more sense, do you think you can make another one for someone trying to purchase a specific item? Is there a way for them to type in a letter/name and it shows up an option of what they can choose from, quantity, etc.
RuneScape - MMORPG - Grand Exchange
RuneScape - MMORPG - Grand Exchange
#9
Posted 25 September 2010 - 06:10 AM
Also, when they post their items can it be shown on the homepage, the latest items up for sale, etc?
#10
Posted 25 September 2010 - 06:38 AM
Nope, sorry. Look at the code provided, I've documented it pretty well with comments. Try see what you can make.
#11
Posted 25 September 2010 - 10:02 AM
That's completely fine, just a few questions.
Can this code be implemented on a homepage or does it have to have it's own page?
Also, http://rsge.comze.com/form.php - There is no submit button?
Can this code be implemented on a homepage or does it have to have it's own page?
Also, http://rsge.comze.com/form.php - There is no submit button?


Sign In
Create Account


Back to top









