I am new to PHP and MySQL, but sofar it's going his way 😃
I created a news site wich I tested locally (and was working fine), but when uploading it
to my website, it aint working that good.
The website is a sort of newssite wich people can reaction on news.
The website uses 2 databases. 1 database where the news + comments are stored and 1 database
where the users are stored in, you maybe ask why 2 databases for this sort of site ?
That's because our site runs a forum and the members of the forum can only give a reaction
on the news!
I have 2 config files where the 1 makes a connection with the news database and 1 makes
a connection to the forum (this is the database where the forum runs on)
Live example of the news site (and error) : http://www.rip-productions.net/uploads/news
The main site shows the latets news (still testing, that's why we have just 1 item) and the
latest forum threads. That's working, but when I want to give a reaction on the news item
I get this error "select command denied to user: 'ripprod_news@localhost' for table 'user'"
I think the error is because I have to use both connections to the 2 databases
(verify if the person may post (using the Forum database) and the newsdatabase (for
storing the news reaction).
Database names are :
- ripprod_ripnews
- ripprod_ripproductions
The connection string are right (otherwise the other things also didn't work)
To give some PHP code :
----- This is working
<?php
include ('./admin/config.php'); //Connection to news database
$theid = $_GET['id'];
$comment = "SELECT * FROM news WHERE newsid='$theid'";
$resultcomment = mysql_query($comment) or die(mysql_error());
$objcomment = mysql_fetch_object($resultcomment);
echo "Comment on news : <b>$objcomment->title</b>";
?>
----- This isn't working
<?php
include ('./admin/configforum.php'); //Connection to Forum database
include ('./admin/config.php'); //Connection to news database
if (isset($_POST['action']) && $_POST['action'] == 'postcomment') {
$theid = $_GET['id'];
$gebruiker = $_POST['Tusername'];
$wachtwoord = $_POST['Tpassword'];
$comment = $_POST['Tcomment'];
$tijd = date("G:i");
$datum = date('d-m-Y');
$encryptpass = md5($wachtwoord);
$queryuser = "SELECT * FROM ripprod_ripproductions.user WHERE user.username='$gebruiker' AND user.password='$encryptpass'";
$resultuser = mysql_query($queryuser) or die(mysql_error());
$objnr = mysql_num_rows($resultuser);
if ($objnr == 1) {
$querynr = "SELECT count(*) as totalrows FROM ripprod_ripnews.rinewscomments";
$resultrow = mysql_query($querynr) or die(mysql_error());
$numberrow = mysql_result($resultrow,0,0);
$numberrow++;
$query = "INSERT INTO ripprod_ripnews.newscomments VALUES ('$numberrow','$theid','$gebruiker','user@test.com','$comment','$tijd','$datum','')";
$result = mysql_query($query) or die(mysql_error());
Print "Reaction of <b>$gebruiker</b> is posted, please return to <A HREF=\"news.php?id=$theid\">newspost.</A>";
}
Else {
Print "<b>Login / Password wrong, please try again!</b>";
}
}
?>
What I am doing wrong (I am still a beginner 😉 )