Forum Moderators: coopster
I am attempting to write out a script that is dual purpose with the if and elseif conditions. If a visitor comes to addurl.php and fills out the form, it adds a new record to the database. I also have something setup so I can email someone and it takes them to addurl.php?linkx=10 (10 being the record number in the db for example). The person in the later example would actually be updating an existing record instead of adding a new one.
The form on addurl.php contains a hidden field to capture the current record id so it can be passed onto the script. This script does 2 things; sends an email out and does what it has to with the database. Overall the database doesnt add or update. I just get a blank screen instead of the header redirects working. Here's my script
require "../../dbconnect.php";//connect to db
//setup form items as variables
$name = $_POST['urname'];
$email = $_POST['uremail'];
$biz = $_POST['biztype'];
$theirsite = $_POST['website'];
$theirsitewords = $_POST['verbage'];
$mylink = $_POST['linkback'];
$active = $_POST['status'];
$submitted = $_POST['dateinsert'];
//email you recieve from person signing up
$to = "***@***.com";//put your email address here
$content .= "Name: $name\r\n";
$content .= "Email: $email\r\n";
$content .= "Type of website: $biz\r\n";
$content .= "Their link needs to point to: $theirsite\r\n";
$content .= "My link can be found at: $mylink\r\n";
$content .= "The following text will be visible as the link: $theirsitewords\r\n";
//add this sign up to the databaseif ($PHP_SELF == "addurl.php") {
$query = "INSERT INTO links (name, email, website, linkback, verbage, added, active, biztype ) VALUES ('$name', '$email', '$theirsite', '$mylink', '$theirsitewords', '$submitted', '$active', '$biz')";
mysql_query($query) or die('Error, insert query failed');
//send a thank you email to the person who signed up
$message .="Message to person.\r\n";
$message .="\r\n";
$message .="Thank you for your time,\r\n";
$message .="Person or company\r\n";
mail($email, "Link Exchange Request Received", $message);
//send them off to the thank you page
header ("location: ../../index.php?c=linkxsent");
//thats it!
}
//update this sign up in the database
elseif ($PHP_SELF == "addurl.php?linkx=") {//THIS MIGHT BE AN ISSUE
$addquery="UPDATE links SET name='" . $_POST['urname'] . "', email='" . $_POST['uremail'] . "', website='" . $_POST['website'] . "', linkback='" . $_POST['linkback'] . "', verbage='" . $_POST['verbage'] . "', active='Active', WHERE id='" . $_POST['con_id'] . "'";
mysql_query($addquery) or die('Error, insert query failed');
//send a thank you email to the person who signed up
$message .="Message to person.\r\n";
$message .="\r\n";
$message .="Thank you for your time,\r\n";
$message .="Person or company\r\n";
mail($email, "Link Exchange Request Completed", $message);
//send them off to the thank you page
header ("location: ../../index.php?c=linkxsent");
//all done!
}
Any suggestions?
if(isset($_GET['linkx')) && (int)$_GET['linkx']){
//Check if POST are ok and
//do the UPDATE STUFF
elseif(!isset($_GET['linkx'))
{
//check the POST if the user really wants to insert new value
//and insert new value
}
If you don't check the post you can have security issues or spam.
And always use mysql_real_escape_string when putting something into a db
Best regards
Michal Cibor
Thanks for responding. Having some trouble with that code you gave me. Encountered this error off the code you gave me.
Parse error: parse error, unexpected ')', expecting ']'
I think I have cleaned it up some, please review
if(isset($_GET['linkx'])) && (int)$_GET['linkx'] {
if(isset($_GET['linkx'])) && (int)($_GET['linkx']){
}elseif(!isset($_GET['linkx'])){
Now I encounter Parse error: parse error, unexpected T_BOOLEAN_AND
ok we got past that part, now onto the next problem
Parse error: parse error, unexpected T_ELSEIF in /home/****/public_html/***/****/script.php on line 37
Line 37 is
} elseif (!isset($_GET['linkx'])){
Before we go any further though, I have a quick question. I noticed that linkx is used in both statements. The URL variable linkx is only to be used if its to update the database. The first operation is just if someone is on addurl.php, with no URL variable. Is this config going to work right?
require "../../dbconnect.php";//connect to db
//setup form items as variables
$name = $_POST['urname'];
$email = $_POST['uremail'];
$biz = $_POST['biztype'];
$theirsite = $_POST['website'];
$theirsitewords = $_POST['verbage'];
$mylink = $_POST['linkback'];
$active = $_POST['status'];
$submitted = $_POST['dateinsert'];
//email you recieve from person signing up
$to = "mattwebb@example.com";//put your email address here
$content .= "Name: $name\r\n";
$content .= "Email: $email\r\n";
$content .= "Type of website: $biz\r\n";
$content .= "Their link needs to point to: $theirsite\r\n";
$content .= "My link can be found at: $mylink\r\n";
$content .= "The following text will be visible as the link: $theirsitewords\r\n";if(isset($_GET['linkx']) && (int)$_GET['linkx']) {
$query = "INSERT INTO links (name, email, website, linkback, verbage, added, active, biztype ) VALUES ('$name', '$email', '$theirsite', '$mylink', '$theirsitewords', '$submitted', '$active', '$biz')";
mysql_query($query) or die('Error, that insert query failed');
//send a thank you email to the person who signed up
$message .="Your link exchange request has been received and is being processed. If you haven't already, please get our reciprocal link setup on your site ASAP. Otherwise, we will not approve the request. Please do not reply to this email, it is just to inform you that your submission was successful.\r\n";
$message .="\r\n";
$message .="Thank you for your time,\r\n";
$message .="Six Deep Studios\r\n";
mail($email, "Link Exchange Request Received", $message);
//send them off to the thank you page
header ("location: ../../index.php?c=linkxsent");
//thats it!
//update this sign up in the database
} elseif (!isset($_GET['linkx'])){
$addquery="UPDATE links SET name='" . $_POST['urname'] . "', email='" . $_POST['uremail'] . "', website='" . $_POST['website'] . "', linkback='" . $_POST['linkback'] . "', verbage='" . $_POST['verbage'] . "', active='Active', WHERE id='" . $_POST['con_id'] . "'";
mysql_query($addquery) or die('Error, this insert query failed');
//send a thank you email to the person who signed up
$message .="Thank you for exchanging links with me! If you haven't already, please get our reciprocal link setup on your site ASAP. Your link is already up on the page and visible to the world. Please do not reply to this email, it is just to inform you that your submission was successful.\r\n";
$message .="\r\n";
$message .="Thank you for your time,\r\n";
$message .="Six Deep Studios\r\n";
mail($email, "Link Exchange Request Completed", $message);
//send them off to the thank you page
header ("location: ../../index.php?c=linkxsent");
}
[edited by: jatar_k at 6:39 pm (utc) on Sep. 1, 2005]
[edit reason] examplified [/edit]
require "../../dbconnect.php";//connect to db
//setup form items as variables
$name = $_POST['urname'];
$email = $_POST['uremail'];
$biz = $_POST['biztype'];
$theirsite = $_POST['website'];
$theirsitewords = $_POST['verbage'];
$mylink = $_POST['linkback'];
$active = $_POST['status'];
$submitted = $_POST['dateinsert'];
//email you recieve from person signing up
$to = "mattwebb@example.com";//put your email address here
$content .= "Name: $name\r\n";
$content .= "Email: $email\r\n";
$content .= "Type of website: $biz\r\n";
$content .= "Their link needs to point to: $theirsite\r\n";
$content .= "My link can be found at: $mylink\r\n";
$content .= "The following text will be visible as the link: $theirsitewords\r\n";if(isset($_GET['linkx']) && (int)$_GET['linkx']) {
$addquery="UPDATE links SET name='" . $_POST['urname'] . "', email='" . $_POST['uremail'] . "', website='" . $_POST['website'] . "', linkback='" . $_POST['linkback'] . "', verbage='" . $_POST['verbage'] . "', active='Active', WHERE id='" . $_POST['con_id'] . "'";
mysql_query($addquery) or die('Error, this insert query failed');
//send a thank you email to the person who signed up
$message .="Thank you for exchanging links with me! If you haven't already, please get our reciprocal link setup on your site ASAP. Your link is already up on the page and visible to the world. Please do not reply to this email, it is just to inform you that your submission was successful.\r\n";
$message .="\r\n";
$message .="Thank you for your time,\r\n";
$message .="Six Deep Studios\r\n";
mail($email, "Link Exchange Request Completed", $message);
//send them off to the thank you page
header ("location: ../../index.php?c=linkxsent");} elseif (!isset($_GET['linkx'])){
$query = "INSERT INTO links (name, email, website, linkback, verbage, added, active, biztype ) VALUES ('$name', '$email', '$theirsite', '$mylink', '$theirsitewords', '$submitted', '$active', '$biz')";
mysql_query($query) or die('Error, that insert query failed');
//send a thank you email to the person who signed up
$message .="Your link exchange request has been received and is being processed. If you haven't already, please get our reciprocal link setup on your site ASAP. Otherwise, we will not approve the request. Please do not reply to this email, it is just to inform you that your submission was successful.\r\n";
$message .="\r\n";
$message .="Thank you for your time,\r\n";
$message .="Six Deep Studios\r\n";
mail($email, "Link Exchange Request Received", $message);
//send them off to the thank you page
header ("location: ../../index.php?c=linkxsent");
//thats it!
//update this sign up in the database}
Michal Cibor