Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have an error within this PHP else if statement (which is part of an if statement):
Parse error: syntax error, unexpected '}' in /home1/tony1964/public_html/2v2tournaments/action.php
The place where the unexpected '}' is at the end of the code below. I can't figure out why this doesn't work. Thanks in advance for any help.
else if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {
include('php-riot-api.php');
$summoner_name_input = $_POST['summonername'];
$summoner_name = str_replace(' ', '_', $summoner_name_input);
$summoner_region = $_POST['summonerregion'];
$verify_code_input = $_POST['verify_code'];
$verify_code = str_replace(' ', '_', $verify_code_input);
$instance = new riotapi($summoner_region);
$grab_data = $instance->getSummonerByName($summoner_name);
$decode_data = json_decode($grab_data);
$grab_id = $decode_data->{'id'};
var_dump($grab_id);
$grab_runes = $instance->getSummoner($grab_id,'runes');
$decode_runes = json_decode($grab_runes);
$rune_check = $decode_runes->{'name'};
if ($rune_check = $verify_code) {
$logged_user = $_SESSION['logged_user'];
if (!($stmt = $con->prepare("INSERT INTO `verified_summoners` (`Username`,`SummonerName`,`SummonerRegion`) VALUES (?,?,?)")) || !is_object($stmt)) {
die( "Error preparing: (" .$con->errno . ") " . $con->error);
}
$stmt->bind_param('sss', $logged_user, $summoner_name, $summoner_region);
if($stmt->execute()) {
echo "Successfully Verified! Check out your new list! <a class='content' href='index.php'><span class='button color_yellow'>Return</span></a>";
} else {
echo "Unsuccessful INSERT, Contact Support or Try again...";
}
$stmt->close();
}
} else {
echo "O Dear, It didn't work! Try Again!";
}
}
Formatting your code would answer your question for you.
else if (isset($_GET['do']) && $_GET['do'] === "reg_type_2") {
include('php-riot-api.php');
$summoner_name_input = $_POST['summonername'];
$summoner_name = str_replace(' ', '_', $summoner_name_input);
$summoner_region = $_POST['summonerregion'];
$verify_code_input = $_POST['verify_code'];
$verify_code = str_replace(' ', '_', $verify_code_input);
$instance = new riotapi($summoner_region);
$grab_data = $instance->getSummonerByName($summoner_name);
$decode_data = json_decode($grab_data);
$grab_id = $decode_data->{'id'};
var_dump($grab_id);
$grab_runes = $instance->getSummoner($grab_id,'runes');
$decode_runes = json_decode($grab_runes);
$rune_check = $decode_runes->{'name'};
if ($rune_check = $verify_code) {
$logged_user = $_SESSION['logged_user'];
if (!($stmt = $con->prepare("INSERT INTO `verified_summoners` (`Username`,`SummonerName`,`SummonerRegion`) VALUES (?,?,?)")) || !is_object($stmt)) {
die( "Error preparing: (" .$con->errno . ") " . $con->error);
}
$stmt->bind_param('sss', $logged_user, $summoner_name, $summoner_region);
if($stmt->execute()) {
echo "Successfully Verified! Check out your new list! <a class='content' href='index.php'><span class='button color_yellow'>Return</span></a>";
} else {
echo "Unsuccessful INSERT, Contact Support or Try again...";
}
$stmt->close();
} else {
echo "O Dear, It didn't work! Try Again!";
}
}
-
$stmt->close();
}
}
Should be
$stmt->close();
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
<?php
if (isset($_POST['submit'])) {
$title = $_POST['title'];
if (isset($_FILES['images']['name'])) {
$image_name = $_FILES['images']['name'];
echo($image_name);
$image_path = $_FILES['images']['tmp_name'];
echo($image_path);
$destination_path = 'location:'.SITEURL.'images/category/'.$image_name;
// echo($destination_path);
$upload = move_uploaded_file($image_name, $destination_path);
echo($upload);
if ($upload==0) {
$_SESSION['upload_image_category'] = "<div class='error'>failed to upload image </div>";
header('location:'.SITEURL.'admin/add-category.php');
die();
}
}
else{
$image_name = "";
}
if (isset($_POST['featureyon'])) {
$feature = $_POST['featureyon'];
}
else{
$feature = "No";
}
if (isset($_POST['a_yes'])) {
$active = $_POST['a_yes'];
}
else{
$active = "No";
}
# code...
$sql = "INSERT INTO tbl_category SET
title = '$title',
image_name='$image_name',
featured='$feature',
active='$active'
";
$res = mysqli_query($conn, $sql);
if ($res == True) {
$_SESSION['add_category'] = "<div class='success'>New category added</div>";
header('location:'.SITEURL.'admin/manage_category.php');
}
else{
$_SESSION['add_category'] = "<div class='error'>failed to add New category </div>";
header('location:'.SITEURL.'admin/add-category.php');
}
}
?>
the first
$destination_path should be a real pathname on the server, not a URL. Like this :- $destination_path = '../images/category/'.$image_name;
the second
move_uploaded_file(source_path, destination_path) Like this :-
$upload = move_uploaded_file($image_path, $destination_path);
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I am getting a parse error with the following code. I have searched but could not find an answer.
error:
Parse error: syntax error, unexpected '$aircrafttype' (T_VARIABLE) in dbinput.php on line 58
Here is the code:
<?php
if (isset($_POST['submit'])) {
$data_missing = array();
if(empty($_POST['airline'])) {
$data_missing[] = 'Flygbolag';
} else {
$airline = $_POST['airline'];
}
if(empty($_POST['registration'])) {
$data_missing[] = 'Registrering';
} else {
$registration = $_POST['registration'];
}
if(empty($_POST['msn'])) {
$data_missing[] = 'MSN';
} else {
$msn = $_POST['msn'];
}
if(empty($_POST['aircrafttype'])) {
$data_missing[] = 'Flygplanstyp';
} else {
$aircrafttype = $_POST['aircrafttype'];
}
if(empty($_POST['enginedata'])) {
$data_missing[] = 'Motorer';
} else {
$enginedata = $_POST['enginedata'];
}
if(empty($_POST['loc'])) {
$data_missing[] = 'Plats';
} else {
$loc = $_POST['loc'];
}
}
if (empty($data_missing)) {
require_once('../dbconnect.php');
$query = "INSERT INTO Aircraft_spotted VALUES (?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, "ssisss", $airline, $registration, $msn, $aircrafttype, $enginedata, $loc);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
if ($affected_rows == 1) {
echo "Aircraft entered to database";
mysqli_stmt_close($stmt);
mysqli_close($conn);
} else {
echo "Error occured: " . mysqli_error();
}
} else {
echo "You need to enter the following data: <br />";
foreach ($data_missing as $missing) {
echo "$missing<br />";
echo "string";
}
}
?>
I am grateful for any answer or help with the issue. Thanks a lot! Very much appreciate it!
Samuel
check if your $_POST['aircrafttype'] exists by print_r($_POST)
Probably you don't have set this or aircrafttype field is not sent to the POST. Try with:
if (isset($_POST['submit'])) {
$data_missing = array();
if(empty($_POST['airline']) || !isset($_POST['airline'])) {
$data_missing[] = 'Flygbolag';
} else {
$airline = $_POST['airline'];
}
if(empty($_POST['registration']) || !isset($_POST['registration'])) {
$data_missing[] = 'Registrering';
} else {
$registration = $_POST['registration'];
}
if(empty($_POST['msn']) || !isset($_POST['msn'])) {
$data_missing[] = 'MSN';
} else {
$msn = $_POST['msn'];
}
if(empty($_POST['aircrafttype']) || !isset($_POST['aircrafttype'])) {
$data_missing[] = 'Flygplanstyp';
} else {
$aircrafttype = $_POST['aircrafttype'];
}
if(empty($_POST['enginedata']) || !isset($_POST['enginedata'])) {
$data_missing[] = 'Motorer';
} else {
$enginedata = $_POST['enginedata'];
}
if(empty($_POST['loc']) || !isset($_POST['loc'])) {
$data_missing[] = 'Plats';
} else {
$loc = $_POST['loc'];
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I want to update a row on a table and it is not updating.
This is my html and php code :
<?php
if ($_GET) {
if (isset($_GET['id'])) {
$id = preg_replace('#[^0-9]#', '', $_GET['id']);
echo $id;
$query = "SELECT * FROM posts WHERE id='{$id}'";
$result = mysqli_query($connect, $query);
$rows = mysqli_fetch_assoc($result);
} elseif (empty($_GET['id'])) {
header("location: manage_posts.php");
}
}
?>
<form action="modify_post.php?id=<?php echo $id; ?>" method="post">
<h3>Post Title <?php //echo $id; ?></h3>
<input name="title" value="<?php echo $rows['title'];?>" type="text" placeholder="Title here ..." id="title" required>
<h3>Post Content</h3>
<textarea name="content" required placeholder="Title here ..." style="resize: none"><?php echo $rows['content'];?></textarea>
<br/>
<input type="submit" value="Update" id="submit"/>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($_POST['title'] != "" || $_POST['content'] != "") {
$id = preg_replace('#[^0-9]#', '', $_GET['id']);
$sql = "UPDATE posts SET title='{$_POST['title']}', content='{$_POST['content']}' WHERE id='{$id}'";
$update_result = mysqli_query($connect, $sql);
if (isset($result)) {
echo "<h2>Update successfully, redirecting back ...</h2>";
} else {
echo "Record hasn't been Updated" . mysqli_errno($result);
}
header("location: manage_posts.php");
} else {
echo "<h3>Please fill all fields</h3>";
}
}
?>
This is all what I could came up with !
I don't know where is the problem coming from ?
a) avoid sql injections e.g. with prepared statements + parameters
b) add more error handling and parameter checking.
<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo 'wrong method';
}
else if ( !isset($_POST['title'], $_POST['content']) ) {
echo 'missing POST parameters';
}
else if ( !isset($_GET['id']) ) {
echo 'missing GET parameter';
}
else if ($_POST['title'] == "" || $_POST['content'] == "") {
echo '<h3>Please fill all fields</h3>';
}
else {
$stmt = $connect->prepare('UPDATE posts SET title=?, content=? WHERE id=?');
if ( !$stmt ) {
trigger_error('prepare failed', E_USER_ERROR);
}
else if ( !$stmt->bind_param('sss', $_POST['title'], $_POST['content'], $_GET['id']) ) {
trigger_error('bind_param failed', E_USER_ERROR);
}
else if ( !$stmt->execute() ) {
trigger_error('execute failed', E_USER_ERROR);
}
else {
echo '# of updated rows: ', $stmt->affected_rows();
}
}
see also
http://docs.php.net/mysqli.error-list
http://docs.php.net/mysqli-stmt.error-list
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I write this but it doesnt work, can`t find the error.
this server side code get the the variable $cpu & $display and use it in select from the data base. when the variable is not important "*" will be sent.
<?php
if (isset($_REQUEST['action']))
{
$action = $_REQUEST['action'];
}
else
{
echo "Invalid Data";
exit;
}
if ($action == "read")
{
readData();
}
function connectToDatabase()
{
$connection = mysqli_connect("localhost", "root", "", "project_pro");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
return $connection;
}
function readData()
{
$connection = connectToDatabase();
$cpu = $_REQUEST['cpu'];
$display = $_REQUEST['display'];
This is the part that problem exists:
$sql = "Select * From phones WHERE";
if ($cpu == "*")
{
}
else
{
$sql+= " phone_cpu='$cpu'";
}
if ($display == "*")
{
}
else
{
$sql+= " AND phone_display='$display'";
}
$output = array();
while ($row = mysqli_fetch_array($result))
{
$record = array();
$record['phone_id'] = $row['phone_id'];
$record['phone_cpu'] = $row['phone_cpu'];
$output[] = $record;
}
echo json_encode($output);
mysqli_close($connection);
}
The concatenation operator in PHP is . not +. So change += to .=.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I got this error
Parse error: syntax error, unexpected '}' in C:\wamp\www\widget_corp\public
\create_subject.php on line 24
when I clicked on my "Creae Subject" button.
I have tried to fix it all day but really can't find what the problem is.
<?php require_once ("../includes/session.php"); ?>
<?php require_once ("../includes/db_connection.php"); ?>
<?php require_once ("../includes/functions.php"); ?>
<?php require_once ("../includes/validation_function.php"); ?>
<?php
if (isset($_POST['submit'])) {
// Process the form
$menu_name = mysql_prep($_POST["menu_name"]);
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
// Validations
$required_fields = array("menu_name", "position", "visible");
validate_presences($required_fields);
$fields_with_max_lengths = array("menu_name" => 30);
validate_max_lengths($fields_with_max_lengths);
if (!empty($errors)) {
$_SESSION["errors"] = $errors;
redirect_to("new_subject.php")
} <-------- THIS IS ROW 24! ----------->
$query = "INSERT INTO subjects (";
$query .= " menu_name, position, visible";
$query .= ") VALUES (";
$query .= " '{$menu_name}, {$position}, {$visible}";
$query .= ")";
$result = mysqli_query($connection, $query);
if ($result) {
// Success
$_SESSION["message"] = "Subject created!";
redirect_to("manage_content.php");
} else {
// Failure
$_SESSION["message"] = "Subject creation failed";
redirect_to("new_subject.php");
}
} else {
// This is probably a GET request
redirect_to("new_subject.php");
}
?>
<!-- Close database connection -->
<?php if (isset($connection)) { mysqli_close($connection); } ?>
Missing semicolon on the line above the brace.
redirect_to("new_subject.php")
A lot of times you have to look at the line above the one given in the error to see what the problem is.
you have missed semicolon in this line:
redirect_to("new_subject.php");
try this:
if (!empty($errors)) {
$_SESSION["errors"] = $errors;
redirect_to("new_subject.php");
}