Jump to content

Archived

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

pocobueno1388

Phpmyadmin messing up SQL...?

Recommended Posts

I am using Phpmyadmin to build my tables, but yet when I submit a form from my website to add information in my tables I get this error:

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 4

I did not manually create this SQL, so I don't know how phpmyadmin could mess it up. Is this an SQL problem or is it my script? From the error message it seems like the SQL and database is where the problem is.

If you could help me with this, that woud be great.

By the way, I am hosting with godaddy.com, not sure if that will help or not. Maybe they don't support something. I don't know. I a fairly new to programming, but I didn't know I could have a problem like this with phpmyadmin(if that is really the problem.).

Thanks in advance for you help =D

Share this post


Link to post
Share on other sites
Don't waste your time letting it do that for you, sql itself is very simple to learn, it's when you are using php to access sql is when it starts getting hard, go to someplace with simple to understand sql syntax if you are trying to just create a table just do
CREATE TABLE tablenamehere
and it will create a table, build onto that to do more with your tables, if you need more help just ask, BUT BE SPECIFIC.
Like something specific you want to do.

Share this post


Link to post
Share on other sites
Well...I am trying to access the table through php, but I am sure I don't have it wrong. Why would I need to create the table using PHP when I already have it created? I know how to build a table from scratch with SQL, but not with php. So I guess I am not sure what to do with your advice.

Share this post


Link to post
Share on other sites
Your query is not correct. Print it out and try to check out what is not correct.
Or post your script here.

Share this post


Link to post
Share on other sites
<?php
include "config.php";
include "header.php";

if($_POST['login_name']){

// Define post fields into simple variables
$loginname = $_POST['login_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$vpassword = $_POST['vpassword'];
$email = $_POST['email'];

/* Let's strip some slashes in case the user entered
any escaped characters. */

$loginname = stripslashes($login_name);
$username = stripslashes($username);
$password = stripslashes($password);
$vpassword = stripslashes($vpassword);
$email = stripslashes($email);


/* Do some error checking on the form posted fields */

if((!$loginname) || (!$username) || (!$password) || (!$email)){
echo 'You did not submit the following required information! <br />';
if(!$login_name){
echo "Login Name is a required field. Please enter it below.<br />";
}
if(!$username){
echo "Desired Username is a required field. Please enter it below.<br />";
}
if(!$password){
echo "Password is a required field. Please enter it below.
";
}
if(!$email){
echo "Email is a required field. Please enter it below.<br />";
}
include 'join_form.html'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}

/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */

$sql_email_check = mysql_query("SELECT email FROM players
WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM players
WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

if(($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($email_check > 0){
echo "<strong>Your email address has already been used by another member
in our database. Please submit a different Email address!<br />";
unset($email_address);
}
if($username_check > 0){
echo "The username you have selected has already been used by another member
in our database. Please choose a different Username!<br />";
unset($username);
}
include 'join_form.html'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}

/* Everything has passed both error checks that we have done.
It's time to create the account! */

// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (loginname, username,
password, vpassword, email)
VALUES('$loginname', '$username', '$password',
'$vpassword', '$email'")
or die (mysql_error());

if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
$userid = mysql_insert_id();
// Let's mail the user!
$subject = "Dog Game";
$message = "Hello $username,
Thank you for registering at our website, www..com

you will be able to login
with the following information:
Username: $username
Password: $password

Thanks!
Colin (Game Owner/creator)

This is an automated response, please do not reply!";

mail($email, $subject, $message,
"From: Dogs Webmaster<colin@mydomain.com>\n
X-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address!
Please check it and follow the directions!';
}
exit;
}
?>

<form name="form1" method="post" action="join_form.php">
<table border="0" cellpadding="4" cellspacing="0" width="100%" valign="center">
<tbody><tr>
<td align="left" valign="top" width="24%">Login Name</td>

<td width="76%"><input name="login_name" id="loginname" value="" type="text"></td>
</tr>
<tr>
<td align="left" valign="top">Desired Username</td>
<td><input name="username" id="username" value="" type="text"></td>
</tr>
<tr>
<td align="left" valign="top">Password</td>
<td><input name="password" id="password" value="" type="password"></td>

</tr>
<tr>
<td align="left" valign="top">Re-type Password</td>
<td><input name="vpassword" id="vpassword" value="" type="password"></td>
</tr>
<tr>
<td align="left" valign="top">Email</td>
<td><input name="email" id="email" value="" type="text"></td>

</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
<td><input name="Submit" value="Join Now!" type="submit"></td>
</tr>
</tbody></table>
</form>

Share this post


Link to post
Share on other sites
Which query are you getting this error for? Just post the SQL statement and the corresponding error, not all of the PHP code.

Share this post


Link to post
Share on other sites
Here is the query:

$sql = mysql_query("INSERT INTO users (loginname, username,
password, vpassword, email)
VALUES('$loginname', '$username', '$password',
'$vpassword', '$email'")
or die (mysql_error());

Here is the error:

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 4

Share this post


Link to post
Share on other sites
[!--quoteo(post=386017:date=Jun 20 2006, 10:02 AM:name=Colin1388)--][div class=\'quotetop\']QUOTE(Colin1388 @ Jun 20 2006, 10:02 AM) [snapback]386017[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Here is the query:

$sql = mysql_query("INSERT INTO users (loginname, username,
password, vpassword, email)
VALUES('$loginname', '$username', '$password',
'$vpassword', '$email'")
or die (mysql_error());

Here is the error:

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 4
[/quote]
Post the value of the statement itself, not the PHP code that generates it... the error will be quite obvious.

Share this post


Link to post
Share on other sites
I guess I don't understand. The values will be what the user enters, so I really can't give you a straight answer on that.

Share this post


Link to post
Share on other sites
businessman332211 - When I do that the entire page just goes blank. So they obviously need to be there. This is so frustrating.

Share this post


Link to post
Share on other sites
Try to change this:

[code]$sql = mysql_query("INSERT INTO users (loginname, username,
password, vpassword, email)
VALUES('$loginname', '$username', '$password',
'$vpassword', '$email'")
or die (mysql_error());[/code]

To:

[code]$sql = mysql_query("INSERT INTO users (loginname, username, password, vpassword, email)
VALUES('$loginname', '$username', '$password', '$vpassword', '$email')") or die (mysql_error());[/code]

Share this post


Link to post
Share on other sites
poirot has solved all my problems =D I have gotten so many things done today, thanks to poirot. -worships- Thank you so much. I should have caught that error myself, but I am rather new...so my eyes are not trained enough yet to see those kinds of mistakes. I am sure I will be needing help again soon with something else, I will probably be having a lot more questions as I go through my current project.

Share this post


Link to post
Share on other sites
[!--quoteo(post=387084:date=Jun 23 2006, 01:33 AM:name=Colin1388)--][div class=\'quotetop\']QUOTE(Colin1388 @ Jun 23 2006, 01:33 AM) [snapback]387084[/snapback][/div][div class=\'quotemain\'][!--quotec--]
poirot has solved all my problems =D I have gotten so many things done today, thanks to poirot. -worships- Thank you so much. I should have caught that error myself, but I am rather new...so my eyes are not trained enough yet to see those kinds of mistakes. I am sure I will be needing help again soon with something else, I will probably be having a lot more questions as I go through my current project.
[/quote]
FYI, if you keep your SQL statements in their own string variables, it will be much easier to echo them to the browser for debugging -- it would have been trivial to see that your string was closing too soon.

Share this post


Link to post
Share on other sites

×

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.