Jump to content

[SOLVED] SYntax to use near ")" on mysql 4.1.21


ruuyx

Recommended Posts

Hi I'm pretty new to this and tried to install a Login system to my website. I got 7 php files online that i have edited to my requirements and have created a database on my host. while trying to fill out the register.html file online and running it ( register.php..background) i got this message:  Could not insert data because 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 ')' at line 1

 

what can i do to correct this error so the register.html will load registration infos to the table?

 

this is what my register.php and config.php looks like

 

<?php

 

include("config.php");

 

// connect to the mysql server

$link = mysql_connect($server, $db_user, $db_pass)

or die ("Could not connect to mysql because ".mysql_error());

 

// select the database

mysql_select_db($database)

or die ("Could not select database because ".mysql_error());

 

// check if the username is taken

$check = "select id from $table where username = '".$_POST['username']."';";

$qry = mysql_query($check)

or die ("Could not match data because ".mysql_error());

$num_rows = mysql_num_rows($qry);

if ($num_rows != 0) {

echo "Sorry, there the username $username is already taken.<br>";

echo "<a href=register.html>Try again</a>";

exit;

} else {

 

// insert the data

$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['firstname']."', '".$_POST['lastname']."',

// print a success message

echo "Your user account has been created!<br>";

echo "Now you can <a href=login.html>log in</a>";

}

 

?>

 

[attachment deleted by admin]

Link to comment
Share on other sites

$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['firstname']."', '".$_POST['lastname']."'");

 

I *hate* convoluted concatenations.

 

As a guideline, separate the construction of the query from the execution and use sensible error trapping:

 

$query = "insert into $table values ...";
$result = mysql_query($query) or die("error: ". mysql_error(). " with query ". $query);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.