Jump to content

Undefined variables, getting error messages......


illkillyouforfun

Recommended Posts

This is what I'm getting...

 

Notice: Undefined variable: sitetitle in /home/vehiclep/public_html/functions.php on line 121

 

Notice: Undefined variable: ADcode in /home/vehiclep/public_html/functions.php on line 121

 

Notice: Undefined variable: email in /home/vehiclep/public_html/functions.php on line 121

 

Notice: Undefined variable: url in /home/vehiclep/public_html/functions.php on line 121

 

Notice: Undefined variable: charge in /home/vehiclep/public_html/functions.php on line 121

 

Notice: Undefined variable: currency in /home/vehiclep/public_html/functions.php on line 121

 

Notice: Undefined variable: price in /home/vehiclep/public_html/functions.php on line 121

 

this is functions.php

function sitesets() {

				$sql = "select * from settings limit 1";
			$rs = mysql_query($sql);
			$row = @mysql_fetch_array($rs);
			extract($row);

$sitesets = array("title"=>$sitetitle, "ADcode"=>$ADcode, "email" => $email, "url" => $url, "charge" => $charge, "currency" => $currency, "price" => $price);

return $sitesets;

}

 

Ive tried going into phpMyadmin and creating a row and entering the info manualy but it doesnt work.  I don't know much about coding so this may be a dumb question but it has me stumped.  I hope somebody can tell me what I'm missing here.

Link to comment
Share on other sites

You should be selecting just the fields you want. Then you can use msql_fetch_assoc and just return the the row.

<?php
function sitesets() {
   $sql = "select sitetitle, ADcode, email, url, charge, currency, price from settings limit 1";
   $rs = mysql_query($sql);
   $sitesets = mysql_fetch_assoc($rs);
   return $sitesets;
}
?>

 

Ken

Link to comment
Share on other sites

I am trying to insert a row. 

 

This is a settings area for my website's script where I enter the title, url, etc to be used as variables throughout it.

 

Sorry if I am not being clear this is the first time I've worked with php or mySQL I am a newbie.

 

I am thinking now there may be errors in two places now you've said that.  I think the code you gave me corrected the function.php but I have to see another index.php file as well.

<?php

if(isset($_GET['page'])) {

$page = $_GET['page'];

switch ($page) {	

	case "settings":
		print $utils->h1("Settings", "");			
		$settings = sitesets();

		if(isset($_POST['sb'])) {
			$update = $query->update("update settings set sitetitle = '".addentities($_POST['title'])."', 
			url = '".addentities($_POST['url'])."',
			email = '".addentities($_POST['email'])."',
			ADcode = '".$_POST['adcode']."'");				
			if($update != 0) {
				print "Update took place successfully";
				refreshPage(3, $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']);
				exit();
			}else{
				print "Error in trying to update!";
			}
		}

		?>
		<style>
		input{width:300px}
		textarea{width:300px; height:80px}
		</style>

		<form action="" method="POST">
		<table>
		<tr><td>Website title</td><td><input type="text" name="title" value="<?=$settings['title'];?>"></td></tr>
		<tr><td>Website URL (include last slash "/")</td>
		<td><input type="text" name="url" value="<?=$settings['url'];?>"></td></tr>
		<tr><td>Email</td><td><input type="text" name="email" value="<?=$settings['email'];?>"></td></tr>			
		<tr><td>Ad code</td><td><textarea name="adcode"><?=htmlentities($settings['ADcode']);?></textarea></td></tr>
		</table>
		<input type="submit" name="sb" id="sb" value="Update" style="width:100px">
		</form>

 

That is the code from the page where I am entering those variables.

Link to comment
Share on other sites

Unless you have your own function called addentities, there is no such function. You really should be using the function mysql_real_escape_string() on any user supplied data that is being used in a mysql query. Also, don't use "<?=", use "<?php echo " instead. If "short-tags" are disabled on your site, the "<?=" short cut won't work.

<?php
if(isset($_GET['page'])) {
$page = $_GET['page'];
switch ($page) {
	case "settings":
	print $utils->h1("Settings", "");
	$settings = sitesets();
	if(isset($_POST['sb'])) {
		$update = $query->update("update settings set sitetitle = '".mysql_real_escape_string($_POST['title'])."',
		url = '".mysql_real_escape_string($_POST['url'])."',
		email = '".mysql_real_escape_string($_POST['email'])."',
		ADcode = '".mysql_real_escape_string($_POST['adcode'])."'");
		if($update != 0) {
			print "Update took place successfully";
			refreshPage(3, $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']);
			exit();
		}else{
			print "Error in trying to update!";
		}
	}
	?>
	<style>
	input{width:300px}
	textarea{width:300px; height:80px}
	</style>

	<form action="" method="POST">
	<table>
	<tr><td>Website title</td><td><input type="text" name="title" value="<?php echo $settings['title'];?>"></td></tr>
	<tr><td>Website URL (include last slash "/")</td>
	<td><input type="text" name="url" value="<?php echo $settings['url'];?>"></td></tr>
	<tr><td>Email</td><td><input type="text" name="email" value="<?php echo $settings['email'];?>"></td></tr>
	<tr><td>Ad code</td><td><textarea name="adcode"><?php echo htmlentities($settings['ADcode']);?></textarea></td></tr>
	</table>
	<input type="submit" name="sb" id="sb" value="Update" style="width:100px">
	</form>

 

Ken

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.