Jump to content

Jeopardy Game


KruSuPhy

Recommended Posts

Hey guys, I'm making a jeopardy game in PHP to better myself. I've been working on it for a couple days, and i ran into a problem making an Edit category Name system. i can connect to the db fine, and insert data fine, but i can't figure out how to make it send all five textfields to their ID spot in `sections`. I have id's one through five, but i can't figure out how to send it all to the database. i get some unexpected T_VARIABLE error on line 7, which is

<?php 

include 'jepconfig.php';
$name=$_POST['secname'];
$idnum=$_POST['idnum'];

$query="INSERT $name INTO sections WHERE id="$idnum""
$result = mysql_query($query)
?>

 

I may have done something wrong in that one, but nothing else i tried has worked either. Can someone help? I can upload the game of what i have so far if needed.

Link to comment
Share on other sites

If the records are already in the database, you would use an UPDATE query. If they are new records, you don't use a WHERE clause. Also, correct syntax for the die() statement to echo the actual error thrown by mysql  would be:

or die( mysql_error() );

Link to comment
Share on other sites

If the records are already in the database, you would use an UPDATE query. If they are new records, you don't use a WHERE clause. Also, correct syntax for the die() statement to echo the actual error thrown by mysql  would be:

or die( mysql_error() );

 

Thanks Pikachu, for clearing that up.  That proves it's time for me to clock off for the night :-[

Link to comment
Share on other sites

what is a literal?

And i did what you guys said, but im getting some other error i can't figure out now..

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id= (5)' at line 1

 

I don't even know what's in any of my line 1s that could cause an error...

Link to comment
Share on other sites

what is a literal?

Paste this in to a new .php file and run it:

<?php
$variable = "This is a string in a variable";
echo 'Single quoted: The variable is $variable <br />';
echo 'Single quoted and concatenated: The variable is ' . $variable . '<br />';
echo "Double quoted: The variable is $variable <br />";
echo "Double quoted and concatenated: The variable is " . $variable . "<br />";
?>

 

And i did what you guys said, but im getting some other error i can't figure out now..

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id= (5)' at line 1

 

I don't even know what's in any of my line 1s that could cause an error...

 

That's the error returned by MySQL in the mysql_error() part of the die() statement. The error is in the first line of the QUERY string, not the script, and it even tells you (sort of) where it is. Paste up your new code, and I'll have a look at what you have now.

Link to comment
Share on other sites

<?php 

include 'jepconfig.php';
$name=$_POST['secname'];
$idnum=$_POST['idnum'];

$query="INSERT INTO sections (name) VALUES (".$name.") WHERE id= .$idnum.";
$result = mysql_query($query) or die( mysql_error() );
?>

basically what i had before, just with what i was told to change, couldn't see anything else that should be modified...

 

i have five rows, each with an ID from 1 to 5(there will be 5 categories in the game). this should send the category name to 'name' in `sections` where the ID is the same as the field.

Link to comment
Share on other sites

already in the database there's the column ID and name, with rows 1 2 3 4 5 for id, and one two three four five for name. Can you tell me how exactly i should assign an id(1-5) to the name that i'm editing? currently i have a form with five text fields for the name of the categories. How would i get a specific id to each text field? If i did wrong what I think i did, I'll feel like a complete moron, so i'd rather not say what i did exactly

Link to comment
Share on other sites

Believe me, we've all felt like morons at some point. Nobody is born with PHP knowledge. If you have the records in the database already, and you just need to change a field, you need to use an UPDATE query rather than an INSERT query. Are you loading all of these into a form and trying to edit them, or are you doing this some other way?

// PSEUDO-CODE - - - - - - -

$query = "UPDATE tbl_name SET id_field_name = 1 WHERE name = 'name' "; // note that integer values do not get quoted in a query string, whereas strings do get quoted
mysql_query( $query ) or die( mysql_error() );

Link to comment
Share on other sites

Well basically I'm just trying to get a basic jeopardy game with the main page, admin access to change questions and sections, and... that's about it. from there i'll make it pretty with nice features like team setup and all that nonsense. for now i just have a form with text fields that let the person type in text(obv) then sends that text to the database to be received by the main question page. i think.

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.