This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
FuuuAInfiniteLoop(F.A.I.L)'s profile picture

Help with php code

Started by FuuuAInfiniteLoop(F.A.I.L), 19 March 2013 - 06:46 AM
FuuuAInfiniteLoop(F.A.I.L) #1
Posted 19 March 2013 - 07:46 AM

<?PHP
$conexion = mysql_connect("mysql3.000webhost.com", "a6845877_aptget", "mysql_query");
mysql_select_db("a6845877_aptget", $conexion);
$action = $_POST['action'];
if ("1" == $action) {
// Post program
$packagename = $_POST['packagename'];
$version = $_POST['version'];
$downloadLink = $_POST['downloadLink'];
$dependencies = $_POST['dependencies'];
$packagename = stripslashes($packagename);
$packagename = mysql_real_escape_string($packagename);
$version = stripslashes($version);
$version = mysql_real_escape_string($version);
$downloadLink = stripslashes($downloadLink);
$downloadLink = mysql_real_escape_string($downloadLink);
$dependencies = stripslashes($dependencies);
$dependencies = mysql_real_escape_string($dependencies);
$result = mysql_query("INSERT INTO packages(PackageName, Verison, DownloadLink, Dependencies) VALUES('$packagename', '$version', '$downloadLink', '$dependencies')")
}
if ("2" == $action) {
// Download program
$packageid = $_POST['packageid'];
$packageid = stripslashes($packageid);
$packageid = mysql_real_escape_string($packageid);
$sql="SELECT * FROM packages WHERE id='$packageid'";
while ($row = mysql_fetch_assoc($result)) {
  echo $row['DownloadLink'];
}
}
if ("3" == $action) {
// Search program
$packagename = $_POST['packagename'];
$packagename = stripslashes($packagename);
$packagename = mysql_real_escape_string($packagename);
$sql="SELECT * FROM packages WHERE PackageName='$packagename'";
while ($row = mysql_fetch_assoc($result)) {
  echo $row['id'];
}
}
if ("4" == $action) {
// Getinfo about the server
echo "ALLOWPOST = true
ALLOWSEARCH = true
";
}
if ("5" == $action) {
// Get the display
$packageid = $_POST['packageid'];
$packageid = stripslashes($packageid);
$packageid = mysql_real_escape_string($packageid);
$sql="SELECT * FROM packages WHERE id='$packageid'";
while ($row = mysql_fetch_assoc($result)) {
  echo $row['display'];
}
}
if ("6" == $action) {
// Get the version
$packageid = $_POST['packageid'];
$packageid = stripslashes($packageid);
$packageid = mysql_real_escape_string($packageid);
$sql="SELECT * FROM packages WHERE id='$packageid'";
while ($row = mysql_fetch_assoc($result)) {
  echo $row['version'];
}
}
<?
Parse error: syntax error, unexpected '}' in /home/a6845877/public_html/action.php on line 20
Lyqyd #2
Posted 19 March 2013 - 07:48 AM
Moved to General.
FuuuAInfiniteLoop(F.A.I.L) #3
Posted 19 March 2013 - 07:51 AM
If makes sense, the post data is a form(that passes 1 as action) for now as testing while im writing hte program and the mysql is hosted on 000webhost
remiX #4
Posted 19 March 2013 - 08:02 AM
$result = mysql_query("INSERT INTO packages(PackageName, Verison, DownloadLink, Dependencies) VALUES('$packagename', '$version', '$downloadLink', '$dependencies')")

Needs a ; at the end, try that?

EDIT:

Php does have if.. elseif btw.

<?php
if ($action == '1') { // Why do you do '1' == $result? :o/> No difference I guess
	// Code
} elseif ($action== '2') {
	// Code
} elseif ($action == '3') {
	// Code
} elseif ($action == '4') {
	// Code
} elseif ($action == '5') {
	// Code
} elseif ($action == '6') {
	// Code
}
?>
FuuuAInfiniteLoop(F.A.I.L) #5
Posted 19 March 2013 - 11:03 AM
Now it works thanks!
PlowmanPlow #6
Posted 21 March 2013 - 06:57 AM
PHP also has a Switch/Case statement: http://php.net/manual/en/control-structures.switch.php
PixelToast #7
Posted 21 March 2013 - 07:16 AM
PHP also has a Switch/Case statement: http://php.net/manua...ures.switch.php
thanks, im just learning php