Jump to content


Photo

Phpmyadmin messing up SQL...?


  • Please log in to reply
15 replies to this topic

#1 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 19 June 2006 - 04:26 AM

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

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 June 2006 - 06:18 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 19 June 2006 - 11:34 PM

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.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 20 June 2006 - 12:21 AM

Your query is not correct. Print it out and try to check out what is not correct.
Or post your script here.
~ D Kuang

#5 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 20 June 2006 - 02:23 AM

<?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>



#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 20 June 2006 - 01:32 PM

Which query are you getting this error for? Just post the SQL statement and the corresponding error, not all of the PHP code.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 20 June 2006 - 02:02 PM

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


#8 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 20 June 2006 - 09:41 PM

I really want to get started, so I really want someone to help me :/

#9 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 June 2006 - 05:14 AM

[!--quoteo(post=386017:date=Jun 20 2006, 10:02 AM:name=Colin1388)--][div class=\'quotetop\']QUOTE(Colin1388 @ Jun 20 2006, 10:02 AM) View Post[/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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#10 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 21 June 2006 - 03:03 PM

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.


#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 21 June 2006 - 03:10 PM

'$email'")
get rid of those 2 quotation marks at the end just leave
'$email')

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 21 June 2006 - 05:45 PM

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

#13 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 22 June 2006 - 12:48 AM

Anyone have anymore ideas?

#14 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 22 June 2006 - 04:09 AM

Try to change this:

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

To:

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

~ D Kuang

#15 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 23 June 2006 - 05:33 AM

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.

#16 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 23 June 2006 - 07:40 AM

[!--quoteo(post=387084:date=Jun 23 2006, 01:33 AM:name=Colin1388)--][div class=\'quotetop\']QUOTE(Colin1388 @ Jun 23 2006, 01:33 AM) View Post[/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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users