d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php/sql
Add Reply New Topic New Poll
Member
Posts: 19,016
Joined: Apr 27 2006
Gold: 0.00
Aug 30 2012 11:09am
I need some basic PHP/SQL help, it'll only take a couple of minutes of your time, please someone? ^^
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Aug 30 2012 11:13am
kinda hard to help if you dont tell us what your problem is. post your code.
Member
Posts: 19,016
Joined: Apr 27 2006
Gold: 0.00
Aug 30 2012 11:18am
Quote (carteblanche @ 30 Aug 2012 18:13)
kinda hard to help if you dont tell us what your problem is. post your code.


I am supposed to explain what is wrong with a sentence and a bit of code and I can't for the love of god figure it out... to me it all seems okay.

The sentence is:

".... meanwhile we sent the values from "N" and "T" to display.php. We did this with:

header ("location: display.php")"

This is supposed to be wrong.

Here is the code from make.php

"<?PHP

$n = $_GET['Namn'];
$t = $_GET['Meddelande'];

$sql ="INSERT INTO gästbok(Namn, Meddelande) VALUES('".$n."','".$t."')";

$db = mysql_connect("localhost", "root");
mysql_select_db("p14");
mysql_query($sql);
header ("location: display.php");



ECHO $sql;

?>
"

and here is display.php

"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" type="text/css"
<TITLE>Train Track</TITLE>
</HEAD>
<BODY>



<?PHP

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

$sql = "SELECT * FROM gästbok ORDER BY id DESC";
$resultSet = mysql_query($sql);


$numberOfRows = mysql_num_rows($resultSet);

for ($i = 0; $i < $numberOfRows; $i++)
{
$row = mysql_fetch_array($resultSet);
$n = $row["Namn"];
$t = $row["Meddelande"];
ECHO $n." ".$t."<br />" ;
}

?>
"


</BODY>
</HTML>
"
_____________________________________________

I have so far changed to sentence to:

"The data is gathered from the database in make.php and then transfered to display.php. We did this by executing:

mysql_select_db("p14");
mysql_query($sql);
header ("location: display.php");
"

is this wrong?
Member
Posts: 1,628
Joined: Aug 11 2012
Gold: 628.00
Aug 30 2012 12:10pm
first of all i would connect to the DB before doing any insert queries

next that echo $sql is useless, its going go directly to the header location before that echo $sql gets executed;

have you tested this code out and did it return any errors?

edit: im stil a little confused what your trying to accomplish.

just seems like a simple insert/select

is he wanting you to pass the insert variables back into the url?

This post was edited by Huayra on Aug 30 2012 12:12pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll