Re: [PHP] Mysql / php help
A quick question; do you use Google Translator for your posts?
Because I can see it quite difficult for people to understand you =s
To edit stuff you have to use a query like:
Code:
UPDATE `Text` SET `News` = 'theNewsHere' WHERE 0
That will set the news to 'theNewsHere' in there, but be warned, this will set in on EVERY ENTRY in the table Text. If you don't want that, change the WHERE.
Re: [PHP] Mysql / php help
So, i need that code for update it, Thanks for that :)
But how so i make like, a text box there you type the news and click submit and it update?
Re: [PHP] Mysql / php help
Ill get some code for you in a sec, let me make it. Meanwhile just read up on PHP forms.
EDIT:
PHP Code:
<?php
//add your database connection here
if($_POST['go'])
{
$news = $_POST['news']; //the textarea field
if(empty($news)) //just a check
{
echo "Fill in the news!";
exit;
}
$sql = "UPDATE `Text` SET `News` = '". $news ."'"; //the code i posted
$query = mysql_query($sql);
if(!$query)
{
die(mysql_error());
}
else
{
echo "News updated!";
header("Location: ". $_SERVER['PHP_SELF']); //failsafe, else if you press F5, it will repeat the action, you can leave this if you want.
exit;
}
}
?>
//put that PHP code ABOVE your <html> tag.
//put this form wherever you want, but put it on the same page as the PHP code!
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<textarea name="news" rows="10" cols="50"></textarea>
<input type="submit" name="go" value="Submit news" />
</form>
Re: [PHP] Mysql / php help
This is my db info``??
$db = mysql_connect("localhost","root","root");
$conn = mysql_select_db("Mysql_site", $db);
$query = mysql_query("SELECT * FROM text");
---------- Post added at 12:17 PM ---------- Previous post was at 12:15 PM ----------
Works fine Thanks - (WARRING)
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Mysql_website\admin.php:9) in C:\xampp\htdocs\Mysql_website\admin.php on line 46
Re: [PHP] Mysql / php help
Oh, yes. Remove the:
PHP Code:
header("Location: ". $_SERVER['PHP_SELF']);
I forgot you can't echo anything before header redirecting.
Re: [PHP] Mysql / php help
added this code to a update.php but it don't works can't update my "updates" line :/
Code:
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<textarea name="Updates" rows="5" cols="40"></textarea>
<input type="submit" name="go" value="Submit updates" />
</form>
<?php
$db = mysql_connect("localhost","root","root");
$conn = mysql_select_db("Mysql_site", $db);
$query = mysql_query("SELECT * FROM text");
if($_POST['go'])
{
$news = $_POST['Updates']; //the textarea field
if(empty($news)) //just a check
{
echo "Fill in the Updates!";
exit;
}
$sql = "UPDATE `Text` SET `Updates` = '". $Updates ."'"; //the code i posted
$query = mysql_query($sql);
if(!$query)
{
die(mysql_error());
}
else
{
echo "Update updated!";
header("Location: ". $_SERVER['PHP_SELF']); //failsafe, else if you press F5, it will repeat the action, you can leave this if you want.
exit;
}
}
?>
Re: [PHP] Mysql / php help
PHP Code:
<?php
$db = mysql_connect("localhost","root","root");
$conn = mysql_select_db("Mysql_site", $db);
$query = mysql_query("SELECT * FROM text");
if($_POST['go'])
{
$Updates = $_POST['Updates']; //the textarea field
if(empty($Updates)) //just a check
{
echo "Fill in the Updates!";
exit;
}
$sql = "UPDATE `Text` SET `Updates` = '". $Updates ."'"; //the code i posted
$query = mysql_query($sql);
if(!$query)
{
die(mysql_error());
}
else
{
echo "Update updated!";
exit;
}
}
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
<textarea name="Updates" rows="5" cols="40"></textarea>
<input type="submit" name="go" value="Submit updates" />
</form>
That should work. You left it as "$news = $_POST['Updates'];", you needed to put it like "$Updates = $_POST['Updates'];"