Jump to content

Hello! Need a bit of basic php coding..

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
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.

#2
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
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).


<?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
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
The thing is I'm not experienced with coding so I don't have a clue what you are talking about :(

#4
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Right, fair enough.

mysql_connect("localhost", "mysqluser", "mysqlpass");
mysql_select_db("database_name");

Do you understand the code above and do you understand what to change?

#5
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
Yes I understand that, but I don't know where to put it.

#6
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
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
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Sorry for not explaining this too well.


<?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
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
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

#9
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
Also, when they post their items can it be shown on the homepage, the latest items up for sale, etc?

#10
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Nope, sorry. Look at the code provided, I've documented it pretty well with comments. Try see what you can make.

#11
SuperSponge

SuperSponge

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
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?