0

Hello, I need help with this. If in my form i put this,

<td><input type="text" name"Example" id="Example"></td>

and my sql what would i put? Mine is,

$insertQuery = "ALTER TABLE atable ADD column '$example' INT";

this is the error shown, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' INT' at line 1. I tried many ways but cannot put in the correct syntax. Please help, Thanks.

4
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by almostbob
0

Thank you for your help, but it doesn't work. Now the error become

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT' at line 1

0

Try below code. And post output you are getting.

<?
$insertQuery = "ALTER TABLE atable ADD `".$example."` INT";
$result = mysql_query($insertQuery);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
else
{
	echo 'Successfully executed';
}
?>
0

They stated,

Incorrect column name ''

what does this mean?

0

where is $example defined?
I think form posted value is not stored properly in $example variable.
post your code where you are assigning value to $example.

0

<form method="post" action="index.php">
<td><label for="example">example</label></td>
<td><input type="text" name="example" id="example"></td>
<td><input type="submit" value="Register"> </td>

0

This is html form. I was asking for php code.
Try below code.

<?
if(isset($_POST['example']])
{
    $example = $_POST['example'];
	if($example=="")
	{
		echo "Field name can not be blank.";
		exit;
	}
    $insertQuery = "ALTER TABLE atable ADD `".$example."` INT";
	$result = mysql_query($insertQuery);
	if (!$result)
	{
		die('Invalid query: ' . mysql_error());
	}
	else
	{
		echo 'Successfully altered';
		exit;
	}
}
?>

Edited by vibhaJ: n/a

0

Sorry, I'm quite new at this. Might not be able to understand what you are asking for. However, I tried to include that and the same error occur.

0

This is html form. I was asking for php code.
Try below code.

<?
if(isset($_POST['example']])
{
    $example = $_POST['example'];
	if($example=="")
	{
		echo "Field name can not be blank.";
		exit;
	}
    $insertQuery = "ALTER TABLE atable ADD `".$example."` INT";
	$result = mysql_query($insertQuery);
	if (!$result)
	{
		die('Invalid query: ' . mysql_error());
	}
	else
	{
		echo 'Successfully altered';
		exit;
	}
}
?>

When you add this code, what message do you see on screen?

0

Hey, Thanks a lot for your help. I found out in the end the caps that i put some the first word caps so they cant locate ><

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.