/    Sign up×
Community /Pin to ProfileBookmark

Inserting infor into the database

The script won’t insert values into my database. it doesn’t give out any error messages. the page displays the info the user input into the form. im using the same connection variables as before so i don’t think there is anything wrong with them

[code=php]<?php

$Username = $_POST[‘Account_Username’];
$Password = $_POST[‘Account_Password’];
$ConfirmP = $_POST[‘Account_PasswordConfirm’];
$FullName = $_POST[‘Contact_FullName’];
$Address1 = $_POST[‘Contact_StreetAddress’];
$Address2 = $_POST[‘Contact_Address2’];
$City = $_POST[‘Contact_City’];
$Province = $_POST[‘Contact_Province’];
$Country = $_POST[‘Contact_Country’];
$Email = $_POST[‘Contact_Email’];

$self = $_SERVER[‘PHP_SELF’];
$referer = $_SERVER[‘HTTP_REFERER’];

if((!$Username) or (!$Password) or (!$ConfirmP) or (!$Email) or (!$FullName))
{
#if the fields required were empty then return to refernce page
header(“Location:$referer”);
exit();

if($Password == $ConfirmP)
{
#submit details into database if the passwords match
echo(“The passwords matched”);

#connect to MySQL
$conn = @mysql_connect(“#”, “#”,”#”)
or die(“Could not Connect”);
#select the specified database
$rs = @mysql_select_db(“lynchmc”, $conn)
or die(“Could not select specified”);

#create the sql query
$sql = “INSERT INTO users
(Username, Password, FullName, Address1, Address2, City, Province, Country, Email)
VALUES
(‘$Username’, PASSWORD(‘$Password’), ‘$FullName’, ‘$Address1’, ‘$Address2’, ‘$City’, ‘$Province’, ‘$Country’, ‘$Email’)”;

#execute the query
$res = mysql_query($sql, $conn)
or die (“Could not execute query: “.mysql_error());

if($res == true) {
echo (“Done”);
}
else
{
echo(“Didn’t work”);
}

}
else{
#send back to registration with all fields still there except passwords
header(“Location:$referer”);
exit();
}
}
?><html><head><title>Registration Page</title></head>
<body>
<hr>
<?
echo(“$Username<br>”);
echo(“$Password<br>”);
echo(“$ConfirmP<br>”);
echo(“$FullName<br>”);
echo(“$Address1<br>”);
echo(“$Address2<br>”);
echo(“$Province<br>”);
echo(“$Country<br>”);
echo(“$Email<br>”);
?>
</body></html>[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@grumpyoldtechsMar 03.2007 — Firstly your open to SQL injection if i'm right.

also i dont see your need to escape the post superglobal at that point.

you need to check your brackets this was open thus sending it back to the referral before it could execute the sql query
[code=php]
if((!$Username) or (!$Password) or (!$ConfirmP) or (!$Email) or (!$FullName))
{
#if the fields required were empty then return to refernce page
header("Location:$referer");
exit();
}
[/code]
Copy linkTweet thisAlerts:
@Marcus_MaximusauthorMar 04.2007 — it works when i take it out but i do i make sure that they have entered data into the required fields
Copy linkTweet thisAlerts:
@Marcus_MaximusauthorMar 04.2007 — done it its ok but is there a way i can return them without clearing the fields
Copy linkTweet thisAlerts:
@grumpyoldtechsMar 04.2007 — you can still use $_POST
Copy linkTweet thisAlerts:
@Marcus_MaximusauthorMar 04.2007 — in what way

$Account_Username = $_POST['Username'];

on the registration page

will that work
×

Success!

Help @Marcus_Maximus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...