Jump to content

Recommended Posts

Hi everybody, I'm a real noob at php but i try to muddle through as best I can.
Recently I had cause to make a webpage that includes a petition on it and i set it ut up like this.

I have a webpage with multiple form fields on it, one for name, address, email and comment.
I use php to connect to a mysql db that has all those fields in it and the script the checks if name and email exists, if they dont it inserts the form fields to a new entry, if they do exist it redirects to another page.

My problem is I seem to mess up the checking of the two fields part. I thought I'd been clever and set it up so that it checks if both fields exits in a given row but users can not add just a name without and email adress.

Any help here would be great, just keep in mind I am fairly new to php.

I will include my code here:


<?php

include "./scripts/config.php";
include "./scripts/opendb.php";


if(isset($_POST['add']))
{
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname,$conn) or die("Could not connect to db");

$navn = $_POST['navn'];
$adresse = $_POST['adresse'];
$email = $_POST['email'];
$kommentar = $_POST['kommentar'];

$query = "SELECT * FROM $table WHERE navn = '$navn' OR email = '$email'";
$result = mysql_query($query);
$numR = mysql_num_rows($result);

if($numR >= 1) {
header('Location: [a href=\"http://www.somesite.com/denied.html');\" target=\"_blank\"]http://www.somesite.com/denied.html');[/a]
}
else {
$query = "INSERT INTO $table (navn,adresse,email,kommentar) VALUES ('$navn','$adresse','$email','$kommentar')";
mysql_query($query,$conn) or die('Error, insert query failed'.mysql_error());

mysql_close();
header('Location: [a href=\"http://www.somesite.com/thankyou.html');\" target=\"_blank\"]http://www.somesite.com/thankyou.html');[/a]
}
}

After this i have another else statement that prints the form and such and after that there is a ?>
So the code analyzer in zend studio tells me it should be well formatted.

Caladan
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.