Unstoppable Domains

[Resolved] Help with Php

Spacemail by SpaceshipSpacemail by Spaceship
Watch

flishess

Established Member
Impact
6
help with php

I am trying to learn php, so far I have managed to write info to my database using forms, and display the info from the page.

My next step is to learn to take the info and make them into URL's:

I have no idea what I am doing with this next step, can anyone help?

index.php:

Code:
<?
include("config.php");
?>
<html>
<form method="post" action="submit.php">
<TABLE>
<TR>
   <TD>Title:</TD>
   <TD><INPUT TYPE='TEXT' NAME='title' VALUE='' size=60></TD>
</TR>
<TR>
   <TD>Description:</TD>
   <TD><INPUT TYPE='TEXT' NAME='description' VALUE='' size=60></TD>
</TR><br>
<TR>
   <TD>Category:</TD>
   <TD><INPUT TYPE='TEXT' NAME='category' VALUE='' size=60></TD>
</TR><br>
<TR>
   <TD></TD><br>
   <TD><INPUT TYPE="submit" name="submit" value="submit"></TD> 
</TR>
</TABLE>
</form>
<html>

submit.php
Code:
<? 
//initilize PHP

if($_POST['submit']) //If submit is hit
{
   include("config.php");

   //convert all the posts to variables:
   $title = $_POST['title'];
   $description = $_POST['description'];
   $category = $_POST['category'];
   
   //Insert the values into the correct database with the right fields
   //mysql table = gamepage
   //table columns = id, title, description, category
   //post variables = $title, $description, '$category
   $result=MYSQL_QUERY("INSERT INTO gamepage (id,title,description,category)".
      "VALUES ('NULL','$title', '$description', '$category')"); 

    //confirm
   echo "Query Finished"; 
}
?>

gamepage.php:
Code:
<?
include("config.php");

$result = mysql_query("SELECT * FROM gamepage"); 
    if (!$result) { 
      echo("<b>Error performing query: " . mysql_error() . "</b>"); 
      exit(); 
    }
while ($row = mysql_fetch_array($result) ) { 
                $title = $row["title"];
                [COLOR="Red"]$id    = $row["id"];[/COLOR]

[COLOR="Red"]echo("<p><a href="gamepage.php?id=$id">$title</a></p>");[/COLOR]
    }
?>

Ok, what I want to be able to do is when you land on gamepage.php it will show the Titles of the games- I want the game title to be a URL and when you click on it the rest of the info for the game will be displayed.

The urls's would look something like mydomain.com/gamepage.php?id=1 etc.

the table name is gamepage
and the table rows are:
id
title
description
category

Can anyone help me finish this code?

I am trying to keep this in the most basic form, so that I can build on this as I learn more.

Thanks.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
<?
include "config.php";

$result = mysql_query("SELECT id,title FROM `gamepage`") or die(mysql_error());
while ($row = mysql_fetch_array($result) ) { 
     $title = $row["title"];
     $id = $row["id"]; 
     echo "<p><a href='gamepage.php?id=$id'>$title</a></p>";
    }
?>

Even though what you had already was close.
 
Last edited:
0
•••
Before we can help you are better telling us the actual problem that you are having. If it is not working in what way is it not working. What errors are being produced, what output do you get etc.
 
0
•••
peter@flexiwebhost said:
Before we can help you are better telling us the actual problem that you are having. If it is not working in what way is it not working. What errors are being produced, what output do you get etc.

www.bf2matchplay.com/gamepage.php

you can see the error
 
0
•••
Syntax error.
You cannot have " in an echo which starts with a ", if that makes sense.

Replace my previous code with yours and it will work.

PHP:
echo("<p><a href="gamepage.php?id=$id">$title</a></p>");
Needs to be:
PHP:
echo '<p><a href="gamepage.php?id=$id">$title</a></p>';
OR
echo "<p><a href='gamepage.php?id=$id'>$title</a></p>";
 
0
•••
Just re read what TheArbiter and realised I misread it anyway.

TheArbiter said:
PHP:
echo("<p><a href="gamepage.php?id=$id">$title</a></p>");
Needs to be:
PHP:
echo '<p><a href="gamepage.php?id=$id">$title</a></p>';
OR
echo "<p><a href='gamepage.php?id=$id'>$title</a></p>";

Your first example is incorrect. If he does that the variable will not be evaluated.

However this is irrelevant to the op's current problem. The error he receives is output when $result evaluates to false.
 
Last edited:
0
•••
problem solved, thanks to those involved!
 
0
•••
did you input the "; DROP TABLE gameplay example on the site?

If not someone is trying to bugger around with your database. Unfortunately (or fortunately for you) they are completely unaware of the fact that mysql_query will only execute 1 query regardless of how many queries are passed to it.

I strongly advise you to look at security when you are coding. I know you are only just starting but that is the best time to start learning. Whenever you take input from a user always check it is what it is supposed to be. Also as you are uploading data to a mysql server use mysql_real_escape_string on what you upload to it.
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back