Current location: Hot Scripts Forums » General Community » Script Requests » database input error


database input error

Reply
  #1 (permalink)  
Old 03-29-05, 04:23 AM
mistrym1 mistrym1 is offline
New Member
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Cool database input error

hi, i have created a simple page in php to add users to a database. you can enter all the details, i.e. first name, surname, username etc, but when submitted it adds two user records to database instead of just one. its something simple is it possibel for anyone to help? here are the two scripts

file name: addform.php

<?php

##Register Student

echo "<h1> StudentRegister </h1>";

echo "<form method = 'Post' action='addstudent.php' >";

echo "<p><b>First Name:</b> <input type='text' name='first_name' size='15' maxlength='15' value='' /></p>";

echo "<p><b>Last Name:</b> <input type='text' name='surname' size='30' maxlength='30' value='' /></p>";

echo "<p><b>User Name:</b> <input type='text' name='username' size='10' maxlength='20' value=' ' /></p>";

echo "<p><b>Password:</b> <input type='password' name='password1' size='20' maxlength='20' /> <small></p>";

echo "<p><b>Confirm Password:</b> <input type='password' name='password2' size='20' maxlength='20' /></p>";
//echo "</fieldset>";

echo "<div align='center'><input type='submit' name='submit' value='Register' /></div>";

?>



filename : addstudent.php

<?php


##ADD STUDENT

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("cybercbt") or die(mysql_error());

$Firstname=$_POST['first_name'];
$Surname=$_POST['surname'];
$Username=$_POST['username'];
$Password1=$_POST['password1'];
$Password2=$_POST['password2'];

IF ((!$Firstname) || (!$Surname) || (!$Username) || (!$Password1) || (!$Password2))

{
Echo "Please Enter Values Into All fields";
}
ELSE IF ($Password1!=$Password2)
{
echo "Passwords Dont Match!!!";
exit();
}

$query = "INSERT INTO student(first_name, surname, username, password) VALUES ('$Firstname', '$Surname', '$Username', '$Password1')";
$result = @mysql_query($query); // Run the query

$result=mysql_query($query) or die(mysql_error());

IF (!$result)
{
echo "There has been a problem updating this record";
}
ELSE
{
echo "<br>";

ECHO "<CENTER>";
echo "<H1>Record Updated Successfully<H1>";
ECHO "</CENTER>";

}

?>
Reply With Quote
  #2 (permalink)  
Old 03-29-05, 05:02 AM
frank1965 frank1965 is offline
New Member
 
Join Date: Mar 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
You are xecuting the query twice!
...
$result = @mysql_query($query); // Run the query

$result=mysql_query($query) or die(mysql_error());

....

Just use only one of the statements above. The "@" in front of mysql_query does mean that no system messages are generated in the event of a failure.

Regards.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
ASP Database search - help - Error bookemdanno ASP 4 01-05-05 10:27 AM
error when creating database tables with php script spiroth10 PHP 4 01-06-04 03:59 PM
[php error] parse error | fatal error xeoHosting PHP 1 01-03-04 08:12 PM


All times are GMT -5. The time now is 11:40 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.