Jump to content

Unexpected T_Variable/String......


Benaravo

Recommended Posts

Hey,

I posted a problem with the same script yetserday, attempting to sort it out my self... I've made some changes to the sytax of the MySQL Query mainly.. If you could take a look and see if there's anything obvious I've missed, it would be greatly appriciated!

The line which the error is on is 31, and also occasionally 24

24: $sql = 'insert into forum values('$usr','$pwd','$name','$admin',''';

31: echo( "Record Added" );




[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

</head>

<body>
<?php

$usr = $_POST['user'];
$pwd = $_POST['pass'];
$name = $_POST['name'];
$admin = $_POST['admin'];


$conn= @mysql_connect( "localhost","ben","/200791bp" )
or die( "Error, could not connect to MySQL" );

$rs = @mysql_select_db( "ben_login", $conn )
or die( mysql_error() );

$sql = 'insert into forum values('$usr','$pwd','$name','$admin',''';

$rs = mysql_query( $sql, $conn )
or die(mysql_error());

if($rs)
{
echo( "Record Added" );
}
else
{
echo('Error with MySQL Connection');
}
?>

</body>
</html>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/34342-unexpected-t_variablestring/
Share on other sites

[code=php:0]
$sql = "insert into forum values ('$usr','$pwd','$name','$admin')";
[/code]

Its also a bad habit not to explicitly name your fields. Your code should look more like...

[code=php:0]
$sql = "insert into forum (usr,pwd,`name`,admin) values('$usr','$pwd','$name','$admin')";
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.