Jump to content

Ad system


avatar.alex

Recommended Posts

im making an add system for my CMS but I cant get it to work at all i know it has something to do with the "elseif" but i cant find anything to help me another thing on line 38 i changed it from "extract()" to "compact()" will that do anything cus it took some errors away. The php manual didn't really help with any of this.

Heres my errors:

 

Parse error: parse error, unexpected T_ELSEIF in /home/www/twilightfor.freehostia.com/admin/adver.php on line 64

 

Heres the code. Im not asking anyone to correct it for me but if someone could give me a resource or something that would be appertained:(If theres other things wrong with my script point it out to me.)

<?
include("ad_auth.php");
include("./dbfunctions.php");
echo "<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">"; 
{ 
elseif($_GET['page']=="add")
 {
echo "<form id=\"FormName\" action=\"adver.php?page=added\" method=\"post\" name=\"FormName\">\n"; 
echo "<table width=\"448\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"; 
echo "<tr><td width = \"150\"><div align=\"right\"><label for=\"image\">image</label></div></td>\n"; 
echo "<td><input id=\"image\" name=\"image\" type=\"text\" size=\"25\" value=\"\" maxlength=\"255\"></td></tr><tr><td width = \"150\"><div align=\"right\"><label for=\"url\">url</label></div></td>\n"; 
echo "<td><input id=\"url\" name=\"url\" type=\"text\" size=\"25\" value=\"http://\" maxlength=\"255\"></td></tr><tr><td width = \"150\"><div align=\"right\"><label for=\"name_website\">name_website</label></div></td>\n"; 
echo "<td><input id=\"name_website\" name=\"name_website\" type=\"text\" size=\"25\" value=\"\" maxlength=\"255\"></td></tr><tr><td width=\"150\"></td><td>\n"; 
echo "<input type=\"submit\" name=\"submitButtonName\" value=\"Add\"></td>\n"; 
echo "</tr></table></form>\n";
}
elseif($_GET['page']=="added")
 {
$image = $_POST['image'];
$url = $_POST['url'];
$name_website = $_POST['name_website'];
$query = "INSERT INTO ad (id, image, url, name_website)
VALUES ('', '$image', '$url', '$name_website')";
$results = mysql_query($query) or die 
("Could not execute query : $query." . mysql_error());
if ($results)
{
echo "Details added.";
}

}
elseif($_GET['update']=="$id")
$id = $_GET['id']; 
{
$qProfile = "SELECT * FROM ad WHERE id='$id'  ";
$rsProfile = mysql_query($qProfile);
$row = mysql_fetch_array($rsProfile);
compact($row);
$image = stripslashes($image);
$url = stripslashes($url);
$name_website = stripslashes($name_website);


echo "<form id=\"FormName\" action=\"adver.php?page=updated\" method=\"post\" name=\"FormName\">\n"; 
echo "<table width=\"448\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"; 
echo "<tr><td width=\"150\"><div align=\"right\">\n"; 
echo "<label for=\"image\">image</label></div>\n"; 
echo "</td><td>\n"; 
echo "<input id=\"image\" name=\"image\" type=\"text\" size=\"25\" value=\"<?php echo $image ?>\" maxlength=\"255\"></td>\n"; 
echo "</tr><tr><td width=\"150\"><div align=\"right\">\n"; 
echo "<label for=\"url\">url</label></div>\n"; 
echo "</td><td>\n"; 
echo "<input id=\"url\" name=\"url\" type=\"text\" size=\"25\" value=\"<?php echo $url ?>\" maxlength=\"255\"></td>\n"; 
echo "</tr><tr><td width=\"150\"><div align=\"right\">\n"; 
echo "<label for=\"name_website\">name_website</label></div>\n"; 
echo "</td><td>\n"; 
echo "<input id=\"name_website\" name=\"name_website\" type=\"text\" size=\"25\" value=\"<?php echo $name_website ?>\" maxlength=\"255\"></td>\n"; 
echo "</tr><tr>\n"; 
echo "<td width=\"150\"></td>\n"; 
echo "<td><input type=\"submit\" name=\"submitButtonName\" value=\"Update\"><input type=\"hidden\" name=\"id\" value=\"<?php echo $id ?>\"></td>\n"; 
echo "</tr></table>\n"; 
echo "</form>\n";
}
elseif($_GET['page']=="updated")	
$id = $_POST['id'];	 
{
$image = $_POST['image'];
$url = $_POST['url'];
$name_website = $_POST['name_website'];
$update = "UPDATE ad SET image = '$image', url = '$url', name_website = '$name_website' WHERE id='$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)
{
echo "Update successful.";
}
}
elseif($_GET['delete']=="$id")
$id = $_GET['id'];
{
$delete = "DELETE FROM ad WHERE id='$id' ";
mysql_query($delete);
echo "Entry deleted";
}
} mysql_close();
?>

Link to comment
Share on other sites

first always always always use <?php never use <?

i would suggest using require_once instead on include, because if the page failes to include then the page will keep going and give a warning a require would be like a die() statement if the file couldnt be found

 

if you could point out which line is 64, that would be awesome but ill look some more

Link to comment
Share on other sites

Thank you now there are no PHP errors but all the stuff is clashing together like the update, add, delete are all on the same page thats not wat I wanted I wanted like adver.php?page=add only the add part shows up?

 

 

This is currrent

1.  	<?php
2.  	require_once("ad_auth.php");
3.  	require_once("./dbfunctions.php");
4.  	echo "<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">"; 
5.  	{
6.  	if($_GET['page']=="add")
7.  	 {
8.  	echo "<form id=\"FormName\" action=\"adver.php?page=added\" method=\"post\" name=\"FormName\">\n"; 
9.  	echo "<table width=\"448\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"; 
10.  	echo "<tr><td width = \"150\"><div align=\"right\"><label for=\"image\">image</label></div></td>\n"; 
11.  	echo "<td><input id=\"image\" name=\"image\" type=\"text\" size=\"25\" value=\"\" maxlength=\"255\"></td></tr><tr><td width = \"150\"><div align=\"right\"><label for=\"url\">url</label></div></td>\n"; 
12.  	echo "<td><input id=\"url\" name=\"url\" type=\"text\" size=\"25\" value=\"http://\" maxlength=\"255\"></td></tr><tr><td width = \"150\"><div align=\"right\"><label for=\"name_website\">name_website</label></div></td>\n"; 
13.  	echo "<td><input id=\"name_website\" name=\"name_website\" type=\"text\" size=\"25\" value=\"\" maxlength=\"255\"></td></tr><tr><td width=\"150\"></td><td>\n"; 
14.  	echo "<input type=\"submit\" name=\"submitButtonName\" value=\"Add\"></td>\n"; 
15.  	echo "</tr></table></form>\n";
16.  	}
17.  	if($_GET['page']=="added")
18.  	 {
19.  	$image = $_POST['image'];
20.  	$url = $_POST['url'];
21.  	$name_website = $_POST['name_website'];
22.  	$query = "INSERT INTO ad (id, image, url, name_website)
23.  	VALUES ('', '$image', '$url', '$name_website')";
24.  	$results = mysql_query($query) or die 
25.  	("Could not execute query : $query." . mysql_error());
26.  	if ($results)
27.  	{
28.  	echo "Details added.";
29.  	}
30.  	}
31.  	elseif($_GET['update']=="$id")
32.  	$id = $_GET['id']; 
33.  	{
34.  	$qProfile = "SELECT * FROM ad WHERE id='$id'  ";
35.  	$rsProfile = mysql_query($qProfile);
36.  	$row = mysql_fetch_array($rsProfile);
37.  	compact($row);
38.  	$image = stripslashes($image);
39.  	$url = stripslashes($url);
40.  	$name_website = stripslashes($name_website);
41.  	
42.  	
43.  	echo "<form id=\"FormName\" action=\"adver.php?page=updated\" method=\"post\" name=\"FormName\">\n"; 
44.  	echo "<table width=\"448\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"; 
45.  	echo "<tr><td width=\"150\"><div align=\"right\">\n"; 
46.  	echo "<label for=\"image\">image</label></div>\n"; 
47.  	echo "</td><td>\n"; 
48.  	echo "<input id=\"image\" name=\"image\" type=\"text\" size=\"25\" value=\"$image\" maxlength=\"255\"></td>\n"; 
49.  	echo "</tr><tr><td width=\"150\"><div align=\"right\">\n"; 
50.  	echo "<label for=\"url\">url</label></div>\n"; 
51.  	echo "</td><td>\n"; 
52.  	echo "<input id=\"url\" name=\"url\" type=\"text\" size=\"25\" value=\"$url\" maxlength=\"255\"></td>\n"; 
53.  	echo "</tr><tr><td width=\"150\"><div align=\"right\">\n"; 
54.  	echo "<label for=\"name_website\">name_website</label></div>\n"; 
55.  	echo "</td><td>\n"; 
56.  	echo "<input id=\"name_website\" name=\"name_website\" type=\"text\" size=\"25\" value=\"$name_website\" maxlength=\"255\"></td>\n"; 
57.  	echo "</tr><tr>\n"; 
58.  	echo "<td width=\"150\"></td>\n"; 
59.  	echo "<td><input type=\"submit\" name=\"submitButtonName\" value=\"Update\"><input type=\"hidden\" name=\"id\" value=\"$id\"></td>\n"; 
60.  	echo "</tr></table>\n"; 
61.  	echo "</form>\n";
62.  	}
63.  	if($_GET['page']=="updated")
64.  	$id = $_POST['id'];  
65.  	{
66.  	$image = $_POST['image'];
67.  	$url = $_POST['url'];
68.  	$name_website = $_POST['name_website'];
69.  	$update = "UPDATE ad SET image = '$image', url = '$url', name_website = '$name_website' WHERE id='$id' ";
70.  	$rsUpdate = mysql_query($update);
71.  	if ($rsUpdate)
72.  	{
73.  	echo "Update successful.";
74.  	}
75.  	}
76.  	if($_GET['delete']=="$id")
77.  	$id = $_GET['id'];
78.  	{
79.  	$delete = "DELETE FROM ad WHERE id='$id' ";
80.  	mysql_query($delete);
81.  	echo "Entry deleted";
82.  	}
83.  	} mysql_close();
84.  	?>

Link to comment
Share on other sites

i got it, its because your $id=$_POST['id']; is after the if statement

change the script to this and try it out

<?php
	require_once("ad_auth.php");
	require_once("./dbfunctions.php");
	echo "<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\">"; 
	{
	if($_GET['page']=="add")
	 {
	echo "<form id=\"FormName\" action=\"adver.php?page=added\" method=\"post\" name=\"FormName\">\n"; 
	echo "<table width=\"448\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"; 
  	echo "<tr><td width = \"150\"><div align=\"right\"><label for=\"image\">image</label></div></td>\n"; 
  	echo "<td><input id=\"image\" name=\"image\" type=\"text\" size=\"25\" value=\"\" maxlength=\"255\"></td></tr><tr><td width = \"150\"><div align=\"right\"><label for=\"url\">url</label></div></td>\n"; 
  	echo "<td><input id=\"url\" name=\"url\" type=\"text\" size=\"25\" value=\"http://\" maxlength=\"255\"></td></tr><tr><td width = \"150\"><div align=\"right\"><label for=\"name_website\">name_website</label></div></td>\n"; 
	echo "<td><input id=\"name_website\" name=\"name_website\" type=\"text\" size=\"25\" value=\"\" maxlength=\"255\"></td></tr><tr><td width=\"150\"></td><td>\n"; 
  	echo "<input type=\"submit\" name=\"submitButtonName\" value=\"Add\"></td>\n"; 
  	echo "</tr></table></form>\n";
  	}
  	if($_GET['page']=="added")
  	 {
  	$image = $_POST['image'];
  	$url = $_POST['url'];
  	$name_website = $_POST['name_website'];
  	$query = "INSERT INTO ad (id, image, url, name_website)
  	VALUES ('', '$image', '$url', '$name_website')";
  	$results = mysql_query($query) or die 
  	("Could not execute query : $query." . mysql_error());
  	if ($results)
  	{
  	echo "Details added.";
  	}
  	}
  	elseif($_GET['update']=="$id")
  	{
    $id = $_GET['id']; 
  	$qProfile = "SELECT * FROM ad WHERE id='$id'  ";
  	$rsProfile = mysql_query($qProfile);
  	$row = mysql_fetch_array($rsProfile);
  	compact($row);
  	$image = stripslashes($image);
  	$url = stripslashes($url);
  	$name_website = stripslashes($name_website);
  	
  	
  	echo "<form id=\"FormName\" action=\"adver.php?page=updated\" method=\"post\" name=\"FormName\">\n"; 
  	echo "<table width=\"448\" border=\"0\" cellspacing=\"2\" cellpadding=\"0\">\n"; 
  	echo "<tr><td width=\"150\"><div align=\"right\">\n"; 
  	echo "<label for=\"image\">image</label></div>\n"; 
  	echo "</td><td>\n"; 
  	echo "<input id=\"image\" name=\"image\" type=\"text\" size=\"25\" value=\"$image\" maxlength=\"255\"></td>\n"; 
  	echo "</tr><tr><td width=\"150\"><div align=\"right\">\n"; 
  	echo "<label for=\"url\">url</label></div>\n"; 
  	echo "</td><td>\n"; 
  	echo "<input id=\"url\" name=\"url\" type=\"text\" size=\"25\" value=\"$url\" maxlength=\"255\"></td>\n"; 
  	echo "</tr><tr><td width=\"150\"><div align=\"right\">\n"; 
  	echo "<label for=\"name_website\">name_website</label></div>\n"; 
  	echo "</td><td>\n"; 
  	echo "<input id=\"name_website\" name=\"name_website\" type=\"text\" size=\"25\" value=\"$name_website\" maxlength=\"255\"></td>\n"; 
  	echo "</tr><tr>\n"; 
	echo "<td width=\"150\"></td>\n"; 
  	echo "<td><input type=\"submit\" name=\"submitButtonName\" value=\"Update\"><input type=\"hidden\" name=\"id\" value=\"$id\"></td>\n"; 
	echo "</tr></table>\n"; 
	echo "</form>\n";
	}
  	if($_GET['page']=="updated")
  	{
    $id = $_POST['id'];  
  	$image = $_POST['image'];
	$url = $_POST['url'];
	$name_website = $_POST['name_website'];
	$update = "UPDATE ad SET image = '$image', url = '$url', name_website = '$name_website' WHERE id='$id' ";
	$rsUpdate = mysql_query($update);
	if ($rsUpdate)
	{
	echo "Update successful.";
}
  	}
  	if($_GET['delete']=="$id")
  	{
    $id = $_GET['id'];
  	$delete = "DELETE FROM ad WHERE id='$id' ";
  	mysql_query($delete);
  	echo "Entry deleted";
	}
} mysql_close();

 

you nede to bput the get get id after the if(){ not inbetween the ) and {

try it and get back to me

Link to comment
Share on other sites

ok i see that part but I got this:

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/www/twilightfor.freehostia.com/admin/adver.php:1) in /home/www/twilightfor.freehostia.com/admin/ad_auth.php on line 2

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/twilightfor.freehostia.com/admin/adver.php:1) in /home/www/twilightfor.freehostia.com/admin/ad_auth.php on line 2

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.