Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Insert Issue

General discussions related to php

Moderators: macek, egami, gesf

Insert Issue

Postby Atkinson1988 » Tue Jun 05, 2012 1:36 am

Hi All,

I have a problem with this insert statement, iv only been doing php for the past two days so please bare with me,

I have a mysql database which is called accounts, which has a table in it called users and im trying to insert information the user has entered into that table.

but it keeps throwing a http 500 internal server error.....

This is my Form where the user inputs the information

Code: Select all
<html>
<head>
<title> Update Database</title>
</head>
<body>
<form method="post" action="Update.php">

FirstName:<br/>

<input type="text" name="Fname" size="30"/><br/>

LastName:<br/>

<input type="text" name="Lname" size="30"/><br/>

UserName:<br/>

<input type="text" name="UName" size="30"/><br/>

Password:<br/>

<input type="text" name="Password" size="30"/><br/>


<input type="submit" value="Create User"/>

</form>
</body>
</html>

And this is where im trying to insert the information in to the users table

Code: Select all
<?php
$Firstname = $_POST['Fname'];
$Surname = $_POST['Lname'];
$UserName = $_POST['UName'];
$Password = $_POST['Password'];

$Valid = mysql_connect('localhost:3306' , 'root' , 'password123');

if(!$Valid)
{
   echo 'Could not connect' . mysql_error();
}
else
{
   mysql_select_db('accounts', $Valid) or die('could not select database');
   
   $query = "INSERT INTO `users` (`UserName`, `Password`, `FirstName`, `Surname`) VALUES ('".$UserName."' , '".$Password."' , '".$FirstName."' , '".$Surname."')"; 
   
   mysql_query($query, $Valid) or die('Error Adding the users details.');
   
   echo "The following user " . $Firstname "has been added to the database";
}
?>



Iv attached an image which shows my database and table.....

any help would be appreciated.
Attachments
mySQLTable.PNG
mySQLTable.PNG (7.24 KiB) Viewed 106 times
Atkinson1988
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Jun 05, 2012 1:31 am

Re: Insert Issue

Postby ejsexton82 » Tue Jun 05, 2012 1:45 am

You might be missing a period on the following line:

Code: Select all
// Incorrect
echo "The following user " . $Firstname "has been added to the database";

// Correct
echo "The following user " . $Firstname . "has been added to the database";
User avatar
ejsexton82
New php-forum User
New php-forum User
 
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: Insert Issue

Postby Atkinson1988 » Tue Jun 05, 2012 1:48 am

Thank you ejsexton82 its now working!!!
Atkinson1988
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Jun 05, 2012 1:31 am

Re: Insert Issue

Postby Nullsig » Tue Jun 05, 2012 7:09 am

I am always worried about missing periods after I perform an insertion.... :D
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron