Passing a mysql row inside of a PHP/HTML Form - php

Im becomming quite a regular on here...
I am trying to dynamicly print out a table in PHP depending on what results are found with a MYSQL Statement.
See the below code, I am getting the below error
[Fri Jun 09 18:51:32.478737 2017] [fcgid:warn] [pid 63368] [client 5.69.190.95:64631] mod_fcgid: stderr: PHP Parse error: syntax error, unexpected 'showhistory' (T_STRING), expecting ',' or ';' in /home/tools/public_html/searchhistory.php on line 84, referer: http://tools.cidetech.co.uk/history.php
It seems to have a problem with just the "form" building inside of the loop I have no problems up until this line -
echo " <td><form method="POST" action="showhistory.php">
<input type="hidden" name="id_director" value=".$row["id"]"
</form></td> ";
I cant seem to figure out where I am going wrong, this would work fine in just pure HTML, however it needs to be inside of the mysql/php part as i need to pass the row id through inside of the button.
To be specific it is this part of the code I am struggling with
for ($i = 0; $i < count($idArray); $i++)
{
$sql="SELECT * FROM history WHERE id LIKE '%{$idArray[$i]}%'";
$result=$con->query($sql);
while($row=$result->fetch_assoc())
{
echo "<tr>";
echo "<td><pre>".$row["id"]."</pre></td>";
echo "<td><pre>".$row["date"]."</pre></td>";
echo "<td><pre>".$row["domain"]."</pre></td>";
echo " <td><form method="POST" action="showhistory.php">
<input type="hidden" name="id_director" value=".$row["id"]"
</form></td> ";
}
}
echo "</table>";
mysqli_close($conn);
?>
The full code can be seen here
<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>CWCS Domain Checker Tool</title>
</head>
<body>
<div class="header">
<a href="index.php">
<img src="cwcs-logo.png">
</a>
</div>
<hr/>
<div class="searchform">
<form action="searchhistory.php" method="post">
<label for="domain"> <input class="submit" type="text" name="domain" /> </label>
<input class="submitbutton" type="submit" name="search" value="Search for Domain" />
</form>
</div>
<?php
#define connection info/variables needed
$servername = "localhost";
$username = "";
$password = "";
$dbname = "domainhistory";
$domain = $_POST['domain'];
$idArray = array();
#creates mysql connection
$con=new mysqli($servername,$username,$password,$dbname);
if($con->connect_error)
{
echo 'Connection Faild: '.$con->connect_error;
}
else
{
$sql="SELECT * FROM history WHERE domain LIKE '%{$domain}%'";
$result=$con->query($sql);
#Pushes the ID of the mysql row into an array
while($row=$result->fetch_assoc())
{
array_push($idArray,$row["id"]);
}
}
mysqli_close($conn);
?>
<!---prints out the ID's stored in the array -->
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "domainhistory";
$con=new mysqli($servername,$username,$password,$dbname);
if($con->connect_error)
{
echo 'Connection Faild: '.$con->connect_error;
}
else
{
}
echo "<table>";
echo "<tr>";
echo "<th> ID </th>";
echo "<th> Domain</th>";
echo "<th> Date </th>";
echo "</tr>";
## - loops through the ID array, and then prints out the data relating to that ID.
for ($i = 0; $i < count($idArray); $i++)
{
$sql="SELECT * FROM history WHERE id LIKE '%{$idArray[$i]}%'";
$result=$con->query($sql);
while($row=$result->fetch_assoc())
{
echo "<tr>";
echo "<td><pre>".$row["id"]."</pre></td>";
echo "<td><pre>".$row["date"]."</pre></td>";
echo "<td><pre>".$row["domain"]."</pre></td>";
echo " <td><form method="POST" action="showhistory.php">
<input type="hidden" name="id_director" value=".$row["id"]"
</form></td> ";
}
}
echo "</table>";
mysqli_close($conn);
?>
</body>
</html>

You should use ' instead of " for your string in php, because you have the " used in the html markup and the " you use for echo.

Related

How do I pass these variables to another php file

I'm currently making a shopping website and I need to be able to pass two variables to the next page, the code may be badly written because I'm new to this, but I'm trying to pass the number from the drop-down menu and the "row['pid']" to another page. As shown below I have attempted to use a form button but it can only transfer the number from the dropdown. There is database connected so if you try to load it up, it may not load anything. This issue is specifically focussing on the button which the form is linked to at the end. Thank you for your time.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://kit.fontawesome.com/9114d9acc8.js" crossorigin="anonymous">
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="includes/navbar/navbar.css">
<link rel="stylesheet" href="css/style.css">
<title>Document</title>
</head>
<body>
<?php include "includes/navbar/navbar.php"; ?>
<div id="arranging">
<?php
require 'includes/dbh.php';
$query = sprintf('SELECT * FROM produce');
$result = mysqli_query($conn, $query);
//$var_value = 'hello';
//$_SESSION['varname'] = $var_value;
while ($row = mysqli_fetch_assoc($result)) {
if ($row['Quantity'] == 0) {
}
else {
?>
<div class="itemTemplate">
<a id="title" onclick="ContentPage(<?php echo $row['pid']; ?>)"><?php echo $row['Name'] ?></a>
<a onclick="ContentPage(<?php echo $row['pid']; ?>)" id="myid"><img src="<?php echo $row['img'] ?>"
alt="<?php echo $row['Name'] ?>"></a>
<span>Price: £<?php echo $row['Price'] ?></span>
<form action="includes/quickBasket.php" method="POST">
<div class="flex-b">
<label for="">Quantity:</label>
<select name="quantity">
<?php
if ($row['Quantity'] > 8) {
for ($x = 1; $x <= 8; $x++) {
echo "<option value='$x'>$x</option>";
}
}
else {
for ($x = 1; $x <= $row['Quantity']; $x++) {
echo "<option value='$x'>$x</option>";
}
}
?>
</select>
<button id="button" type="submit" name="cart" class="fas fa-shopping-basket"></button>
</div>
</form>
</div>
<?php
}
}
?>
</div>
<script>
function ContentPage(elem) {
location.href = "Product.php" + "?id=" + elem;
};
</script>
</body>
</html>
If you want to transfer the PID when the form is submitted then you need a field for it within the form, e.g. a hidden field like this:
<input type="hidden" name="pid" value="<?php echo $row['pid']; ?>"/>
Then when you submit the form, it will be accessible as $_POST["pid"] (just like the value from the dropdown is accessible as $_POST["quantity"]).
This applies to any value - if you want it to be submitted with the form, then there needs to be a proper field for it within the form (or least associated with the form via the necessary attribute).

start end date & dropdown menu from mysql in one html page

I am trying to make a html or php page (for some own learning process) which can input 3 selection and then display there results in next page.
1- input Start Date
2- input End Date
3- Show Service Name in drop down menu via mysql query to get services names from the table
So far I have managed to get the start and end table and drop down menu which successfully query the services table and shows the name, but the problem is that when i click submit i can see the results of start and end date but i am unable to see how can i add services selection in the posting.
This is my code.
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#start_datepicker").datepicker();
$("#end_datepicker").datepicker();
});
</script>
</head>
<body style="font-size:62.5%;">
<form action="test.php" method="post">
Start Date: <input type="text" name="startdate" id="start_datepicker"> <br />
End Date: <input type="text" name="enddate" id="end_datepicker"><br />
<select name="srvname">
<?php
$conn = new mysqli('localhost', 'root', 'SQLPASS', 'radius')
or die ('Cannot connect to db');
$result = $conn->query("select srvname name from rm_services");
while ($row = $result->fetch_assoc()) {
echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>";
}
?>
</select>
<input type="submit" value="Submit:">
</form>
</body>
</html>
and this is test.php which will per form action shows the date
<?php
$STARTDATE = $_POST['startdate'];
$ENDDATE = $_POST['enddate'];
$SRVNAME = $_POST['srvname']; //gets the value -> $row["id"]
echo "<h2>You have entered the following information:</h2>";
echo "<pre>$STARTDATE</pre> ";
echo "<pre>$ENDDATE</pre>";
echo "<pre>$SRVNAME</pre>";
?>
This one should work, and for the future: if you post something on stackoverflow, please post formatted code, it's way easier to edit and especially to read it...
your index.php or whatever...
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#start_datepicker").datepicker();
$("#end_datepicker").datepicker();
});
</script>
</head>
<body style="font-size:62.5%;">
<form action="test.php" method="post">
Start Date: <input type="text" name="startdate" id="start_datepicker"> <br />
End Date: <input type="text" name="enddate" id="end_datepicker"><br />
<select name="srvname">
<?php
$conn = new mysqli('localhost', 'root', 'SQLPASS', 'radius')
or die ('Cannot connect to db');
$result = $conn->query("select id, name from rm_services");
while ($row = $result->fetch_assoc()) {
echo "<option value=\"" . $row["id"] . "\">" . $row["name"] . "</option>";
}
?>
</select>
<input type="submit" value="Submit:">
</form>
</body>
</html>
your test.php
<?php
$STARTDATE = $_POST['startdate'];
$ENDDATE = $_POST['enddate'];
$SRVNAME = $_POST['srvname']; //gets the value -> $row["id"]
echo "<h2>You have entered the following information:</h2>";
echo "<pre>$STARTDATE</pre> ";
echo "<pre>$ENDDATE</pre>";
echo "<pre>$SRVNAME</pre>";
?>
I didn't test it, but actually it should work...

Unable to change database

My aim to is to Update Value in Database By using Update Query . On my first page i have just displayed database table in webpage. Then by using hyperlink i have to click on Edit to second page "edit.php".While on first page i have to get the value of id and send it to second page. Where a input form is displayed which gets Value casually but Id through hidden tag. On third page getting the values query is implented but the value of id is missing.
First Page
<html>
<head>
<title>Assignment</title>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
// Check connection
if (!mysql_connect()) {
echo "Failed to connect to MySQL: " . mysql_connect_error();
}
$db=mysql_select_db("assignment",$con);
$result = mysql_query("SELECT * FROM teacher ",$con);
?><table cellpadding="2px" border="2px"><?php
while($row = mysql_fetch_array($result)) {
?> <tr>
<td><a href="edit.php?id=<?php
echo $row['id']; ?>">Edit</a > Delete
</td><td>
<?php
echo $row['id']; ?></td><td> <?php echo $row['name'];?></td><td><?php echo $row['program']; ?></td>
<?php }
?></table><?php
mysql_close($con);
?>
</body>
</html>
Secnod Page edit.php
<html>
<head>
<title>Assignment Edit</title>
</head>
<body>
<?php
$id = $_GET['id'];
?>
<form action="update.php" method="get">
Address <input type="text" name="program"><br>
<input type="hidden" name="id" value='<?php $id?>'>
<input type="submit" name="submit">
</form>
</body>
</html>
Third Page update.php
<html>
<head>
<title>Update Page</title>
</head>
<body>
<?php
$add=$_GET['program'];
$id=$_GET['id'];
$con=mysql_connect("localhost","root","");
// Check connection
if (!mysql_connect()) {
echo "Failed to connect to MySQL: " . mysql_connect_error();
}
$db=mysql_select_db("assignment",$con);
$query = "UPDATE teacher SET program='$add' WHERE id =".$id;
echo $query;
$result = mysql_query($query,$con);
/* while($row = mysql_fetch_array($result)) {
echo $row['id'] ." " . $row['name']." ". $row['address']."<br>";
}
mysql_close($con);
*/
?>
</body>
</html>
output
UPDATE teacher SET program='openSource' WHERE id =
you need to change this
<input type="hidden" name="id" value='<?php $id?>'>
to
<input type="hidden" name="id" value='<?php echo $id?>'>
(or)
<input type="hidden" name="id" value='<?=$id?>'>

Form not recognizing post variables

I have a simple html form and some php that input the POST variables into a mysql database. However, I noticed that the form would not input the data when
if (isset($_POST['submit'])){
insert stuff in here
}
was included. I then removed the if statement above and ran the code. All of the variables were imputed except the ones from the form using POST (ex $_POST['var1']). It seems like the POST variables are not being recognized and I dont know what's wrong.
ALL CODE:
<?php session_start(); ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.min.js'></script>
<script type='text/javascript' src='http://twitter.github.com/bootstrap/1.4.0/bootstrap-modal.js'></script>
<link rel="stylesheet" href="../css/bootstrap.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/basic.css" type="text/css" media="screen" />
</head>
<body>
<?php include '../css/bar.php'; ?>
<div id='content'>
<?php include '../nav.php';
?>
<?php
if (isset($_POST['submit'])){
include '../connect.php';
$question=mysql_real_escape_string($_POST['question']);
$detail=mysql_real_escape_string($_POST['detail']);
$date=date("d M Y");
$time=time();
$user=$_SESSION['id'];
$put=mysql_query("INSERT INTO questions VALUES ('','$question','$detail','$date','$time','$user','subject','0')");
$result=mysql_query("SELECT * FROM questions WHERE user='$user' AND time='$time'");
while ($row = mysql_fetch_assoc($result)){
$q=$row['id'];
}
}
?>
<form method='POST' action='question.php?q=<?php echo $q ?>'>
<p>Question:</p>
<p><input type='text' name='question' id='question' maxlength='200'></p>
<p>Add some detail (optional):</p>
<p><textarea id='detail' name='detail' ></textarea></p>
<p>Tags:</p>
<p><input type='submit' value='submit' name='submit'></p>
</form>
</div>
<?php include '../footer.php'; ?>
</body>
</html>
TESTPAGE:
<?php
include 'connect.php';
if (isset($_POST['submit'])){
$hhh=mysql_real_escape_string($_POST['hhh']);
$put=mysql_query("INSERT INTO questions VALUES ('','$hhh','','','','','','')");
}
?>
<form action='test.php' method='post'>
<input type='text' name='hhh'>
<input type='submit' name='submit' value='submit'>
</form>
You have two PHP pages - ask.php and question.php. I (guess)think the ask.php is used to store questions and other details and you want to open a question.php with question id.
ask.php
<?php session_start(); ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.min.js'></script>
<script type='text/javascript' src='http://twitter.github.com/bootstrap/1.4.0/bootstrap-modal.js'></script>
<link rel="stylesheet" href="../css/bootstrap.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/basic.css" type="text/css" media="screen" />
</head>
<body>
<?php include '../css/bar.php'; ?>
<div id='content'>
<?php
include '../nav.php';
/*--- If submit button is pressed ---- */
if (isset($_POST['submit']))
{
include '../connect.php';
$question=mysql_real_escape_string($_POST['question']);
$detail=mysql_real_escape_string($_POST['detail']);
$date=date("d M Y");
$time=time();
$user=$_SESSION['id'];
/* SELECT column names you want to use with INSERT statement */
$put=mysql_query("INSERT INTO questions
(`question`,`detail`,`date`,`time`,`user`,`subject`,`name_of_last_col` )
VALUES
('$question','$detail','$date','$time','$user','subject','0')");
//for debug purpose
if($put)
{
echo "Record added";
}
else
{
echo "Can't add record " . mysql_error();
}
}
/*----- End submit block -----------*/
/*----List the questions and select it----------*/
$time=time();
$user=$_SESSION['id'];
//I think this wont work. Try to remove time comparison from the SELECT statement.
$result=mysql_query("SELECT * FROM questions WHERE `user`='$user' AND `time`='$time'");
//$result=mysql_query("SELECT * FROM questions WHERE `user`='$user'");
if($result)
{
echo "<table>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>$row[question]</td>";
echo "<td><a href='question.php?qid=$row[id]'>Show a question</a></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No questions!!!";
}
?>
<form method='POST' action="ask.php">
<p>Question:</p>
<p><input type='text' name='question' id='question' maxlength='200'></p>
<p>Add some detail (optional):</p>
<p><textarea id='detail' name='detail' ></textarea></p>
<p>Tags:</p>
<p><input type='submit' value='submit' name='submit'></p>
</form>
question.php should be:
<?php
$qid=$_GET["qid"];
echo "$qid is selected...";
?>
You may split code into two PHP pages - one for save records and another to list and select rows.
addquestion.php
<?php
session_start();
if(isset($_POST['submit']))
{
mysql_connect("localhost","user","password") or die(mysql_error());
mysql_select_db("your_db_name") or die(mysql_error());
$question=mysql_real_escape_string($_POST['question']);
$detail=mysql_real_escape_string($_POST['detail']);
$date=date("d M Y");
$time=time();
$user=$_SESSION['id'];
$put=mysql_query("INSERT INTO questions
(`question`,`detail`,`date`,`time`,`user`,`subject`,`name_of_last_col` )
VALUES
('$question','$detail','$date','$time','$user','subject','0')");
//for debug purpose
if($put)
{
echo "Record added";
}
else
{
echo "Can't add record " . mysql_error();
}
}
?>
<form method='post' action="addquestion.php">
<p>Question:</p>
<p><input type='text' name='question' id='question' maxlength='200'></p>
<p>Add some detail (optional):</p>
<p><textarea id='detail' name='detail' ></textarea></p>
<p>Tags:</p>
<p><input type='submit' value='submit' name='submit'></p>
</form>
questionlist.php
<?php
session_start();
$user=$_SESSION['id'];
mysql_connect("localhost","user","password") or die(mysql_error());
mysql_select_db("your_db_name") or die(mysql_error());
$result=mysql_query("SELECT * FROM questions WHERE `user`='$user'");
if($result)
{
echo "<table>";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>$row[question]</td>";
echo "<td><a href='question.php?qid=$row[id]'>Show a question</a></td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No questions!!!";
}
?>

PHP syntax error “unexpected $end”

I have 3 files
1) show_createtable.html
2) do_showfielddef.php
3) do_showtble.php
1) First file is for creating a new table for a data base, it is a fom with 2 inputs, Table Name and Number of Fields. THIS WORKS FINE!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<h1>Step 1: Name and Number</h1>
<form method="post" action="do_showfielddef.php" />
<p><strong>Table Name:</strong><br />
<input type="text" name="table_name" size="30" /></p>
<p><strong>Number of fields:</strong><br />
<input type="text" name="num_fields" size="30" /></p>
<p><input type="submit" name="submit" value="go to step2" /></p>
</form>
</body>
</html>
2) this script validates fields and createa another form to enter all the table rows.
This for also WORKS FINE!
<?php
//validate important input
if ((!$_POST[table_name]) || (!$_POST[num_fields])) {
header( "location: show_createtable.html");
exit;
}
//begin creating form for display
$form_block = "
<form action=\"do_createtable.php\" method=\"post\">
<input name=\"table_name\" type=\"hidden\" value=\"$_POST[table_name]\">
<table cellspacing=\"5\" cellpadding=\"5\">
<tr>
<th>Field Name</th><th>Field Type</th><th>Table Length</th>
</tr>";
//count from 0 until you reach the number fo fields
for ($i = 0; $i <$_POST[num_fields]; $i++) {
$form_block .="
<tr>
<td align=center><input type=\"texr\" name=\"field name[]\"
size=\"30\"></td>
<td align=center>
<select name=\"field_type[]\">
<option value=\"char\">char</option>
<option value=\"date\">date</option>
<option value=\"float\">float</option>
<option value=\"int\">int</option>
<option value=\"text\">text</option>
<option value=\"varchar\">varchar</option>
</select>
</td>
<td align=center><input type=\"text\" name=\"field_length[]\" size=\"5\">
</td>
</tr>";
}
//finish up the form
$form_block .= "
<tr>
<td align=center colspan=3><input type =\"submit\" value=\"create table\">
</td>
</tr>
</table>
</form>";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Create a database table: Step 2</title>
</head>
<body>
<h1>defnie fields for <? echo "$_POST[table_name]"; ?>
</h1>
<? echo "$form_block"; ?>
</body>
</html>
Problem is here
3) this form creates the tables and enteres them into the database.
I am getting an error on line 37 "Parse error: syntax error, unexpected $end in /home/admin/domains/domaina.com.au/public_html/do_createtable.php on line 37"
<?
$db_name = "testDB";
$connection = #mysql_connect("localhost", "admin_user", "pass")
or die(mysql_error());
$db = #mysql_select_db($db_name, $connection)
or die(mysql_error());
$sql = "CREATE TABLE $_POST[table_name](";
for ($i = 0; $i < count($_POST[field_name]); $i++) {
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
if ($_POST[field_length][$i] !="") {
$sql .=" (".$_POST[field_length][$i]."),";
} else {
$sql .=",";
}
$sql = substr($sql, 0, -1);
$sql .= ")";
$result = mysql_query($sql, $connection) or die(mysql_error());
if ($result) {
$msg = "<p>" .$_POST[table_name]." has been created!</p>";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Create A Database Table: Step 3</title>
</head>
<body>
<h1>Adding table to <? echo "$db_name"; ?>...</h1>
<? echo "$msg"; ?>
</body>
</html>
$result = mysql_query($sql, $connection) or die(mysql_error());
if ($result) {
$msg = "<p>" .$_POST[table_name]." has been created!</p>";
}
you missing a } in your last if statement, and your for loop is missing a } too
for ($i = 0; $i < count($_POST[field_name]); $i++) {
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
if ($_POST[field_length][$i] !="") {
$sql .=" (".$_POST[field_length][$i]."),";
} else {
$sql .=",";
}
}
This error message means that a control structure block isn’t closed properly. In your case the closing } of some of your control structures like the for loop or the last if are missing.
You should use proper indentation and an editor that highlights bracket pairs to have a visual aid to avoid such errors.
You must close the for expression block:
for ($i = 0; $i < count($_POST[field_name]); $i++) {
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
// ...
}
Your for loop is not terminated. You are missing a }
for ($i = 0; $i < count($_POST[field_name]); $i++) {
$sql .= $_POST[field_name][$i]." ".$_POST[field_type][$i];
}
And as pointed by others there is also a missing } for the last if statement:
if ($result) {
$msg = "< p>" .$_POST[table_name]." has been created!< /p>";
}
 
in your php.ini (php configuration) change :
short_open_tag = Off
you opened php tag shortly at line 1
just find and replace all <? with <?php
Stylistic tip: Use HEREDOCs to assign blocks of text to a variable, instead of the hideous multi-line-with-tons-of-escaping-backslashes constructs you're using. They're far easier to read and less error prone if/when you happen to forget a \ somewhere and break the script with a parse error.
I just solved this error, after checking my code, I had no open tags/braces.
For me, I got this error when moving to a amazon server.
It turns out I needed to enable short_open_tag = On in my php.ini.
This solved this error for me.

Categories