I've searched the web and tried many different methods, and still failing. Heres the situation:
<form is up here>
<?php
if(isset($_POST['save1'])) {
$title1 = $_POST['title1'];
$title2 = $_POST['title2'];
$title3 = $_POST['title3'];
$content1 = $_POST['content1'];
$content2 = $_POST['content2'];
$content3 = $_POST['content3'];
if(!get_magic_quotes_gpc()) {
$title1 = addslashes($title1);
$title2 = addslahses($title2);
$title3 = addslashes($title3);
$content1 = addslashes($content1);
$content2 = addslashes($content2);
$content3 = addslashes($content3);
}
$con = mysql_connect(input my info...);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);
$result = mysql_query("UPDATE 'homepage' SET title='$title1' WHERE id='1'");
$result = mysql_query("UPDATE 'homepage' SET title='$title2' WHERE id='2'");
$result = mysql_query("UPDATE 'homepage' SET title='$title3' WHERE id='3'");
$result = mysql_query("UPDATE 'homepage' SET content='$content1' WHERE id='1'");
$result = mysql_query("UPDATE 'homepage' SET content='$content2' WHERE id='2'");
$result = myslq_query("UPDATE 'homepage' SET content='$content3' WHERE id='3'");
mysql_close($con);
echo "Edit complete";
}
?>
what would be the issue? Or any better method of going about this? (building a content manager) I already have the homepage pulling preset data from database and works fine.. but this is annoying!!!
Thanks for the reply, however even with that fix it still seems like my entries are just pretending to exist. How ever I will say, this page is acting extremely weird... I link my style sheet with same pages and this page randomly puts a few elements wayyy out of place, and reviewing the css after an hour their is NOTHING wrong, and confusing the hell out of me... I think someone is screwing with me lolz.
But since maybe this script is not the problem.. I basically have this set up:
homepage echos the database content in corrent position (I put some present text in there), and this script I put on is avaliable from a protected admin page that will perform what you see from the inputs of a form.. Everything is working but the updating portion and random css bug.
Edit: every since I added your update, now the missplaced content i was talking about earlier has disapeared.. or all the html below this script 0_0
Add mysql_error to the end of your update queries or run the query (replacing the variables with actual values) in PHPMyAdmin and see if you get an error.
You also need to secure your queries by using mysql_real_escape_string on your posted data as at the moment it is open to php injection.
You can also remove the $result = from each query line unless you are going to use it later in your script.
As for your CSS I have no idea as that was not your question.
mysql_query("UPDATE homepage SET title='".$title1."', content='".$content1."' WHERE id=1");
mysql_query("UPDATE homepage SET title='".$title2."', content='".$content2."' WHERE id=2");
mysql_query("UPDATE homepage SET title='".$title3."', content='".$content3."' WHERE id=3");
How did you test for errors? Using mysql_error or in PHPMyAdmin?
By the way, you are repeating your queries unnecessarily as well:
PHP Code:
$result = mysql_query("UPDATE 'homepage' SET title='$title1' WHERE id='1'");
// AND
$result = mysql_query("UPDATE 'homepage' SET content='$content1' WHERE id='1'");
// Should be combined (and I have re-formatted to how I would do it)
mysql_query("UPDATE homepage SET title='".$title1."', content='".$content1."' WHERE id=1");
I echoed after each event.. like echo "connected to database! "; ..etc. I find this more productive as I can pin point things easier, then delete when Its 100%
Ok thanks for that, I knew it existed but was trying to get the easier way to work first
Bookmarks