Jump to content

some errors


ianhaney50

Recommended Posts

Hi


 


I need bit of help on the edit.php page


 


I got the following errors come up and was just seeing if anyone could help with where I am going wrong please if ok


 


Warning: Missing argument 13 for renderForm(), called in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/micromend/admin/edit.php on line 163 and defined in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/micromend/admin/edit.php on line 26


 


Notice: Undefined variable: error in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/micromend/admin/edit.php on line 41


 


Below is the coding from the edit.php page



<?php
error_reporting(-1);
ini_set('display_errors', 'On');
?>

<?php
session_start();
if(empty($_SESSION['loggedin']))
{
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/admin/login.php');
exit;
}

echo 'You will only see this if you are logged in.';
?>


<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/

// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($visitor_id, $visitor_name, $visitor_name, $visitor_email, $visitor_firstline, $visitor_secondline, $visitor_town, $visitor_county, $visitor_postcode, $visitor_tel, $visitor_mobile, $visitor_newsletter, $error)
{
?>

<?php

include ( 'includes/header.php' );

?>
<title>Admin edit customers data</title>
</head>
<body>
<div id='column-whole-inner'>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $visitor_id; ?>"/>
<div>
<p><strong>Visitor ID:</strong> <?php echo $visitor_id; ?></p>
<strong>Name: *</strong> <input type="text" name="visitor_name" value="<?php echo $visitor_name; ?>"/>
<br/><br>
<strong>Email: *</strong> <input type="text" name="visitor_email" value="<?php echo $visitor_email; ?>"/>
<br/><br>
<strong>Address Line 1: *</strong> <input type="text" name="visitor_firstline" value="<?php echo $visitor_firstline;?>"/>
<br><br>
<strong>Address Line 2: *</strong> <input type="text" name="visitor_secondline" value="<?php echo $visitor_secondline;?>"/>
<br><br>
<strong>Town: *</strong> <input type="text" name="visitor_town" value="<?php echo $visitor_town; ?>"/>
<br><br>
<strong>County: *</strong> <textarea name="visitor_county" rows="8" cols="30"><?php echo $visitor_county; ?></textarea>
<br><br>
<strong>Postcode: *</strong> <input type="text" name="visitor_postcode" value="<?php echo $visitor_postcode; ?>"/>
<br><br>
<strong>Telephone Number: *</strong> <input type="text" name="visitor_tel" value="<?php echo $visitor_tel; ?>"/>
<br><br>
<strong>Mobile Number: *</strong> <input type="text" name="visitor_mobile" value="<?php echo $visitor_mobile; ?>"/>
<br>
<label style="color: #FFFFFF;"><input type="radio" name="visitor_newsletter" value="Yes" <?php if($visitor_newsletter == Yes) echo 'checked="checked"'; ?> > Yes</label>
<br>
<label style="color: #FFFFFF;"><input type="radio" name="visitor_newsletter" value="No"<?php if($visitor_newsletter == No) echo 'checked="checked"'; ?> > No</label>
<p>* Required</p>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
<?php
}



// connect to the database
include('config.php');

// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['visitor_id']))
{
// get form data, making sure it is valid
$visitor_id = $_POST['visitor_id'];
$visitor_name = mysql_real_escape_string(htmlspecialchars($_POST['visitor_name']));
$visitor_email = mysql_real_escape_string(htmlspecialchars($_POST['visitor_email']));
$visitor_firstline = mysql_real_escape_string(htmlspecialchars($_POST['visitor_firstline']));
$visitor_secondline = mysql_real_escape_string(htmlspecialchars($_POST['visitor_secondline']));
$visitor_town = mysql_real_escape_string(htmlspecialchars($_POST['visitor_town']));
$visitor_county = mysql_real_escape_string(htmlspecialchars($_POST['visitor_county']));
$visitor_postcode = mysql_real_escape_string(htmlspecialchars($_POST['visitor_postcode']));
$visitor_tel = mysql_real_escape_string(htmlspecialchars($_POST['visitor_tel']));
$visitor_mobile = mysql_real_escape_string(htmlspecialchars($_POST['visitor_mobile']));
$visitor_newsletter = $_POST['visitor_newsletter'];

// check that all fields are both filled in
if ($visitor_name == '' || $visitor_email == '' || $visitor_firstline == '' || $visitor_secondline == '' || $visitor_town == '' || $visitor_county == '' || $visitor_postcode == '' || $visitor_tel == '' || $visitor_mobile == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';

//error, display form
renderForm($visitor_id, $visitor_name, $visitor_email, $visitor_firstline, $visitor_secondline, $visitor_town, $visitor_county, $visitor_postcode, $visitor_tel, $visitor_mobile, $visitor_newsletter, $error);
}
else
{

// save the data to the database
mysql_query("UPDATE visitors SET visitor_name='$visitor_name', visitor_email='$visitor_email', visitor_firstline='$visitor_firstline', visitor_secondline='$secondline', visitor_town='$town', visitor_county='$visitor_county', visitor_postcode='$visitor_postcode', visitor_tel='$visitor_tel', visitor_mobile='$visitor_mobile', visitor_newsletter='$visitor_newsletter' WHERE visitor_id='$visitor_id'")
or die(mysql_error());

// once saved, redirect back to the view page
header("Location: index.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{

// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['visitor_id']) && is_numeric($_GET['visitor_id']) && $_GET['visitor_id'] > 0)
{
// query db
$visitor_id = $_GET['visitor_id'];
$result = mysql_query("SELECT * FROM visitors WHERE visitor_id=$visitor_id")
or die(mysql_error());
$row = mysql_fetch_array($result);

// check that the 'id' matches up with a row in the databse
if($row)
{

// get data from db
$visitor_id = $row['visitor_id'];
$visitor_name = $row['visitor_name'];
$visitor_email = $row['visitor_email'];
$visitor_firstline = $row['visitor_firstline'];
$visitor_secondline = $row['visitor_secondline'];
$visitor_town = $row['visitor_town'];
$visitor_county = $row['visitor_county'];
$visitor_postcode = $row['visitor_postcode'];
$visitor_tel = $row['visitor_tel'];
$visitor_mobile = $row['visitor_mobile'];
$visitor_newsletter = $row['visitor_newsletter'];

// show form
renderForm($visitor_id, $visitor_name, $visitor_email, $visitor_firstline, $visitor_secondline, $visitor_town, $visitor_county, $visitor_postcode, $visitor_tel, $visitor_mobile, $visitor_newsletter, '');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
}
?>

Link to comment
Share on other sites

Hmm another issue, just tried to update a record and I clicked submit and came up with the following error

 

Notice: Undefined index: visitor_id in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/micromend/admin/edit.php on line 90 Error!

 

On line 90 is the following

if (is_numeric($_POST['visitor_id'])) 
Link to comment
Share on other sites

Notice: Undefined index: visitor_id in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/micromend/admin/edit.php on line 90 Error!

 

On line 90 is the following

if (is_numeric($_POST['visitor_id'])) 

 

It looks like the visitor ID is stored in a hidden field named "id".

<input type="hidden" name="id" value="<?php echo $visitor_id; ?>"/>

You'll need to update that name...or use $_POST['id'].

Link to comment
Share on other sites

Ahh yeah easy to miss things until someone points it out

 

Got another issue, hopefully is the last one

 

When I am on the edit.php page, I am putting the address line 2 and town and county text in the input field but is not updating and storing it in the database

 

Sorry

Link to comment
Share on other sites

When I am on the edit.php page, I am putting the address line 2 and town and county text in the input field but is not updating and storing it in the database

 

You'll want to double check the variable names. In the query, for example, you use $secondline. But the POST information appears to be store in $visitor_secondline.

Link to comment
Share on other sites

Hi QuickOldCar

 

so should it be all the same either POST or GET?

 

If the information comes from the form which has its method attribute set to POST, you would use $_POST. If the information comes from a GET method (form or HTML link), you would use $_GET. Note that I haven't spent a lot of time with your script, so I can't say definitively which one you should use.

 

If you're unclear about the difference between $_GET and $_POST, perhaps the manual can help:

http://php.net/manual/en/reserved.variables.get.php

http://php.net/manual/en/reserved.variables.post.php

Link to comment
Share on other sites

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.