My php does not post information to mysql

In my php file i have made it so it post information to mysql and it works when i use “XAMPP” to host it from my local pc but when i copy the file over to my website and change the mysqli_connect with the right settings it dosnt post anything in mysql database, please help.
Thanks, Victor

So what is your code and what is your site and what are your config settings?

Im using php version :PHP 5.6 (becouse newer version dosnt work to open up the php file)
This is the php code:

<?php
	session_start();
	//connect to database
	$db = mysqli_connect("localhost", "username", "password", "database");
	
	if(isset($_POST['send_btn'])) {
		session_start();
		$firstname = mysql_real_escape_string($_POST['firstname']);
		$lastname = mysql_real_escape_string($_POST['lastname']);
		$age = mysql_real_escape_string($_POST['age']);
		$email = mysql_real_escape_string($_POST['email']);
		$ingusername = mysql_real_escape_string($_POST['ingusername']);
		$position = mysql_real_escape_string($_POST['position']);
		$why = mysql_real_escape_string($_POST['why']);
		$mcexperience = mysql_real_escape_string($_POST['mcexperience']);
		$weexperience = mysql_real_escape_string($_POST['weexperience']);
		$anything = mysql_real_escape_string($_POST['anything']);
		
		
		$sql = "INSERT INTO application(firstname, lastname, email, age, ingusername, position, why, mcexperience, weexperience, anything) VALUES('$firstname', '$lastname', '$age', '$email', '$ingusername', '$position','$why','$mcexperience','$weexperience','$anything')";
		mysqli_query($db, $sql);
		header("location: applied.php");
	}

?>

html

<!DOCTYPE html>
<html>
	<head>
		<title>Staff Application</title>
		<meta charset="utf-8">
		<link href="style.css" type="text/css" rel="stylesheet">
	</head>
<body>
	<h2>Staff Application</h2>
	<div class="wrapper">
		<form method="post" action="index.php">
			<table>
				<tr>
					<td>First Name: </td>
					<td><input type="text" name="firstname" class="textInput" required></td>
				<tr>
					<td>Last Name: </td>
					<td><input type="text" name="lastname" class="textInput" required></td>
				<tr>
					<td>Age: </td>
					<td><input type="number" name="age" class="textInput" required></td>
				<tr>
					<td>E-mail: </td>
					<td><input type="email" name="email" class="textInput" required></td>
				<tr>
					<td>InGame Username: </td>
					<td><input type="text" name="ingusername" class="textInput" required></td>
				<tr>
					<td>Applying position: </td>
					<td><select name="position" class="dropdownInput" required>
						<option>Admin</option>
						<option>Modertor</option>
						<option>Builder</option>
						<option>Plugin Developer</option>
					</select></td>
				<tr>
					<td>Why should you be a staff: </td>
					<td><textarea name="why" cols="40" rows="5" class="boxInput"></textarea></td>
				<tr>
					<td>Minecraft Experience: </td>
					<td><select name="mcexperience" class="dropdownInput">
						<option>1</option>
						<option>2</option>
						<option>3</option>
						<option>4</option>
						<option>5</option>
						<option>6</option>
						<option>7</option>
						<option>8</option>
						<option>9</option>
						<option>10</option>
					</select></td>
				<tr>
					<td>WorldEdit Experience: </td>
					<td><select name="weexperience" class="dropdownInput">
						<option>1</option>
						<option>2</option>
						<option>3</option>
						<option>4</option>
						<option>5</option>
						<option>6</option>
						<option>7</option>
						<option>8</option>
						<option>9</option>
						<option>10</option>
					</select></td>
				<tr>
					<td>Anything worth mension: </td>
					<td><textarea name="anything" cols="40" rows="5" class="boxInput"></textarea></td>
				<tr>
					<td></td>
					<td><input type="submit" name="send_btn" value="Send" class="send_btn"></td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

I can assume you created a database within 000webhost.com and then put those details into the script?

id_1332653_staffappdata
id_1332653_staffappuser
password903876378

for example

yes i did create one a database in 000webhost and i have the right database information.

Just replace the"mysql_real_escape_string"
and only use $_POST[‘firstname’];
like this:
$firstname =$_POST[‘firstname’];
.
.
.
and it will be ok

2 Likes

I changed the code but now i cant load the site anymore.
Error message:

The page does not work on ----.----.—

-----.-----.— currently unable to handle the request.
HTTP Error 500

Visit general settings on 000webhost.com and choose the PHP version you are working with :slight_smile:

I fixed it i forgot to remove “)” after the name of the string :slight_smile:
Thanks everyone that helped me :slight_smile:

1 Like