Jump to content

[SOLVED] PHP/MySQL problem


mohaakilla51

Recommended Posts

[random side note] Hello Everyone, I am MOHAAkilla516. I have been coding HTML/Javascript for about 4 years now. I finally decided to upgrade to CSS and PHP. That is why I am here [/side note]

 

OK, so I am trying to create a method for creating resources (Tutorial, Articles, etc.) From registered memberes of my site. Here is the code I am using to try to do this (Without all the formatting and etc.):

<html>
<head>
<?php mysql_connect("localhost","root",""); 
mysql_select_db("if_847191_resources"); ?>
<title><?php 
$title = $_GET['article'];
echo $title;
?>
</title>
</head>
<body>
<?php
$title = $_GET['article']; //Yeah yeah, I know that was unneccessary. Is this the proper syntax for a comment in PHP?
$article = mysql_query("SELECT * FROM article WHERE title==$title");

echo $article['body'];
echo "that was the article";
?>
</body>
</html>

I am able to connect to the database without problem. The only problem I get it that I only get a blank page, with no article! The URL I have is blah.com/resources.php?article=Test Where resources is the above page. Here is a screen shot of PHPMyAdmin:

image.php?a7e5a2c4a5.jpg

OR, If you can't see that: Click Here

So the table exists. THe Data Exists. What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/61802-solved-phpmysql-problem/
Share on other sites

 

edited try now.

 

try that before i rewrite it all lol

<html>
<head>

<?php 

//if password exist.
$db=mysql_connect("localhost","root","password");
mysql_select_db("if_847191_resources",$db); 

?>

<title>
<?php 
$title = $_GET['article'];
echo $title;
?>
</title>
</head>
<body>
<?php

$title=$_POST['title'];

$query = "SELECT * FROM article";

$result-mysql_query($query) or die("mysql_error()");

while($article=mysql_fetch_assoc($result)){

$a=$article['body'];

echo "$a that was the article";

}
?>
</body>

</html>

try now please

<?php 

$db=mysql_connect("localhost","root","");
mysql_select_db("if_847191_resources",$db); 

$query = "SELECT * FROM article";

$result-mysql_query($query) or die("mysql_error()");

while($article=mysql_fetch_assoc($result)){

$a=$article['body'];

echo "$a that was the article";

}
?>

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\acdec\resource.php on line 28

I have no idea what that Mysql_fetch_assoc is so I do not know how to fix this... BTW, thanks for the help so far red arrow... YOU ROCK

<?php 

$db=mysql_connect("localhost","root","");
mysql_select_db("if_847191_resources",$db); 

$query = "SELECT * FROM article";

$result=mysql_query($query) or die("mysql_error()");

while($article=mysql_fetch_assoc($result)){

$a=$article['body'];

echo "$a that was the article";

}
?>

I think this part of code is wrong..

 


$title = $_GET['article']; //Yeah yeah, I know that was unneccessary. Is this the proper syntax for a comment in PHP?
$article = mysql_query("SELECT * FROM article WHERE title==$title");

 

try to change..

 


$title = $_GET['article']; //Yeah yeah, I know that was unneccessary. Is this the proper syntax for a comment in PHP?
$article = mysql_query("SELECT * FROM article WHERE title=$title");
$data = $mysql_fetch_array($article);
# check if there's query result
print_r($data); exit;

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.