Jump to content

proper mysql_query function syntax??


deed02392

Recommended Posts

<?php


include 'library/config.php';
include 'library/opendb.php';

$userId = $_POST['txtUserId'];
$userPass = $_POST['txtUserPass'];

//this code but replace the preset input to a form dependant value
$insert = 'INSERT INTO tbl_auth_user (user_id, user_password) VALUES (\'theadmin\', PASSWORD(\'chumbawamba\'));';

//my attempt not working...
$insert = 'INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('$userId', PASSWORD('$userPass'));';

$result = mysql_query($insert)
or die('Query failed. ' . mysql_error());

include 'library/closedb.php';

?>

 

Hi, I'm trying to build a registration form with mysql, I used phpmyadmin to generate me some php from entries that i made in a mysql query box, and it made that. I'm desperately trying to reword it so that it will swap the 'theadmin' string to the variable, which pulls it out of a form. The same for the password. After about 20 minutes i managed to get it working but it would just add $userId to the table rather than actually getting it from the post?? Do I need some special way of entering it in there for it to properly add? Thanks

Link to comment
Share on other sites

Query failed. 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 on earth? There is no php on line 1!

The line number refers to your sql query and not your PHP code. Remember when using mysql_error() the generated error reported is coming from mysql and not php.

Link to comment
Share on other sites

Thank you, it now works without error. Unfortunately when it posts the data to the database it doesn't encrypt the password with mysql's built in encryption cipher. So it just posts the password as text. How can i alter the queries string so that it encrypts it? I'm sure the function is PASSWORD() but i'm not sure how to integrate it into this line:

 

$insert = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "');";

 

 

Oh and I forgot to add, although it successfuly puts data into the database, it also adds a blank entry?! Why is this string doing that?

MySQL is difficult  :'(

 

Thanks!

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.