Hi,

Iv'e been reading through all the different posts and searching the web all day and I am not sure what went wrong I am getting this error

"Parse error: syntax error, unexpected T_STRING in /home/gamersh1/public_html/database/register.php on line 9"

Code: Register.php

<?php
include ('mysql.php');

if(isset($_POST['submit'])){
          $username = ($_POST['username']);
          $password = ($_POST['password']);
		  
		     $sql = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate)
								   VALUES("hi","$username","$password","beta")
								   ?>			 
<form action="register.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="submit" value="Register">
</form>

And the i also have my mysql connect page: mysql.php

<?php


$host = 'localhost';  // mysql server domain
$user = 'root';      // mysql username
$pass = 'root';     // mysql password
$db = 'dinopanel';  // mysql database name

'$connect' = '@mysql_connect($host,$user,$pass) or die ('Error connecting to database'))'

$select = @mysql_sellect_db($db,$connect) or die ('Error selecting database');

?>

Can any of you see any errors in this I am new to php and mysql

Recommended Answers

All 10 Replies

Do it in the following way.

$sql_query = "INSERT INTO users (user_id, username, user_password, user_regdate) VALUES ('hi',".$username.",".$password.",'beta')";

mysql_query($sql_query);

You are getting the error coz the double quote which appears just before the value 'hi' marks the end of the string. I always suggest that assign the queries to a variable and then use that variable in mysql_query() function.

Hope this helps!

Try this too

$Result = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate) VALUES ('hi',". $username .",". $password .",'beta')");

. is use for concatination

Hi,
There is problem with php syntax.You were using double quotes without worry of concatenation.Whenever you uses double quotes it should be properly ended and text should be enclosed properly.
Also if you are using any column's datatype as varchar in a database please use single quotes to enclose values in a query while writing application logic/code.
I think your query should be like this

<?php
$sql = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate)
VALUES('hi',' ".$username." ',' ".$password." ','beta')");

mysql_query($sql);
?>

Please let me know if you have problem with this query in your code.

Hi,
There is problem with php syntax.You were using double quotes without worry of concatenation.Whenever you uses double quotes it should be properly ended and text should be enclosed properly.
Also if you are using any column's datatype as varchar in a database please use single quotes to enclose values in a query while writing application logic/code.
I think your query should be like this

<?php
$sql = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate)
VALUES('hi',' ".$username." ',' ".$password." ','beta')");

mysql_query($sql);
?>

Please let me know if you have problem with this query in your code.

you write it

mysql_query($sql);

2 times,. why?

Hi,
Sorry for wrong code.By mistake.I though $sql variable contains only string without any sql function.
I think this would be right

<?php
      $sql = "INSERT INTO users (user_id, username, user_password, user_regdate)
      VALUES('hi',' ".$username." ',' ".$password." ','beta')";
      mysql_query($sql);
      ?>
#
<?php
#
$sql = "INSERT INTO users (user_id, username, user_password, user_regdate)
#
VALUES('hi',' ".$username." ',' ".$password." ','beta')";
#
mysql_query($sql);
#
?>
User id must be any integer value and your are giving characters in it
User id must be any integer value and your are giving characters in it

Hi BzzBee,
I have put 'hi' instead of integer because I have use same query written by thread writer who needs solution.And I also dont know what data type has used for user_id.
No any other reason.

Try the following as you had a few bugs...

<?php
include ('mysql.php');

if(isset($_POST['submit'])){
      $username = mysql_real_escape_string($_POST['username']);
      $password = mysql_real_escape_string($_POST['password']);	  
      $sql = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate) VALUES('hi','$username','$password','beta')");
?>			 
<form action="register.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="submit" value="Register">
</form>

Hi,

Iv'e been reading through all the different posts and searching the web all day and I am not sure what went wrong I am getting this error

"Parse error: syntax error, unexpected T_STRING in /home/gamersh1/public_html/database/register.php on line 9"

Code: Register.php

<?php
include ('mysql.php');

if(isset($_POST['submit'])){
          $username = ($_POST['username']);
          $password = ($_POST['password']);
		  
		     $sql = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate)
								   VALUES("hi","$username","$password","beta")
								   ?>			 
<form action="register.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="submit" value="Register">
</form>

And the i also have my mysql connect page: mysql.php

<?php


$host = 'localhost';  // mysql server domain
$user = 'root';      // mysql username
$pass = 'root';     // mysql password
$db = 'dinopanel';  // mysql database name

'$connect' = '@mysql_connect($host,$user,$pass) or die ('Error connecting to database'))'

$select = @mysql_sellect_db($db,$connect) or die ('Error selecting database');

?>

Can any of you see any errors in this I am new to php and mysql

just changed double quotes(") VALUES("hi","$username","$password","beta") to single qoute(').

ei wait something still wrong... after you changed double qoutes to single qoutes... put a double qoute on after the close parenthesis... here this is the correct syntax.

$sql = mysql_query("INSERT INTO users (user_id, username, user_password, user_regdate) VALUES('hi','$username','$password','beta')");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.