Jump to content

Some help for my first phpsite


zamp0e

Recommended Posts

Hello!

I recently got some help with my INSERT syntax, and I think it's right now. The problem is that nothing is inserted into the database.

 

I think it might have something to do with me placing the INSERT row wrong in the code, but I just have no idea where to place it, so that's where some help would be appreciated.

 

I have no idea how you could help me if I wouldnt give you all code I use for the site, so I'm sorry for putting up so much.

 

Notes:

My databese is called iqsmart, and the table is called iqtable.

Right now I've placed the INSERT row in the end of the document, right before the end of the php tags.

I know the whole site sucks, I just started learning about php and it's purely experimental.

 

Any help would be highly appreciated!

 

 

<html> 
<head> 
<basefont face="Arial"> 
</head> 
<body> 

<?php 

// set database server access variables: 
$host = "*****"; 
$user = "****"; 
$pass = "****"; 
$db = "iqsmart"; 

// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 
mysql_select_db($db) or die ("Unable to select database!"); 

// create query 
$query = "SELECT * FROM iqtable"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Iqsmart.webb.se</title>
<?php
$points="0";
function Sum()
{
    global $points;
$points=$points;
} 
?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body bgcolor="#666666">
<h1 align="center">Hur mycket kan du?</h1>
<h3 align="center">Svara på ett antal frågor</h3>
<center>
<?php 
if (!isset($_POST['submit1'])) { 
    ?> 
<b>Vilken världsdel ligger Kenya i?</b>
<br />
<form action="<?php echo $_SERVER['../../../Documents and Settings/HP_Administrator.SIMON/My Documents/test2/PHP_SELF']; ?>" method="POST"> 
    <input type="radio" name="varldsdel[]" value="Europa">Europa
    <input type="radio" name="varldsdel[]" value="Amerika">Amerika
    <input type="radio" name="varldsdel[]" value="Sydamerika ">Sydamerika 
    <input type="radio" name="varldsdel[]" value="Asien">Asien 
    <input type="radio" name="varldsdel[]" value="Afrika">Afrika 
    <input type="radio" name="varldsdel[]" value="Sydpolen">Sydpolen 
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
 <b>Vilket tal skulle du säga är det bästa närmevärdet till pi (π)?</b>
     <br />
    <input type="radio" name="pi[]" value="pi1">2.132456
    <input type="radio" name="pi[]" value="pi2">3.174213
    <input type="radio" name="pi[]" value="pi3">3.141537
    <input type="radio" name="pi[]" value="pi4">3.155642
    <input type="radio" name="pi[]" value="pi5">3.141592 
    <input type="radio" name="pi[]" value="pi6">3.141574 
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    <b>Under vilka år pågick andra världskriget?</b>
    <br />
    <input type="radio" name="kriget[]" value="kriget1">1929-1935
    <input type="radio" name="kriget[]" value="kriget2">1423-1539
    <input type="radio" name="kriget[]" value="kriget3">1939-1945
    <input type="radio" name="kriget[]" value="kriget4">1940-1945
    <input type="radio" name="kriget[]" value="kriget5">1937-1944
    <input type="radio" name="kriget[]" value="kriget6">1982-1996
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    
    <b>Vem kom på den fysikaliska lagen E=mc^2?</b>
    <br />
    <input type="radio" name="vem[]" value="Frank">Frank Roosevelt
    <input type="radio" name="vem[]" value="Isaac">Isaac Newton
    <input type="radio" name="vem[]" value="Alfred">Alfred Nobell
    <input type="radio" name="vem[]" value="Albert">Albert Einstein
    <input type="radio" name="vem[]" value="William">William Shakespeare
    <input type="radio" name="vem[]" value="Emilie">Emilie Dickinsson
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    
    <b>Vad blir 100^(1/2)?</b>
    <br />
    <input type="radio" name="tal1[]" value="tal1">20
    <input type="radio" name="tal1[]" value="tal2">50
    <input type="radio" name="tal1[]" value="tal3">5
    <input type="radio" name="tal1[]" value="tal4">1000
    <input type="radio" name="tal1[]" value="tal5">33
    <input type="radio" name="tal1[]" value="tal6">10
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    
    <b>Hur lyder Pythagoras Sats ?</b>
    <br />
    <input type="radio" name="pythagoras[]" value="pythagoras1">a^2+b^2=c^2
    <input type="radio" name="pythagoras[]" value="pythagoras2">a*2+b*2=c*2
    <input type="radio" name="pythagoras[]" value="pythagoras3">(a+2)*(b+2)=c+2
    <input type="radio" name="pythagoras[]" value="pythagoras4">a*b=c
    <input type="radio" name="pythagoras[]" value="pythagoras5">a/b=c
    <input type="radio" name="pythagoras[]" value="pythagoras6">(a/2)*(b/2)=c/2
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    
    <b>Vilken land har i historien haft det största imperiet?</b>
    <br />
    <input type="radio" name="land1[]" value="land1">England
    <input type="radio" name="land1[]" value="land2">Kina
    <input type="radio" name="land1[]" value="land3">USA
    <input type="radio" name="land1[]" value="land4">Mongoliet
    <input type="radio" name="land1[]" value="land5">Sverige
    <input type="radio" name="land1[]" value="land6">Turkiet
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    
    <b>Vilket av följande tal är ett primtal?</b>
    <br />
    <input type="radio" name="primtal[]" value="primtal1">62
    <input type="radio" name="primtal[]" value="primtal2">63
    <input type="radio" name="primtal[]" value="primtal3">64
    <input type="radio" name="primtal[]" value="primtal4">65
    <input type="radio" name="primtal[]" value="primtal5">66
    <input type="radio" name="primtal[]" value="primtal6">67
     <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
    Vad heter du ?
    <br />
    <input type="text" name="name" />
    
    <br />
                            
    <br />
    <input type="submit" name="submit1" value="Svara!"> 
    </form>


<?php 

}
elseif(empty($_POST['varldsdel']) || empty($_POST['pi']) || empty($_POST['kriget']) || empty($_POST['vem']) || empty($_POST['tal1']) || empty($_POST['pythagoras']) || empty($_POST['land1'])|| empty($_POST['primtal']))
{
echo "Du har inte svarat på alla frågor!";
}
																																					   
else { 

    if (is_array($_POST['varldsdel'])) {  
        foreach ($_POST['varldsdel'] as $a) { 
	if($a=="Afrika"){
	Sum();
	$points=$points+"1";	
		}
            } 

         
}



    if (is_array($_POST['pi'])) {  
        foreach ($_POST['pi'] as $a) { 
	if($a=="pi5"){
	Sum();
	$points=$points+"4";	
		}

            } 
         
}

    if (is_array($_POST['kriget'])) {  
        foreach ($_POST['kriget'] as $a) { 
	if($a=="kriget3"){
	Sum();
	$points=$points+"2";	
		}

            } 

}


    if (is_array($_POST['vem'])) {  
        foreach ($_POST['vem'] as $a) { 
	if($a=="Albert"){
	Sum();
	$points=$points+"1";	
		}

            } 
}


    if (is_array($_POST['tal1'])) {  
        foreach ($_POST['tal1'] as $a) { 
	if($a=="tal6"){
	Sum();
	$points=$points+"2";	
		}
            } 

}


    if (is_array($_POST['pythagoras'])) {  
        foreach ($_POST['pythagoras'] as $a) { 
	if($a=="pythagoras1"){
	Sum();
	$points=$points+"1";	
		}
            } 

}
	   
	   
	if (is_array($_POST['land1'])) {  
        foreach ($_POST['land1'] as $a) { 
	if($a=="land4"){
	Sum();
	$points=$points+"2";	
		}
            } 
}



	if (is_array($_POST['primtal'])) {  
        foreach ($_POST['primtal'] as $a) { 
	if($a=="primtal6"){
	Sum();
	$points=$points+"3";	
		}
            } 
	if($points<="3")
	{
		echo"Du är helt jävla dum i huvet, kan ju inte ett skit. Världen skulle må bättre utan dig! ($points/16) Rätta svar.";
	}
	elseif($points>"3"&&$points<="9")
	{
		echo"Dum...dum...dum...dum ($points/16) Rätta svar.";
	}
	elseif($points>"9"&&$points<="12")
	{
		echo"Du kunde ju varit bättre ($points/16) Rätta svar.";
	}
	elseif($points>"12"&&$points<="20")
	{
		echo"Tråkigt! Fuskis! ($points</16) Rätta svar.";
	}
	?>
        <br>
        <?php
	echo "Du heter <b>{$_POST['name']}</b>";
}

} 
	$sql = "INSERT into iqtable VALUES (NULL, {$_POST['name']}, '$points')";
?> 




</center>
</p>

</p>
<center>
    <br />
                                                                 
    <br />
                                                                           
    <br />
                                                                     
    <br />
                                                                           
    <br />
    

</body>
</html>

 

 

 

Thanks in advance!

Link to comment
Share on other sites

So how should it be like ?

 

$sql = "INSERT into iqtable VALUES (NULL, {$_POST['name']}, '$points')";
$result = mysql_query($sql) or die ("Error in query: $sql. ".mysql_error());

 

Like that, in the same area it is in now ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.