| | |
A little problem with a script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 23
Reputation:
Solved Threads: 0
Hi guys.I am new to web development and of course I have been experiensing some problems.Most of them are easy to solve and I usually find my way, but there is some thing that is getting on my nerves for some time now.
I have been trying to make a simple script for registering a user via MySQL.No filtering input, no validating only the part that adds the new user into the MySQL table. But it doesn't work.I have checked my code a couple of times and i can't see the problem.Here it is:
I have been trying to make a simple script for registering a user via MySQL.No filtering input, no validating only the part that adds the new user into the MySQL table. But it doesn't work.I have checked my code a couple of times and i can't see the problem.Here it is:
PHP Syntax (Toggle Plain Text)
<?php if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"])) { $name=$_POST["name"]; $pass=$_POST["pass"]; $email=$_POST["email"]; $con=mysql_connect('localhost','root','password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("users", $con); mysql_query("INSERT INTO members (username,password,email) values ('$name','$pass','$email')") or die('Error'); } ?>
try this:
if this script doesn't fix the problem, post the mysql error message and i will help you from there.
PHP Syntax (Toggle Plain Text)
<?php if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"])) { $name=$_POST["name"]; $pass=$_POST["pass"]; $email=$_POST["email"]; $con=mysql_connect('localhost','root','password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("users", $con); $sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')"; $query = mysql_query($sql,$con) or die('Error: ' . mysql_error()); } ?>
if this script doesn't fix the problem, post the mysql error message and i will help you from there.
•
•
Join Date: Jan 2008
Posts: 23
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
<?php if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"])) { $name=$_POST["name"]; $pass=$_POST["pass"]; $email=$_POST["email"]; $con=mysql_connect('localhost','root','password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("users", $con); $sql = "INSERT INTO `members` (username,password,email) VALUES ('" . $name . "','" . $pass . "','" . $email . "')"; $query = mysql_query($sql,$con) or die('Error: ' . mysql_error()); } ?> <html> <body> <form action="register.php" method="post"> Username: <input type="text" name="name" /></br> Password: <input type="password" name="pass" /></br> Email: <input type="text" name="email" width=40 /></br> <input type="submit" /> </form> </body> </html>
Is it inserting the data into the database.Of course,it will display blank because you have not triggered something to display if it is inserted correctly.try to replace this part:
with this:
php Syntax (Toggle Plain Text)
$query = mysql_query($sql,$con) or die('Error: ' . mysql_error());
with this:
php Syntax (Toggle Plain Text)
$query = mysql_query($sql); if (!$query) { echo 'Error: ' . mysql_error(); } else { echo 'Inserted correctly.'; }
change this line:
to this:
then add a name in your form button
See if that helps.
By the way,is this page the register.php page?
php Syntax (Toggle Plain Text)
if(isset($_POST["name"]) && isset($_POST["pass"]) && isset($_POST["email"]))
to this:
php Syntax (Toggle Plain Text)
if ($_POST['Submit'])
then add a name in your form button
php Syntax (Toggle Plain Text)
<input type="submit" name="Submit" />
See if that helps.
By the way,is this page the register.php page?
Try this..
php Syntax (Toggle Plain Text)
<?php if(isset($_POST['submit'])){ if(!empty($_POST["name"]) && !empty($_POST["pass"]) && !empty($_POST["email"])) { $name=$_POST["name"]; $pass=$_POST["pass"]; $email=$_POST["email"]; $con=mysql_connect('localhost','root','password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("users"); $sql = "INSERT INTO members (username,password,email) VALUES ('$name','$pass','$email')"; $query = mysql_query($sql) or die('Error: ' . mysql_error()); echo "Inserted successfully !"; } else { echo "Fields can't be empty !"; } } ?> <html> <body> <form action="register.php" method="post"> Username: <input type="text" name="name" /></br> Password: <input type="password" name="pass" /></br> Email: <input type="text" name="email" width=40 /></br> <input type="submit" name="submit" value="submit" /> </form> </body> </html>
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Learning PHP but problem with script (PHP)
- [Bash] problem with script in sed command (Shell Scripting)
- Minor problem with some script... (C)
- Large Array Problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP sort control
- Next Thread: Ajax Problem
| Thread Tools | Search this Thread |
apache api array basic beginner body broken cache cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic email error file filter folder form forms forum function functions gc_maxlifetime google header headmethod howtowriteathesis href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu msqli_multi_query multiple mycodeisbad mysql navigation neutrality oop parameter parsing paypal pdf php phpmysql play query question random recourse regex root script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube







