Hi Guys,
Wondering if anyone can please help
Here’s what I am trying to do:
Here's my 'user' table layout I have created in MySQL
ID int(11) No auto_increment
userid varchar(100) No
password varchar(16) No
fullname varchar(100) No
email varchar(100) No
notes text No
Now using this table each agent logs into my website from a record saved in this table and their details are held in a session:
Accesscontrol.php
<?php // accesscontrol.php
include_once 'common.php';
include_once 'db.php';
session_start();
$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid'];
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : $_SESSION['pwd'];
if(!isset($uid)) {
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Please Log In for Access </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="layout.css">
</head>
<body>
<h1><img src="../images/logo.gif" width="150" height="110"> </h1>
<h1>Login Required </h1>
<p>You must log in to access this area of the site. If you are
not a registered user, <a href="signup.php">click here</a>
to sign up for instant access!</p>
<p><form method="post" action="<?=$_SERVER['PHP_SELF']?>">
User ID: <input type="text" name="uid" size="8" /><br />
Password: <input type="password" name="pwd" SIZE="8" /><br />
<input type="submit" value="Log in" />
</form></p>
<div id="footer">
<table width="95%" border="0" cellpadding="1" cellspacing="1">
<tr bgcolor="#CC0000">
<td class="text"> <b><font color="#FFFFFF">The Regional Press Club - <font color="#FFFF00">www.regionalpressclub.co.uk</font></font></b></td>
</tr>
</table>
</div>
<!-- End of "wrapper" DIV. -->
</body>
</html>
<?php
exit;
}
$_SESSION['uid'] = $uid;
$_SESSION['pwd'] = $pwd;
dbConnect("regpress_rpc");
$sql = "SELECT * FROM user WHERE
userid = '$uid' AND password = PASSWORD('$pwd')";
$result = mysql_query($sql);
if (!$result) {
error('A database error occurred while checking your '.
'login details.\\nIf this error persists, please '.
'contact requests@regionalpressclub.co.uk');
}
if (mysql_num_rows($result) == 0) {
unset($_SESSION['uid']);
unset($_SESSION['pwd']);
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Access Denied </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1> Access Denied </h1>
<p>Your user ID or password is incorrect, or you are not a
registered user on this site. To try logging in again, click
<a href="<?=$_SERVER['PHP_SELF']?>">here</a>. To register for instant
access, click <a href="signup.php">here</a>.</p>
</body>
</html>
<?php
exit;
}
$username = mysql_result($result,0,'fullname');
?>
db.php
<?php // db.php
$dbhost = 'localhost';
$dbuser = '*********';
$dbpass = '******';
function dbConnect($db='regpress_rpc') {
global $dbhost, $dbuser, $dbpass;
$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die('The site database appears to be down.');
if ($db!='' and !@mysql_select_db($db))
die('The site database is unavailable.');
return $dbcnx;
}
?>
Now when each agent is logged in they are redirected to go to a page where they can:
1) Create a new listing
2) Modify an existing listing
3) Delete an existing listing.
Now all this works fine and each user can log-in, but all the text below is where I am now stuck and would appreciate help please.
If I click on ‘Create a new listing’ on this page it takes me to the following add.php page I have created, but when I hit submit nothing saves to the database – any idea why?:
<?php
// login stuff
include("accesscontrol.php");
$msg = "";
$name = "";
$title = "";
$full_details = "";
$redemption = "";
$restrictions = "";
if(isset($_POST['Submit']))
{
$name = $_POST['name'];
$title = $_POST['title'];
$full_details = $_POST['full_details'];
$redemption = $_POST['redemption'];
$restrictions = $_POST['restrictions'];
if(!isset($_GET['offers_id']))
{
$result = mysql_query("Insert into offers(name,title,full_details,redemption,restrictions) values('$name','$title','$full_details','$redemption','$restrictions')");
$msg = "New record is saved";
}
else
{
$result = mysql_query("Update offers set name='$name', title='$title', full_details='$full_details', redemption='$redemption', restrictions='$restrictions' where offers_id=".$_GET['offers_id']);
$msg = "Record is updated";
}
}
if(isset($_GET['offers_id']))
{
$result = mysql_query("Select * From offers where offers_id=".$_GET['offers_id'],$link);
$row = mysql_fetch_array($result, MYSQL_BOTH);
$name = $row['name'];
$title = $row['title'];
$full_details = $row['full_details'];
$redemption = $row['redemption'];
$restrictions = $row['restrictions'];
}
if(mysql_error())
{
echo mysql_error() ."<br>\n";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Members-Only Page </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1
</head>
<link rel="stylesheet" href="layout.css">
<link rel="stylesheet" href="layout.css">
<body>
<p><img src="../images/logo.gif" width="150" height="110"></p>
<p> <?=$username?> please enter a deal for the RPC website below.</p>
<h1 id="mainhead" class="text"> MVP - Partner Companies</h1>
<p class="text">Please create use the links below to add, update or delete a deal
that you wish to offer the RPC</p>
<table width="95%" border="0">
<tr bgcolor="#FFFF00">
<td><?php echo $msg?></td>
</tr>
</table>
<form>
<table width="22%" border="0">
<tr valign="middle">
<td height="20" colspan="2"> <img src="../images/1.jpg" width="20" height="20">
Please Enter Your Name:</td>
</tr>
<tr>
<td colspan="2">
<input type="text" name="name" class="box" size="40">
</td>
</tr>
</table>
<br>
<table width="22%" border="0">
<tr valign="middle">
<td height="20" colspan="2"><img src="../images/2.jpg" width="20" height="20">
Please give a title for the offer:</td>
</tr>
<tr>
<td colspan="2">
<input type="text" name="title" class="box" size="40">
</td>
</tr>
</table>
<br>
<table width="22%" border="0">
<tr valign="middle">
<td height="20" colspan="2"><img src="../images/3.jpg" width="20" height="20">
Please give full details of the offer:</td>
</tr>
<tr>
<td colspan="2">
<textarea name="full_details" class="bigbox" rows="10" cols="40"></textarea>
</td>
</tr>
</table>
<br>
<table width="22%" border="0">
<tr valign="middle">
<td height="20" colspan="2"><img src="../images/4.jpg" width="20" height="20">
Method of Redemption:</td>
</tr>
<tr>
<td colspan="2">
<textarea name="redemption" class="bigbox" rows="10" cols="40"></textarea>
</td>
</tr>
</table>
<br>
<table width="22%" border="0">
<tr valign="middle">
<td height="20" colspan="2"><img src="../images/5.jpg" width="20" height="20">
Details of Restrictions:</td>
</tr>
<tr>
<td colspan="2">
<textarea name="restrictions" class="bigbox" rows="10" cols="40"></textarea>
</td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit" class="buttons">
<input type="reset" name="Submit2" value="Reset" class="buttons">
</p>
</form>
<?php
include ('./includes/footer.html');
?>
Here’s mysql table layout for the table ‘offers’:
offer_id int(3) No auto_increment
name varchar(200) No
title varchar(200) No
full_details longtext No
redemption longtext No
restrictions longtext No
Can anyone advise. It just returns all the values I entered in the URL bar and does not save them to the 'offers' table?
ie like:
http://www.mysite.co.uk/sessions/add.php?name=Fred&title=Here+is+the+title&full_details=Full+Details&redemption=Redemptoion&restrictions=Restictions&Submit=Submit
Ta
Chris