hi im using textpad to do the code, phpmyadmin for the database.
im currently doing a page where a user can rate the place they have been to in london however i cant get it working. im a beginner to php so sorry for any stupid errors in advance. this is my code for the form and the php script
The bit in bold is the one i cant get working. when the user selects a rating i want it to go into the database with their user id going through which is called Unique ID in the database and they id of the place they have rated which is UniqueID in the database. the php script is:
Thanks in advance
im currently doing a page where a user can rate the place they have been to in london however i cant get it working. im a beginner to php so sorry for any stupid errors in advance. this is my code for the form and the php script
Code:
<?php require_once('Connections/nightlifeinlondon.php'); ?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_DetailRS1 = "-1";
if (isset($_GET['recordID'])) {
$colname_DetailRS1 = $_GET['recordID'];
}
mysql_select_db($database_nightlifeinlondon, $nightlifeinlondon);
$query_DetailRS1 = sprintf("SELECT * FROM `places` WHERE UniqueID = %s", GetSQLValueString($colname_DetailRS1, "-1"));
$DetailRS1 = mysql_query($query_DetailRS1, $nightlifeinlondon) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($DetailRS1);
?><?php
require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
DeSign2 by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Nightlife in London</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<span class="style1"><a href="Homepage.php"> Logout</a></span>
<?php include "header2.php" ?>
<div id="wrapper">
<div id="content">
<div id="content">
<div id="welcome" class="post">
<h2 align="center" class="title"> </h2>
<h2 align="center" class="title">Details of the place you have chosen</h2>
<h3 class="date"> </h3>
<div class="meta"></div>
<div class="story">
<form id="form1" method="post" action="">
<div align="center">
<table border="0" cellspacing="15">
<tr>
<td width="136"><strong>Club/Bar/Pub</strong></td>
<td width="224"><?php echo $row_DetailRS1['Club/Bar/Pub']; ?> </td>
</tr>
<tr>
<td><strong>Name</strong></td>
<td><?php echo $row_DetailRS1['Name']; ?> </td>
</tr>
<tr>
<td><strong>Street Name/Number</strong></td>
<td><?php echo $row_DetailRS1['Street Name/Number']; ?> </td>
</tr>
<tr>
<td><strong>Town</strong></td>
<td><?php echo $row_DetailRS1['Town']; ?> </td>
</tr>
<tr>
<td><strong>Postcode</strong></td>
<td><?php echo $row_DetailRS1['Postcode']; ?> </td>
</tr>
<tr>
<td><strong>Telephone</strong></td>
<td><?php echo $row_DetailRS1['Telephone']; ?> </td>
</tr>
<tr>
<td><strong>E-mail</strong></td>
<td><?php echo $row_DetailRS1['E-mail']; ?> </td>
</tr>
<tr>
<td><strong>MusicGenre</strong></td>
<td><?php echo $row_DetailRS1['MusicGenre']; ?> </td>
</tr>
<tr>
<td><strong>DisabledAcess</strong></td>
<td><?php echo $row_DetailRS1['DisabledAcess']; ?> </td>
</tr>
</table>
<p> </p>
<p>If you have been to this place, you can give this a rating between 1-10, 1 being really bad and 10 being perfect! Press the submit button to put your rating through.</p>
<p>
<label></label>
[B] <form id="ratings" name="ratings" method="post" action="rating.php">
<select name="rating">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label>
</form>[/B]
</p>
</div>
</form>
</div>
</div>
<div style="clear: both;"> </div>
</div>
<div id="footer">
<p id="legal">Copyright © Developed by Chanbir Dhesi. CSS templates from <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p>
</div>
<?php
mysql_free_result($DetailRS1);
?>
Code:
<?php
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect("localhost", "Chanbir", "liverpool");
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("nightlifeinlondon");
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$rating = clean($_POST['ratings']);
//Create INSERT query
$qry = "INSERT INTO `rating`(`ratingValue`) VALUES('$rating')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if ($result) {
echo 'The query returned ' . $result[ 'whatever' ];
} else {
die('Invalid query: ' . mysql_error());
} ?>
Comment