Jump to content

[SOLVED] Going crazy


newguy222

Recommended Posts

I have a table in my SQL for downloads. I wanted to make a page that other admin on my site can edit those downloads, change the description, icon, date, things like that then resubmit to the database. My challenge has been to get the information to pre populate from the database into an editing form. After piecing together different coding I knew it finally worked. My problem is that it's displaying all my downloads instead of the download id carried over from the page before. I hope I'm explaining this correctly. Let me show my code and see what comes from that.

 

This is the link on the previous page that is supposed to direct and bring the ID of the download into the editing page.

 

<td><a href="23.php?action=confirm&id=<?=$row['id'] ?>">Test</a></td>

 

That code works (I believe). It bring over and allows the form on the next page to auto populate. This is my code from the editing page.

 

<head>
<style type="text/css">
a {
color: #008000;
}
a:visited {
color: #008000;
}
a:active {
color: #008000;
}
a:hover {
color: #008000;
}
</style>
</head>
<html>
<?php
include 'inc/config.php';
include 'inc/opendb.php';

$query  = "SELECT id, name, dis, icon, maker, date FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
} 
else
{
while(list($id, $name, $dis, $icon, $maker, $date) = mysql_fetch_array($result))
{

?>

<center>
<body bgcolor="Black" style="color: #008000">
<input type="hidden" name="id" value="<?=$_REQUEST['id'] ?>">
<strong class="font"><span class="style2">Name:</span></strong><span class="style4"><strong><br />
<input type="text" name="name" size="30" value="<?=$dis;?>"><br>
</strong></span>
<strong class="font"><span class="style2">Icon:</span></strong><span class="style4"><strong><br>
<input type="text" name="icon" size="30" value="<?=$icon;?>"><br>
</strong></span>
<strong class="font"><span class="style2">Maker:</span></strong><span class="style4"><strong><br />
<input type="text" name="maker" size="30" value="<?=$maker;?>"><br>
</strong></span>
<strong class="font"><span class="style2">Date:</span></strong><span class="style4"><strong><br />
<input type="text" name="date" size="30" value="<?=$date;?>"><br>
</strong></span>

<?php  
}
}
include 'inc/closedb.php';
?>

</body>
</html>

 

 

Now all I get is every download in my DB is listed in their own form up and down the page.

 

Please help this is driving me insane.

Link to comment
https://forums.phpfreaks.com/topic/130565-solved-going-crazy/
Share on other sites

There's no WHERE part in your SQL query, so it gets all rows from the table.

 

$query  = "SELECT id, name, dis, icon, maker, date FROM upload";

 

You should change it to something like this:

 

$query  = "SELECT id, name, dis, icon, maker, date FROM upload WHERE id =" . mysql_real_escape_string($_GET['id']);

 

And yeah... you use MySQL, and posted it MSSQL forum... you sure you want someone help you? :P

Link to comment
https://forums.phpfreaks.com/topic/130565-solved-going-crazy/#findComment-677386
Share on other sites

That work great, thank you so much. I did post this in the wrong section, I didn't even notice *sorry*.

 

One last question, hopefully you can guide me in the right direction...

 

As I explained a link from page 1 brings up a form on page 2, now I was thinking I needed a page three to have this update page 2's contents to the database. If there's any easier way please tell me because this doesn't work >>

 

The following edit were made to page 2:

while(list($id, $name, $dis, $icon, $maker, $date) = mysql_fetch_array($result))
{

?>
<form method="post" id="edit" action="page3.php" class="style6">
<center>
<body bgcolor="Black" style="color: #008000">
<input type="hidden" name="id" value="<?=$_REQUEST['id'] ?>">
<strong class="font"><span class="style2">Name:</span></strong><span class="style4"><strong><br />
<input type="text" name="name" size="30" value="<?=$dis;?>"><br>
</strong></span>
<strong class="font"><span class="style2">Icon:</span></strong><span class="style4"><strong><br>
<input type="text" name="icon" size="30" value="<?=$icon;?>"><br>
</strong></span>
<strong class="font"><span class="style2">Maker:</span></strong><span class="style4"><strong><br />
<input type="text" name="maker" size="30" value="<?=$maker;?>"><br>
</strong></span>
<strong class="font"><span class="style2">Date:</span></strong><span class="style4"><strong><br />
<input type="text" name="date" size="30" value="<?=$date;?>"><br>
</strong></span>
<input type="submit" value="Add A DJ" name="B3">
<?php		
}
}
include 'inc/closedb.php';
?>

 

Page 3:

 

<html>
<center>
<body bgcolor="Black">
<meta http-equiv="refresh" content="3; URL/upload/page1.php">
<?
$host = "localhost"; 
$user = "xxxxxx"; 
$pass = "xxxxxx"; 
$db = "xxxxxx"; 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
mysql_select_db($db) or die ("Unable to select database!"); 
$name = $_POST['name'];
$dis = $_POST['dis'];
$icon = $_POST['icon'];
$maker = $_POST['maker'];
$date = $_POST['date'];
if($_POST['action'] == 'edit'){
UPDATE (id, name, dis, icon, maker, date) Values ('NULL', '".$name."', '".$dis."', '".$icon."', '".$maker."', '".$date."') INTO upload WHERE id =".$_POST['id'];
@mysql_query($sql);?>
echo "The DJ Database Is Being Updated. Please Wait 3 Seconds." ;
<? }?>

Link to comment
https://forums.phpfreaks.com/topic/130565-solved-going-crazy/#findComment-677417
Share on other sites

You have:

if($_POST['action'] == 'edit') {/*...*/}

in page3.php

 

but have no "action" defined in page2.php

 

In fact all this:

if($_POST['action'] == 'edit'){
UPDATE (id, name, dis, icon, maker, date) Values ('NULL', '".$name."', '".$dis."', '".$icon."', '".$maker."', '".$date."') INTO upload WHERE id =".$_POST['id'];
@mysql_query($sql);?>
echo "The DJ Database Is Being Updated. Please Wait 3 Seconds." ;
<? }?>

is full of errors...

 

 

if($_POST['action'] == 'edit'){
$sql = "UPDATE UPLOAD (id, name, dis, icon, maker, date) Values ('NULL', '$name', '$dis', '$icon', '$maker', '$date') WHERE id ={$_POST['id']}";
@mysql_query($sql);
echo "The DJ Database Is Being Updated. Please Wait 3 Seconds." ;
}

Link to comment
https://forums.phpfreaks.com/topic/130565-solved-going-crazy/#findComment-677425
Share on other sites

SOLVED -

 

I changed the form method to post on page 2, and changed page 3 to:

 

<html>
<center>
<body bgcolor="Black">
<meta http-equiv="refresh" content="3; URL=/sniper/upload/view.php">
<?
$host = "xxxxx"; 
$user = "xxxxxxx"; 
$pass = "xxxxxxxx"; 
$db = "xxxxxx"; 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 
mysql_select_db($db) or die ("Unable to select database!"); 
$id = $_POST['id'];
$dis = $_POST['dis'];
$icon = $_POST['icon'];
$maker = $_POST['maker'];
$date = $_POST['date'];
$query="UPDATE upload SET dis = '$dis', icon = '$icon', maker = '$maker' WHERE id = '$id'";
mysql_query($query) or die ('Error Updating Database');
echo "Database Updating Please Wait 3 Seconds." ;
?>
<body style="color: #00FF00; background-color: #000000"></center>

 

Thank you for the help. It works great now. :D

Link to comment
https://forums.phpfreaks.com/topic/130565-solved-going-crazy/#findComment-677465
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.