Jump to content

write to SQL table not working.


adzi

Recommended Posts

Hi,

I'm pretty new to the whole PHP coding side of websites. I'm trying to create a very simple, very basic members login system for my website where only registered members can access. It doesnt have to be 100% secure at the moment as that's what Im looking to improve but I cant seem to get the fundamentals sorted.

 

This is my register.html code, with a simple form capturing the data.

<form name="register" method="post" action="register.php">
<input name="register_name" type="text" value="username" size="20"/><br>
<input name="register_password" type="password" value="password" size="20"/><br>
<input name="password_reminder" type="text" value="password reminder" size="20"/><br>
<input name="register_email" type="text" value="email" size="50"/><br>
<input type="submit" name="submit" value="submit"/>
<input type="reset" name="reset" value="reset"/>
</form>

 

Here's my register.php page thats called when the submit button is hit.

<?php
$register_name = $_POST['register_name'];
$register_password = $_POST['register_password'];
$register_email = $_POST['register_email'];
$password_reminder = $_POST['password_reminder'];

@mysql_connect("localhost", "My Database User", "My database password") or die("Cannot connect to database.");
@mysql_select_db("centrest_members") or die("Cannot select database");
$insert = mysql_query("insert into users values ('NULL','".addslashes($register_name)."', 
'".sha1($register_password)."','".$password_reminder."','".$register_email."')")
or die("Could not insert data because ".mysql_error());
?>

 

I get the error,

Parse error: syntax error, unexpected T_VARIABLE in /home/centrest/public_html/adzi/register.php on line 2

 

Can anyone help as to why this is happening?

 

Thanks,

Adzi

 

Edit:

 

This is my SQL table structure;

 

id smallint(6) auto_increment               
register_name varchar(15)                 
register_password varchar(20)                 
register_email varchar(50)              
password_reminder varchar(30)

             

 

 

Link to comment
https://forums.phpfreaks.com/topic/80987-write-to-sql-table-not-working/
Share on other sites

See if renaming it helps

 

$register_name = $_POST['register_name'];

 

to

 

$name = $_POST['name'];

 

and change your form and sql statement to match.

 

Echo the $_POST variable to see its data.

 

Try having data instead of the $_POST variable, like

 

$register_name = "hi";

 

Using a normal text editor?

 

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.